primitivus: refactoring to use urwid-satext which is now a separate project
This commit is contained in:
parent
2c9364addf
commit
c8b5f1db90
10 changed files with 63 additions and 1317 deletions
|
|
@ -23,7 +23,7 @@ import urwid
|
|||
from tools.games import TarotCard
|
||||
from quick_frontend.quick_card_game import QuickCardGame
|
||||
from xmlui import XMLUI
|
||||
import custom_widgets
|
||||
from urwid_satext import sat_widgets
|
||||
|
||||
class CardDisplayer(urwid.Text):
|
||||
"""Show a card"""
|
||||
|
|
@ -314,7 +314,7 @@ class CardGame(QuickCardGame,urwid.WidgetWrap):
|
|||
self.hand_wid.update(self.hand)
|
||||
if self.state == "ecart":
|
||||
if len(self.hand_wid.getSelected()) == 6:
|
||||
pop_up_widget = custom_widgets.ConfirmDialog(_("Do you put these cards in chien ?"), yes_cb=self.onEcartDone, no_cb=self.parent.host.removePopUp)
|
||||
pop_up_widget = sat_widgets.ConfirmDialog(_("Do you put these cards in chien ?"), yes_cb=self.onEcartDone, no_cb=self.parent.host.removePopUp)
|
||||
self.parent.host.showPopUp(pop_up_widget)
|
||||
elif self.state == "play":
|
||||
card = card_wid.getCard()
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
import urwid
|
||||
from quick_frontend.quick_contact_list import QuickContactList
|
||||
from quick_frontend.quick_chat import QuickChat
|
||||
import custom_widgets
|
||||
from urwid_satext import sat_widgets
|
||||
import time
|
||||
from tools.jid import JID
|
||||
from card_game import CardGame
|
||||
from files_management import FileDialog
|
||||
from urwid_satext.files_management import FileDialog
|
||||
|
||||
|
||||
class ChatText(urwid.FlowWidget):
|
||||
|
|
@ -107,7 +107,7 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
|||
for wid in self.content:
|
||||
wid._invalidate()
|
||||
elif key == "meta l": #user wants to (un)hide widget decoration
|
||||
show = not isinstance(self._w, custom_widgets.LabelLine)
|
||||
show = not isinstance(self._w, sat_widgets.LabelLine)
|
||||
self.showDecoration(show)
|
||||
self._invalidate()
|
||||
elif key == "meta s": #user wants to (un)hide group's subject or change its apperance
|
||||
|
|
@ -126,7 +126,7 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
|||
|
||||
def getMenu(self):
|
||||
"""Return Menu bar"""
|
||||
menu = custom_widgets.Menu(self.host.loop)
|
||||
menu = sat_widgets.Menu(self.host.loop)
|
||||
if self.type == 'group':
|
||||
game = _("Game")
|
||||
menu.addMenu(game, "Tarot", self.onTarotRequest)
|
||||
|
|
@ -141,11 +141,11 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
|||
elif type == 'group':
|
||||
if len(self.chat_colums.widget_list) == 1:
|
||||
present_widget = self.__buildPresentList()
|
||||
self.present_panel = custom_widgets.VerticalSeparator(present_widget)
|
||||
self.present_panel = sat_widgets.VerticalSeparator(present_widget)
|
||||
self.__appendPresentPanel()
|
||||
|
||||
def __getDecoration(self, widget):
|
||||
return custom_widgets.LabelLine(widget, custom_widgets.SurroundedText(unicode(self.target)))
|
||||
return sat_widgets.LabelLine(widget, sat_widgets.SurroundedText(unicode(self.target)))
|
||||
|
||||
def showDecoration(self, show=True):
|
||||
"""Show/Hide the decoration around the chat window"""
|
||||
|
|
@ -157,7 +157,7 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
|||
|
||||
|
||||
def __buildPresentList(self):
|
||||
self.present_wid = custom_widgets.GenericList([],option_type = custom_widgets.ClickableText)
|
||||
self.present_wid = sat_widgets.GenericList([],option_type = sat_widgets.ClickableText)
|
||||
return self.present_wid
|
||||
|
||||
def __appendPresentPanel(self):
|
||||
|
|
@ -241,7 +241,7 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
|||
normal: general info like "toto has joined the room"
|
||||
me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
|
||||
"""
|
||||
self.content.append(custom_widgets.ClickableText(msg))
|
||||
self.content.append(sat_widgets.ClickableText(msg))
|
||||
self.text_list.set_focus(len(self.content)-1)
|
||||
self.host.redraw()
|
||||
|
||||
|
|
@ -263,7 +263,7 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
|||
#MENU EVENTS#
|
||||
def onTarotRequest(self, menu):
|
||||
if len(self.occupants) != 4:
|
||||
self.host.showPopUp(custom_widgets.Alert(_("Can't start game"), _("You need to be exactly 4 peoples in the room to start a Tarot game"), ok_cb=self.host.removePopUp))
|
||||
self.host.showPopUp(sat_widgets.Alert(_("Can't start game"), _("You need to be exactly 4 peoples in the room to start a Tarot game"), ok_cb=self.host.removePopUp))
|
||||
else:
|
||||
self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile)
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
import urwid
|
||||
from quick_frontend.quick_contact_list import QuickContactList
|
||||
from tools.jid import JID
|
||||
import custom_widgets
|
||||
from urwid_satext import sat_widgets
|
||||
|
||||
|
||||
class ContactList(urwid.WidgetWrap, QuickContactList):
|
||||
|
|
@ -36,7 +36,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
|
||||
#we now build the widget
|
||||
self.frame = urwid.Frame(self.__buildList())
|
||||
self.main_widget = custom_widgets.LabelLine(self.frame, custom_widgets.SurroundedText(_("Contacts")))
|
||||
self.main_widget = sat_widgets.LabelLine(self.frame, sat_widgets.SurroundedText(_("Contacts")))
|
||||
urwid.WidgetWrap.__init__(self, self.main_widget)
|
||||
if on_click:
|
||||
urwid.connect_signal(self, 'click', on_click, user_data)
|
||||
|
|
@ -75,7 +75,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
def __contactClicked(self, contact_wid, selected):
|
||||
self.selected = contact_wid.data
|
||||
for widget in self.frame.body.body:
|
||||
if widget.__class__ == custom_widgets.SelectableText:
|
||||
if widget.__class__ == sat_widgets.SelectableText:
|
||||
widget.setState(widget.data == self.selected, invisible=True)
|
||||
if self.selected in self.alert_jid:
|
||||
self.alert_jid.remove(self.selected)
|
||||
|
|
@ -95,7 +95,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
nick = self.CM.getAttr(jid,'nick')
|
||||
display = nick or name or jid.node or jid.short
|
||||
header = '(*) ' if contact in self.alert_jid else ''
|
||||
widget = custom_widgets.SelectableText(('alert' if contact in self.alert_jid else 'default',display),
|
||||
widget = sat_widgets.SelectableText(('alert' if contact in self.alert_jid else 'default',display),
|
||||
selected = contact==self.selected, header=header)
|
||||
widget.data = contact
|
||||
content.append(widget)
|
||||
|
|
@ -110,7 +110,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
unfolded = self.groups[key][0]
|
||||
if key!=None:
|
||||
header = '[-]' if unfolded else '[+]'
|
||||
widget = custom_widgets.ClickableText(key,header=header+' ')
|
||||
widget = sat_widgets.ClickableText(key,header=header+' ')
|
||||
content.append(widget)
|
||||
urwid.connect_signal(widget, 'click', self.__groupClicked)
|
||||
if unfolded:
|
||||
|
|
@ -121,7 +121,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
"""Unselect all contacts"""
|
||||
self.selected = None
|
||||
for widget in self.frame.body.body:
|
||||
if widget.__class__ == custom_widgets.SelectableText:
|
||||
if widget.__class__ == sat_widgets.SelectableText:
|
||||
widget.setState(False, invisible=True)
|
||||
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,234 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Primitivus: a SAT frontend
|
||||
Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import urwid
|
||||
import custom_widgets
|
||||
from tools.jid import JID
|
||||
import os, os.path
|
||||
from xml.dom import minidom
|
||||
from logging import debug, info, error
|
||||
from time import time
|
||||
|
||||
class PathEdit(custom_widgets.AdvancedEdit):
|
||||
"""AdvancedEdit with manage file paths"""
|
||||
|
||||
def keypress(self, size, key):
|
||||
if key == '~' and self.edit_pos==0:
|
||||
expanded = os.path.expanduser('~')
|
||||
self.set_edit_text(os.path.normpath(expanded+'/'+self.edit_text))
|
||||
self.set_edit_pos(len(expanded)+1)
|
||||
elif key == 'ctrl w':
|
||||
if self.edit_pos<2:
|
||||
return
|
||||
before = self.edit_text[:self.edit_pos]
|
||||
pos = (before[:-1] if before.endswith('/') else before).rfind("/")+1
|
||||
self.set_edit_text(before[:pos] + self.edit_text[self.edit_pos:])
|
||||
self.set_edit_pos(pos)
|
||||
return
|
||||
else:
|
||||
return super(PathEdit, self).keypress(size, key)
|
||||
|
||||
class FilesViewer(urwid.WidgetWrap):
|
||||
"""List specialised for files"""
|
||||
|
||||
def __init__(self, onPreviousDir, onDirClick, onFileClick):
|
||||
self.path=''
|
||||
self.key_cache = ''
|
||||
self.key_time = time()
|
||||
self.onPreviousDir = onPreviousDir
|
||||
self.onDirClick = onDirClick
|
||||
self.onFileClick = onFileClick
|
||||
self.files_list = urwid.SimpleListWalker([])
|
||||
self.show_hidden = True
|
||||
listbox = urwid.ListBox(self.files_list)
|
||||
urwid.WidgetWrap.__init__(self, listbox)
|
||||
|
||||
def keypress(self, size, key):
|
||||
if key=='meta h':
|
||||
#(un)hide hidden files
|
||||
self.show_hidden = not self.show_hidden
|
||||
self.showDirectory(self.path)
|
||||
if key=='meta d':
|
||||
#jump to directories
|
||||
if self.files_list:
|
||||
self._w.set_focus(0)
|
||||
elif key=='meta f':
|
||||
for idx in range(len(self.files_list)):
|
||||
if isinstance(self.files_list[idx].base_widget,urwid.Divider):
|
||||
if idx<len(self.files_list)-1:
|
||||
self._w.set_focus(idx+1)
|
||||
break
|
||||
elif len(key) == 1:
|
||||
if time() - self.key_time > 2:
|
||||
self.key_cache=key
|
||||
else:
|
||||
self.key_cache+=key
|
||||
self.key_time = time()
|
||||
for idx in range(len(self.files_list)):
|
||||
if isinstance(self.files_list[idx],custom_widgets.ClickableText) and self.files_list[idx].get_text().lower().startswith(self.key_cache.lower()):
|
||||
self._w.set_focus(idx)
|
||||
break
|
||||
else:
|
||||
return self._w.keypress(size, key)
|
||||
|
||||
def showDirectory(self, path):
|
||||
self.path = path
|
||||
del self.files_list[:]
|
||||
directories = []
|
||||
files = []
|
||||
try:
|
||||
for filename in os.listdir(path):
|
||||
fullpath = os.path.join(path,filename)
|
||||
if os.path.isdir(fullpath):
|
||||
directories.append(filename)
|
||||
else:
|
||||
files.append(filename)
|
||||
except OSError:
|
||||
self.files_list.append(urwid.Text(("warning",_("Impossible to list directory")),'center'))
|
||||
directories.sort()
|
||||
files.sort()
|
||||
if os.path.abspath(path)!='/' and os.path.abspath(path) != '//':
|
||||
previous_wid = custom_widgets.ClickableText(('directory','..'))
|
||||
urwid.connect_signal(previous_wid,'click',self.onPreviousDir)
|
||||
self.files_list.append(previous_wid)
|
||||
for directory in directories:
|
||||
if directory.startswith('.') and not self.show_hidden:
|
||||
continue
|
||||
dir_wid = custom_widgets.ClickableText(('directory',directory))
|
||||
urwid.connect_signal(dir_wid,'click',self.onDirClick)
|
||||
self.files_list.append(dir_wid)
|
||||
self.files_list.append(urwid.AttrMap(urwid.Divider('-'),'separator'))
|
||||
for filename in files:
|
||||
if filename.startswith('.') and not self.show_hidden:
|
||||
continue
|
||||
file_wid = custom_widgets.ClickableText(filename)
|
||||
urwid.connect_signal(file_wid,'click',self.onFileClick)
|
||||
self.files_list.append(file_wid)
|
||||
|
||||
|
||||
|
||||
class FileDialog(urwid.WidgetWrap):
|
||||
|
||||
def __init__(self, ok_cb, cancel_cb, title=_("Please select a file"), style=[]):
|
||||
"""Create file dialog
|
||||
@param title: title of the window/popup
|
||||
@param style: NOT USED YET #FIXME
|
||||
"""
|
||||
self.ok_cb = ok_cb
|
||||
self.__home_path = os.path.expanduser('~')
|
||||
self.path_wid = PathEdit(_('Path: '))
|
||||
self.path_wid.setCompletionMethod(self._directory_completion)
|
||||
urwid.connect_signal(self.path_wid, 'change', self.onPathChange)
|
||||
header = urwid.Pile([self.path_wid, urwid.Divider(u'─')])
|
||||
bookm_list = urwid.SimpleListWalker([])
|
||||
self.bookmarks = list(self.getBookmarks())
|
||||
self.bookmarks.sort()
|
||||
for bookmark in self.bookmarks:
|
||||
if bookmark.startswith(self.__home_path):
|
||||
bookmark="~"+bookmark[len(self.__home_path):]
|
||||
book_wid = custom_widgets.ClickableText(bookmark)
|
||||
urwid.connect_signal(book_wid, 'click', self.onBookmarkSelected)
|
||||
bookm_list.append(book_wid)
|
||||
bookm_wid = urwid.Frame(urwid.ListBox(bookm_list), urwid.AttrMap(urwid.Text(_('Bookmarks'),'center'),'title'))
|
||||
self.files_wid = FilesViewer(self.onPreviousDir, self.onDirClick, self.onFileClick)
|
||||
center_row = urwid.Columns([('weight',2,bookm_wid),
|
||||
('weight',8,custom_widgets.VerticalSeparator(self.files_wid))])
|
||||
|
||||
buttons = []
|
||||
buttons.append(custom_widgets.CustomButton(_('Cancel'),cancel_cb))
|
||||
max_len = max([button.getSize() for button in buttons])
|
||||
buttons_wid = urwid.GridFlow(buttons,max_len,1,0,'center')
|
||||
main_frame = custom_widgets.FocusFrame(center_row, header, buttons_wid)
|
||||
decorated = custom_widgets.LabelLine(main_frame, custom_widgets.SurroundedText(title))
|
||||
urwid.WidgetWrap.__init__(self, decorated)
|
||||
self.path_wid.set_edit_text(os.getcwdu())
|
||||
|
||||
def _directory_completion(self, path, completion_data):
|
||||
path=os.path.abspath(path)
|
||||
if not os.path.isdir(path):
|
||||
head,dir_start = os.path.split(path)
|
||||
else:
|
||||
head=path
|
||||
dir_start=''
|
||||
try:
|
||||
filenames = os.listdir(head)
|
||||
filenames.sort()
|
||||
try:
|
||||
start_idx=filenames.index(completion_data['last_dir'])+1
|
||||
if start_idx == len(filenames):
|
||||
start_idx = 0
|
||||
except (KeyError,ValueError):
|
||||
start_idx = 0
|
||||
for idx in range(start_idx,len(filenames)) + range(0,start_idx):
|
||||
full_path = os.path.join(head,filenames[idx])
|
||||
if filenames[idx].lower().startswith(dir_start.lower()) and os.path.isdir(full_path):
|
||||
completion_data['last_dir'] = filenames[idx]
|
||||
return full_path
|
||||
except OSError:
|
||||
pass
|
||||
return path
|
||||
|
||||
def getBookmarks(self):
|
||||
gtk_bookm = os.path.expanduser("~/.gtk-bookmarks")
|
||||
kde_bookm = os.path.expanduser("~/.kde/share/apps/kfileplaces/bookmarks.xml")
|
||||
bookmarks = set()
|
||||
try:
|
||||
with open(gtk_bookm) as gtk_fd:
|
||||
for bm in gtk_fd.readlines():
|
||||
if bm.startswith("file:///"):
|
||||
bookmarks.add(bm[7:].replace('\n',''))
|
||||
except IOError:
|
||||
info(_('No GTK bookmarks file found'))
|
||||
pass
|
||||
|
||||
try:
|
||||
dom = minidom.parse(kde_bookm)
|
||||
for elem in dom.getElementsByTagName('bookmark'):
|
||||
bm = elem.getAttribute("href")
|
||||
if bm.startswith("file:///"):
|
||||
bookmarks.add(bm[7:])
|
||||
except IOError:
|
||||
info(_('No KDE bookmarks file found'))
|
||||
pass
|
||||
|
||||
return bookmarks
|
||||
|
||||
def onBookmarkSelected(self, button):
|
||||
self.path_wid.set_edit_text(os.path.expanduser(button.get_text()))
|
||||
|
||||
def onPathChange(self, edit, path):
|
||||
if os.path.isdir(path):
|
||||
self.files_wid.showDirectory(path)
|
||||
|
||||
def onPreviousDir(self, wid):
|
||||
path = os.path.abspath(self.path_wid.get_edit_text())
|
||||
if not os.path.isdir(path):
|
||||
path = dirname(path)
|
||||
self.path_wid.set_edit_text(os.path.split(path)[0])
|
||||
|
||||
def onDirClick(self, wid):
|
||||
path = os.path.abspath(self.path_wid.get_edit_text())
|
||||
if not os.path.isdir(path):
|
||||
path = dirname(path)
|
||||
self.path_wid.set_edit_text(os.path.join(path,wid.get_text()))
|
||||
|
||||
def onFileClick(self, wid):
|
||||
self.ok_cb(os.path.abspath(os.path.join(self.files_wid.path,wid.get_text())))
|
||||
|
|
@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
import urwid
|
||||
import custom_widgets
|
||||
from urwid_satext import sat_widgets
|
||||
from tools.jid import JID
|
||||
from quick_frontend.quick_gateways import QuickGatewaysManager
|
||||
|
||||
|
|
@ -37,19 +37,19 @@ class GatewaysManager(urwid.WidgetWrap, QuickGatewaysManager):
|
|||
for gateway in gateways:
|
||||
self.addGateway(widget_list,gateway, gateways[gateway])
|
||||
widget_list.append(urwid.Divider())
|
||||
self.ext_serv = custom_widgets.AdvancedEdit(_("Use external XMPP server: "))
|
||||
go_button = custom_widgets.CustomButton( _("GO !"),self.browseExternalServer)
|
||||
self.ext_serv = sat_widgets.AdvancedEdit(_("Use external XMPP server: "))
|
||||
go_button = sat_widgets.CustomButton( _("GO !"),self.browseExternalServer)
|
||||
ext_serv_col = urwid.Columns([self.ext_serv,('fixed',go_button.getSize(),go_button)])
|
||||
widget_list.append(ext_serv_col)
|
||||
list_wid = urwid.ListBox(widget_list)
|
||||
decorated = custom_widgets.LabelLine(list_wid, custom_widgets.SurroundedText(title))
|
||||
decorated = sat_widgets.LabelLine(list_wid, sat_widgets.SurroundedText(title))
|
||||
urwid.WidgetWrap.__init__(self, decorated)
|
||||
|
||||
def browseExternalServer(self, button):
|
||||
"""Open the gateway manager on given server"""
|
||||
server = self.ext_serv.get_edit_text()
|
||||
if not server:
|
||||
popup = custom_widgets.Alert(_("Error"), _("You must enter an external server JID"), ok_cb=self.host.removePopUp)
|
||||
popup = sat_widgets.Alert(_("Error"), _("You must enter an external server JID"), ok_cb=self.host.removePopUp)
|
||||
self.host.showPopUp(popup)
|
||||
return
|
||||
id = self.host.bridge.findGateways(server, self.host.profile)
|
||||
|
|
@ -67,10 +67,10 @@ class GatewaysManager(urwid.WidgetWrap, QuickGatewaysManager):
|
|||
|
||||
#The buttons
|
||||
|
||||
reg_button = custom_widgets.CustomButton( _("Register"), self.onRegister)
|
||||
reg_button = sat_widgets.CustomButton( _("Register"), self.onRegister)
|
||||
reg_button.gateway_jid = JID(gateway)
|
||||
widget_col.append(('fixed',reg_button.getSize(),reg_button))
|
||||
unreg_button = custom_widgets.CustomButton( _("Unregister"), self.onUnregister)
|
||||
unreg_button = sat_widgets.CustomButton( _("Unregister"), self.onUnregister)
|
||||
unreg_button.gateway_jid = JID(gateway)
|
||||
widget_col.append(('fixed',unreg_button.getSize(),unreg_button))
|
||||
widget_list.append(urwid.Columns(widget_col,1))
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ from profile_manager import ProfileManager
|
|||
from contact_list import ContactList
|
||||
from chat import Chat
|
||||
from gateways import GatewaysManager
|
||||
import custom_widgets
|
||||
from urwid_satext import sat_widgets
|
||||
import logging
|
||||
from logging import debug, info, error
|
||||
import sys, os
|
||||
|
|
@ -99,7 +99,7 @@ class PrimitivusApp(QuickApp):
|
|||
|
||||
##misc setup##
|
||||
self.chat_wins=ChatList(self)
|
||||
self.notBar = custom_widgets.NotificationBar()
|
||||
self.notBar = sat_widgets.NotificationBar()
|
||||
urwid.connect_signal(self.notBar,'change',self.onNotification)
|
||||
self.progress_wid = Progress(self)
|
||||
urwid.connect_signal(self.notBar.progress,'click',lambda x:self.addWindow(self.progress_wid))
|
||||
|
|
@ -196,7 +196,7 @@ class PrimitivusApp(QuickApp):
|
|||
return input
|
||||
|
||||
def __buildMenuRoller(self):
|
||||
menu = custom_widgets.Menu(self.loop)
|
||||
menu = sat_widgets.Menu(self.loop)
|
||||
general = _("General")
|
||||
menu.addMenu(general, _("Connect"), self.onConnectRequest)
|
||||
menu.addMenu(general, _("Disconnect"), self.onDisconnectRequest)
|
||||
|
|
@ -221,18 +221,18 @@ class PrimitivusApp(QuickApp):
|
|||
assert(type=="NORMAL") #TODO: manage other types
|
||||
menu.addMenu(unicode(category), unicode(item), add_menu_cb)
|
||||
|
||||
menu_roller = custom_widgets.MenuRoller([(_('Main menu'),menu)])
|
||||
menu_roller = sat_widgets.MenuRoller([(_('Main menu'),menu)])
|
||||
return menu_roller
|
||||
|
||||
def __buildMainWidget(self):
|
||||
self.contactList = ContactList(self, self.CM, on_click = self.contactSelected, on_change=lambda w: self.redraw())
|
||||
#self.center_part = urwid.Columns([('weight',2,self.contactList),('weight',8,Chat('',self))])
|
||||
self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))])
|
||||
self.editBar = custom_widgets.AdvancedEdit('> ')
|
||||
self.editBar = sat_widgets.AdvancedEdit('> ')
|
||||
self.editBar.setCompletionMethod(self._nick_completion)
|
||||
urwid.connect_signal(self.editBar,'click',self.onTextEntered)
|
||||
self.menu_roller = self.__buildMenuRoller()
|
||||
self.main_widget = custom_widgets.FocusFrame(self.center_part, header=self.menu_roller, footer=self.editBar, focus_part='footer')
|
||||
self.main_widget = sat_widgets.FocusFrame(self.center_part, header=self.menu_roller, footer=self.editBar, focus_part='footer')
|
||||
return self.main_widget
|
||||
|
||||
def _nick_completion(self, text, completion_data):
|
||||
|
|
@ -357,25 +357,25 @@ class PrimitivusApp(QuickApp):
|
|||
|
||||
def showDialog(self, message, title="", type="info", answer_cb = None, answer_data = None):
|
||||
if type == 'info':
|
||||
popup = custom_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
|
||||
popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
|
||||
flags = wx.OK | wx.ICON_INFORMATION
|
||||
elif type == 'error':
|
||||
popup = custom_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
|
||||
popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
|
||||
elif type == 'yes/no':
|
||||
popup = custom_widgets.ConfirmDialog(unicode(message),
|
||||
popup = sat_widgets.ConfirmDialog(unicode(message),
|
||||
yes_cb=self._dialogOkCb, yes_value = (answer_cb, answer_data),
|
||||
no_cb=self._dialogCancelCb, no_value = (answer_cb, answer_data))
|
||||
else:
|
||||
popup = custom_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
|
||||
popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
|
||||
error(_('unmanaged dialog type: %s'), type)
|
||||
self.showPopUp(popup)
|
||||
|
||||
def onNotification(self, notBar):
|
||||
"""Called when a new notification has been received"""
|
||||
if not isinstance(self.main_widget, custom_widgets.FocusFrame):
|
||||
if not isinstance(self.main_widget, sat_widgets.FocusFrame):
|
||||
#if we are not in the main configuration, we ignore the notifications bar
|
||||
return
|
||||
if isinstance(self.main_widget.footer,custom_widgets.AdvancedEdit):
|
||||
if isinstance(self.main_widget.footer,sat_widgets.AdvancedEdit):
|
||||
if not self.notBar.canHide():
|
||||
#the notification bar is not visible and has usefull informations, we show it
|
||||
pile = urwid.Pile([self.notBar, self.editBar])
|
||||
|
|
@ -411,7 +411,7 @@ class PrimitivusApp(QuickApp):
|
|||
ui.show('window')
|
||||
elif type == "ERROR":
|
||||
self.current_action_ids.remove(id)
|
||||
self.showPopUp(custom_widgets.Alert(_("Error"), unicode(data["message"]), ok_cb=self.removePopUp)) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
|
||||
self.showPopUp(sat_widgets.Alert(_("Error"), unicode(data["message"]), ok_cb=self.removePopUp)) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
|
||||
elif type == "RESULT":
|
||||
self.current_action_ids.remove(id)
|
||||
if self.current_action_ids_cb.has_key(id):
|
||||
|
|
@ -437,7 +437,7 @@ class PrimitivusApp(QuickApp):
|
|||
else:
|
||||
message = _("'%s' is an invalid JID !") % room_jid
|
||||
error (message)
|
||||
self.showPopUp(custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
|
||||
self.showPopUp(sat_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
|
||||
|
||||
def onAddContact(self, button, edit):
|
||||
self.removePopUp()
|
||||
|
|
@ -447,7 +447,7 @@ class PrimitivusApp(QuickApp):
|
|||
else:
|
||||
message = _("'%s' is an invalid JID !") % jid
|
||||
error (message)
|
||||
self.showPopUp(custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
|
||||
self.showPopUp(sat_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
|
||||
|
||||
def onRemoveContact(self, button):
|
||||
self.removePopUp()
|
||||
|
|
@ -471,7 +471,7 @@ class PrimitivusApp(QuickApp):
|
|||
|
||||
def onJoinRoomRequest(self, menu):
|
||||
"""User wants to join a MUC room"""
|
||||
pop_up_widget = custom_widgets.InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt = 'room@muc_service.server.tld', cancel_cb=self.removePopUp, ok_cb=self.onJoinRoom)
|
||||
pop_up_widget = sat_widgets.InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt = 'room@muc_service.server.tld', cancel_cb=self.removePopUp, ok_cb=self.onJoinRoom)
|
||||
self.showPopUp(pop_up_widget)
|
||||
|
||||
def onFindGatewaysRequest(self, e):
|
||||
|
|
@ -481,19 +481,19 @@ class PrimitivusApp(QuickApp):
|
|||
self.current_action_ids_cb[id] = self.onGatewaysFound
|
||||
|
||||
def onAddContactRequest(self, menu):
|
||||
pop_up_widget = custom_widgets.InputDialog(_("Adding a contact"), _("Please enter new contact JID"), default_txt = 'name@server.tld', cancel_cb=self.removePopUp, ok_cb=self.onAddContact)
|
||||
pop_up_widget = sat_widgets.InputDialog(_("Adding a contact"), _("Please enter new contact JID"), default_txt = 'name@server.tld', cancel_cb=self.removePopUp, ok_cb=self.onAddContact)
|
||||
self.showPopUp(pop_up_widget)
|
||||
|
||||
def onRemoveContactRequest(self, menu):
|
||||
contact = self.contactList.get_contact()
|
||||
if not contact:
|
||||
self.showPopUp(custom_widgets.Alert(_("Error"), _("You have not selected any contact to delete !"), ok_cb=self.removePopUp))
|
||||
self.showPopUp(sat_widgets.Alert(_("Error"), _("You have not selected any contact to delete !"), ok_cb=self.removePopUp))
|
||||
else:
|
||||
pop_up_widget = custom_widgets.ConfirmDialog(_("Are you sure you want to delete the contact [%s] ?" % contact), yes_cb=self.onRemoveContact, no_cb=self.removePopUp)
|
||||
pop_up_widget = sat_widgets.ConfirmDialog(_("Are you sure you want to delete the contact [%s] ?" % contact), yes_cb=self.onRemoveContact, no_cb=self.removePopUp)
|
||||
self.showPopUp(pop_up_widget)
|
||||
|
||||
def onAboutRequest(self, menu):
|
||||
self.showPopUp(custom_widgets.Alert(_("About"), const_APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp))
|
||||
self.showPopUp(sat_widgets.Alert(_("About"), const_APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp))
|
||||
|
||||
#MISC CALLBACKS#
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
import urwid
|
||||
from custom_widgets import Password,List,InputDialog,ConfirmDialog,Alert,FocusFrame
|
||||
from urwid_satext.sat_widgets import Password,List,InputDialog,ConfirmDialog,Alert,FocusFrame
|
||||
from tools.jid import JID
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
import urwid
|
||||
import custom_widgets
|
||||
from urwid_satext import sat_widgets
|
||||
from tools.jid import JID
|
||||
|
||||
|
||||
|
|
@ -32,10 +32,10 @@ class Progress(urwid.WidgetWrap):
|
|||
self.progress_dict = {}
|
||||
listbox = urwid.ListBox(self.progress_list)
|
||||
buttons = []
|
||||
buttons.append(custom_widgets.CustomButton(_('Clear progress list'), self.__onClear))
|
||||
buttons.append(sat_widgets.CustomButton(_('Clear progress list'), self.__onClear))
|
||||
max_len = max([button.getSize() for button in buttons])
|
||||
buttons_wid = urwid.GridFlow(buttons,max_len,1,0,'center')
|
||||
main_wid = custom_widgets.FocusFrame(listbox, footer=buttons_wid)
|
||||
main_wid = sat_widgets.FocusFrame(listbox, footer=buttons_wid)
|
||||
urwid.WidgetWrap.__init__(self, main_wid)
|
||||
|
||||
def addProgress(self, id, message):
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
import urwid
|
||||
from logging import debug, info, warning, error
|
||||
import custom_widgets
|
||||
from urwid_satext import sat_widgets
|
||||
from xml.dom import minidom
|
||||
|
||||
class Pairs(urwid.WidgetWrap):
|
||||
|
|
@ -82,24 +82,24 @@ class XMLUI(urwid.WidgetWrap):
|
|||
elif type=="label":
|
||||
ctrl = urwid.Text(value+": ")
|
||||
elif type=="string":
|
||||
ctrl = custom_widgets.AdvancedEdit(edit_text = value)
|
||||
ctrl = sat_widgets.AdvancedEdit(edit_text = value)
|
||||
self.ctrl_list[name] = ({'type':type, 'control':ctrl})
|
||||
elif type=="password":
|
||||
ctrl = custom_widgets.Password(edit_text = value)
|
||||
ctrl = sat_widgets.Password(edit_text = value)
|
||||
self.ctrl_list[name] = ({'type':type, 'control':ctrl})
|
||||
elif type=="textbox":
|
||||
ctrl = custom_widgets.AdvancedEdit(edit_text = value, multiline=True)
|
||||
ctrl = sat_widgets.AdvancedEdit(edit_text = value, multiline=True)
|
||||
self.ctrl_list[name] = ({'type':type, 'control':ctrl})
|
||||
elif type=="bool":
|
||||
ctrl = urwid.CheckBox('', state = value=="true")
|
||||
self.ctrl_list[name] = ({'type':type, 'control':ctrl})
|
||||
elif type=="list":
|
||||
style=[] if elem.getAttribute("multi")=='yes' else ['single']
|
||||
ctrl = custom_widgets.List(options=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style)
|
||||
ctrl = sat_widgets.List(options=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style)
|
||||
self.ctrl_list[name] = ({'type':type, 'control':ctrl})
|
||||
elif type=="button":
|
||||
callback_id = elem.getAttribute("callback_id")
|
||||
ctrl = custom_widgets.CustomButton(value, on_press=self.onButtonPress)
|
||||
ctrl = sat_widgets.CustomButton(value, on_press=self.onButtonPress)
|
||||
ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")])
|
||||
else:
|
||||
error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME !
|
||||
|
|
@ -122,7 +122,7 @@ class XMLUI(urwid.WidgetWrap):
|
|||
if node.nodeName == "layout":
|
||||
type = node.getAttribute('type')
|
||||
if type == "tabs":
|
||||
tab_cont = custom_widgets.TabsContainer()
|
||||
tab_cont = sat_widgets.TabsContainer()
|
||||
self.__parseChilds(current, node, ['category'], tab_cont)
|
||||
current.append(tab_cont)
|
||||
elif type == "vertical":
|
||||
|
|
@ -137,7 +137,7 @@ class XMLUI(urwid.WidgetWrap):
|
|||
elif node.nodeName == "category":
|
||||
name = node.getAttribute('name')
|
||||
label = node.getAttribute('label')
|
||||
if not name or not isinstance(data,custom_widgets.TabsContainer):
|
||||
if not name or not isinstance(data,sat_widgets.TabsContainer):
|
||||
raise InvalidXMLUI
|
||||
if self.type == 'param':
|
||||
self._current_category = name #XXX: awful hack because params need category and we don't keep parent
|
||||
|
|
@ -167,7 +167,7 @@ class XMLUI(urwid.WidgetWrap):
|
|||
|
||||
assert ret_wid.body
|
||||
|
||||
if isinstance(ret_wid.body[0],custom_widgets.TabsContainer):
|
||||
if isinstance(ret_wid.body[0],sat_widgets.TabsContainer):
|
||||
ret_wid = ret_wid.body[0] #xxx: awfull hack cause TabsContainer is a BoxWidget, can't be inside a ListBox
|
||||
|
||||
|
||||
|
|
@ -180,10 +180,10 @@ class XMLUI(urwid.WidgetWrap):
|
|||
grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center')
|
||||
ret_wid.body.append(grid_wid)
|
||||
elif self.type == 'param':
|
||||
assert(isinstance(ret_wid,custom_widgets.TabsContainer))
|
||||
assert(isinstance(ret_wid,sat_widgets.TabsContainer))
|
||||
buttons = []
|
||||
buttons.append(custom_widgets.CustomButton(_('Save'),self.onSaveParams))
|
||||
buttons.append(custom_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow()))
|
||||
buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams))
|
||||
buttons.append(sat_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow()))
|
||||
max_len = max([button.getSize() for button in buttons])
|
||||
grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center')
|
||||
ret_wid.addFooter(grid_wid)
|
||||
|
|
@ -195,7 +195,7 @@ class XMLUI(urwid.WidgetWrap):
|
|||
- popup
|
||||
- window"""
|
||||
self.__dest = "popup"
|
||||
decorated = custom_widgets.LabelLine(self, custom_widgets.SurroundedText(self.title or ''))
|
||||
decorated = sat_widgets.LabelLine(self, sat_widgets.SurroundedText(self.title or ''))
|
||||
if show_type == 'popup':
|
||||
self.host.showPopUp(decorated)
|
||||
elif show_type == 'window':
|
||||
|
|
@ -213,7 +213,7 @@ class XMLUI(urwid.WidgetWrap):
|
|||
data = {"callback_id":callback_id}
|
||||
for field in fields:
|
||||
ctrl = self.ctrl_list[field]
|
||||
if isinstance(ctrl['control'],custom_widgets.List):
|
||||
if isinstance(ctrl['control'],sat_widgets.List):
|
||||
data[field] = '\t'.join(ctrl['control'].getSelectedValues())
|
||||
else:
|
||||
data[field] = ctrl['control'].getValue()
|
||||
|
|
@ -230,7 +230,7 @@ class XMLUI(urwid.WidgetWrap):
|
|||
data = []
|
||||
for ctrl_name in self.ctrl_list:
|
||||
ctrl = self.ctrl_list[ctrl_name]
|
||||
if isinstance(ctrl['control'], custom_widgets.List):
|
||||
if isinstance(ctrl['control'], sat_widgets.List):
|
||||
data.append((ctrl_name, ctrl['control'].getSelectedValue()))
|
||||
elif isinstance(ctrl['control'], urwid.CheckBox):
|
||||
data.append((ctrl_name, "true" if ctrl['control'].get_state() else "false"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue