frontends: XMLUI refactoring + dialogs:
- there are now XMLUIPanel and XMLUIDialog both inheriting from XMLUIBase
- following dialogs are managed:
- MessageDialog
- NoteDialog
- ConfirmDialog
- FileDialog
- XMLUI creation is now made using xmlui.create(...) instead of instanciating directly XMLUI
- classes must be registed in frontends
- "parent" attribute renamed to "_xmlui_parent" to avoid name conflicts with frontends toolkits
This commit is contained in:
parent
38efb8b0bd
commit
b6563c596b
5 changed files with 516 additions and 228 deletions
|
|
@ -22,7 +22,7 @@ import urwid
|
|||
from urwid_satext import sat_widgets
|
||||
from sat_frontends.tools.games import TarotCard
|
||||
from sat_frontends.quick_frontend.quick_card_game import QuickCardGame
|
||||
from sat_frontends.primitivus.xmlui import XMLUI
|
||||
from sat_frontends.primitivus import xmlui
|
||||
|
||||
|
||||
class CardDisplayer(urwid.Text):
|
||||
|
|
@ -269,7 +269,7 @@ class CardGame(QuickCardGame, urwid.WidgetWrap):
|
|||
def chooseContrat(self, xml_data):
|
||||
"""Called when the player has to select his contrat
|
||||
@param xml_data: SàT xml representation of the form"""
|
||||
form = XMLUI(self.parent.host, xml_data, title=_('Please choose your contrat'), flags=['NO_CANCEL'])
|
||||
form = xmlui.create(self.parent.host, xml_data, title=_('Please choose your contrat'), flags=['NO_CANCEL'])
|
||||
form.show(valign='top')
|
||||
|
||||
def showCards(self, game_stage, cards, data):
|
||||
|
|
@ -288,7 +288,7 @@ class CardGame(QuickCardGame, urwid.WidgetWrap):
|
|||
title = _("Draw game")
|
||||
else:
|
||||
title = _('You win \o/') if self.player_nick in winners else _('You loose :(')
|
||||
form = XMLUI(self.parent.host, xml_data, title=title, flags=['NO_CANCEL'])
|
||||
form = xmlui.create(self.parent.host, xml_data, title=title, flags=['NO_CANCEL'])
|
||||
form.show()
|
||||
|
||||
def invalidCards(self, phase, played_cards, invalid_cards):
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ from urwid_satext.files_management import FileDialog
|
|||
from sat_frontends.quick_frontend.quick_chat import QuickChat
|
||||
from sat_frontends.primitivus.card_game import CardGame
|
||||
from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate
|
||||
from sat_frontends.primitivus.xmlui import XMLUI
|
||||
from sat_frontends.primitivus import xmlui
|
||||
from sat_frontends.primitivus.constants import Const as C
|
||||
import time
|
||||
from sat.tools.jid import JID
|
||||
|
|
@ -352,8 +352,8 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
|||
self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile)
|
||||
|
||||
def onConfigureRoom(self, menu):
|
||||
def gotUI(xmlui):
|
||||
self.host.addWindow(XMLUI(self.host, xmlui))
|
||||
def gotUI(xml_ui):
|
||||
self.host.addWindow(xmlui.create(self.host, xml_ui))
|
||||
def configureError(failure):
|
||||
self.host.showPopUp(sat_widgets.Alert(failure.fullname, failure.message, ok_cb=self.host.removePopUp))
|
||||
self.host.bridge.configureRoom(self.id, self.host.profile, callback=gotUI, errback=configureError)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ from sat_frontends.quick_frontend.quick_utils import getNewPath, unescapePrivate
|
|||
from sat_frontends.primitivus.profile_manager import ProfileManager
|
||||
from sat_frontends.primitivus.contact_list import ContactList
|
||||
from sat_frontends.primitivus.chat import Chat
|
||||
from sat_frontends.primitivus.xmlui import XMLUI
|
||||
from sat_frontends.primitivus import xmlui
|
||||
from sat_frontends.primitivus.progress import Progress
|
||||
from sat_frontends.primitivus.notify import Notify
|
||||
from sat_frontends.tools.misc import InputHistory
|
||||
|
|
@ -462,7 +462,7 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
# action was a one shot, nothing to do
|
||||
pass
|
||||
elif "xmlui" in data:
|
||||
ui = XMLUI(self, xml_data=data['xmlui'])
|
||||
ui = xmlui.create(self, xml_data=data['xmlui'])
|
||||
ui.show()
|
||||
elif "authenticated_profile" in data:
|
||||
assert("caller" in data)
|
||||
|
|
@ -529,7 +529,7 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
title = _('Registration')
|
||||
misc['target'] = data['target']
|
||||
misc['action_back'] = self.bridge.gatewayRegister
|
||||
ui = XMLUI(self, title=title, xml_data = data['xml'], misc = misc)
|
||||
ui = xmlui.create(self, title=title, xml_data = data['xml'], misc = misc)
|
||||
if data['type'] == 'registration':
|
||||
ui.show('popup')
|
||||
else:
|
||||
|
|
@ -573,7 +573,7 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
|
||||
def onParam(self, menu):
|
||||
def success(params):
|
||||
self.addWindow(XMLUI(self, xml_data=params))
|
||||
self.addWindow(xmlui.create(self, xml_data=params))
|
||||
|
||||
def failure(error):
|
||||
self.showPopUp(sat_widgets.Alert(_("Error"), _("Can't get parameters (%s)") % error, ok_cb=self.removePopUp))
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@
|
|||
|
||||
from sat.core.i18n import _
|
||||
import urwid
|
||||
import copy
|
||||
from urwid_satext import sat_widgets
|
||||
from sat_frontends.primitivus.xmlui import XMLUI
|
||||
from sat_frontends.constants import Const as commonConst
|
||||
from sat_frontends.primitivus.constants import Const
|
||||
|
||||
|
|
|
|||
|
|
@ -21,15 +21,17 @@ from sat.core.i18n import _
|
|||
import urwid
|
||||
import copy
|
||||
from urwid_satext import sat_widgets
|
||||
from urwid_satext import files_management
|
||||
from sat.core.log import getLogger
|
||||
log = getLogger(__name__)
|
||||
from sat_frontends.primitivus.constants import Const as C
|
||||
from sat_frontends.tools import xmlui
|
||||
|
||||
|
||||
class PrimitivusEvents(object):
|
||||
""" Used to manage change event of Primitivus widgets """
|
||||
|
||||
def _event_callback(self, ctrl, *args, **ktkwargs):
|
||||
def _event_callback(self, ctrl, *args, **kwargs):
|
||||
"""" Call xmlui callback and ignore any extra argument """
|
||||
args[-1](ctrl)
|
||||
|
||||
|
|
@ -40,20 +42,20 @@ class PrimitivusEvents(object):
|
|||
|
||||
class PrimitivusEmptyWidget(xmlui.EmptyWidget, urwid.Text):
|
||||
|
||||
def __init__(self, parent):
|
||||
def __init__(self, _xmlui_parent):
|
||||
urwid.Text.__init__(self, '')
|
||||
|
||||
|
||||
class PrimitivusTextWidget(xmlui.TextWidget, urwid.Text):
|
||||
|
||||
def __init__(self, parent, value, read_only=False):
|
||||
def __init__(self, _xmlui_parent, value, read_only=False):
|
||||
urwid.Text.__init__(self, value)
|
||||
|
||||
|
||||
class PrimitivusLabelWidget(xmlui.LabelWidget, PrimitivusTextWidget):
|
||||
|
||||
def __init__(self, parent, value):
|
||||
super(PrimitivusLabelWidget, self).__init__(parent, value+": ")
|
||||
def __init__(self, _xmlui_parent, value):
|
||||
super(PrimitivusLabelWidget, self).__init__(_xmlui_parent, value+": ")
|
||||
|
||||
|
||||
class PrimitivusJidWidget(xmlui.JidWidget, PrimitivusTextWidget):
|
||||
|
|
@ -62,7 +64,7 @@ class PrimitivusJidWidget(xmlui.JidWidget, PrimitivusTextWidget):
|
|||
|
||||
class PrimitivusDividerWidget(xmlui.DividerWidget, urwid.Divider):
|
||||
|
||||
def __init__(self, parent, style='line'):
|
||||
def __init__(self, _xmlui_parent, style='line'):
|
||||
if style == 'line':
|
||||
div_char = u'─'
|
||||
elif style == 'dot':
|
||||
|
|
@ -82,7 +84,7 @@ class PrimitivusDividerWidget(xmlui.DividerWidget, urwid.Divider):
|
|||
|
||||
class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, PrimitivusEvents):
|
||||
|
||||
def __init__(self, parent, value, read_only=False):
|
||||
def __init__(self, _xmlui_parent, value, read_only=False):
|
||||
sat_widgets.AdvancedEdit.__init__(self, edit_text=value)
|
||||
self.read_only = read_only
|
||||
|
||||
|
|
@ -100,7 +102,7 @@ class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, Primi
|
|||
|
||||
class PrimitivusPasswordWidget(xmlui.PasswordWidget, sat_widgets.Password, PrimitivusEvents):
|
||||
|
||||
def __init__(self, parent, value, read_only=False):
|
||||
def __init__(self, _xmlui_parent, value, read_only=False):
|
||||
sat_widgets.Password.__init__(self, edit_text=value)
|
||||
self.read_only = read_only
|
||||
|
||||
|
|
@ -118,7 +120,7 @@ class PrimitivusPasswordWidget(xmlui.PasswordWidget, sat_widgets.Password, Primi
|
|||
|
||||
class PrimitivusTextBoxWidget(xmlui.TextBoxWidget, sat_widgets.AdvancedEdit, PrimitivusEvents):
|
||||
|
||||
def __init__(self, parent, value, read_only=False):
|
||||
def __init__(self, _xmlui_parent, value, read_only=False):
|
||||
sat_widgets.AdvancedEdit.__init__(self, edit_text=value, multiline=True)
|
||||
self.read_only = read_only
|
||||
|
||||
|
|
@ -136,7 +138,7 @@ class PrimitivusTextBoxWidget(xmlui.TextBoxWidget, sat_widgets.AdvancedEdit, Pri
|
|||
|
||||
class PrimitivusBoolWidget(xmlui.BoolWidget, urwid.CheckBox, PrimitivusEvents):
|
||||
|
||||
def __init__(self, parent, state, read_only=False):
|
||||
def __init__(self, _xmlui_parent, state, read_only=False):
|
||||
urwid.CheckBox.__init__(self, '', state=state)
|
||||
self.read_only = read_only
|
||||
|
||||
|
|
@ -154,7 +156,7 @@ class PrimitivusBoolWidget(xmlui.BoolWidget, urwid.CheckBox, PrimitivusEvents):
|
|||
|
||||
class PrimitivusButtonWidget(xmlui.ButtonWidget, sat_widgets.CustomButton, PrimitivusEvents):
|
||||
|
||||
def __init__(self, parent, value, click_callback):
|
||||
def __init__(self, _xmlui_parent, value, click_callback):
|
||||
sat_widgets.CustomButton.__init__(self, value, on_press=click_callback)
|
||||
|
||||
def _xmluiOnClick(self, callback):
|
||||
|
|
@ -163,7 +165,7 @@ class PrimitivusButtonWidget(xmlui.ButtonWidget, sat_widgets.CustomButton, Primi
|
|||
|
||||
class PrimitivusListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents):
|
||||
|
||||
def __init__(self, parent, options, selected, flags):
|
||||
def __init__(self, _xmlui_parent, options, selected, flags):
|
||||
sat_widgets.List.__init__(self, options=options, style=flags)
|
||||
self._xmluiSelectValues(selected)
|
||||
|
||||
|
|
@ -194,7 +196,7 @@ class PrimitivusListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents)
|
|||
|
||||
class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer, PrimitivusEvents):
|
||||
|
||||
def __init__(self, parent, columns, selectable='no'):
|
||||
def __init__(self, _xmlui_parent, columns, selectable='no'):
|
||||
options = {'ADAPT':()}
|
||||
if selectable != 'no':
|
||||
options['HIGHLIGHT'] = ()
|
||||
|
|
@ -219,7 +221,7 @@ class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.T
|
|||
|
||||
class PrimitivusPairsContainer(xmlui.PairsContainer, sat_widgets.TableContainer):
|
||||
|
||||
def __init__(self, parent):
|
||||
def __init__(self, _xmlui_parent):
|
||||
options = {'ADAPT':(0,), 'HIGHLIGHT':(0,)}
|
||||
if self._xmlui_main.type == 'param':
|
||||
options['FOCUS_ATTR'] = 'param_selected'
|
||||
|
|
@ -234,7 +236,7 @@ class PrimitivusPairsContainer(xmlui.PairsContainer, sat_widgets.TableContainer)
|
|||
|
||||
class PrimitivusTabsContainer(xmlui.TabsContainer, sat_widgets.TabsContainer):
|
||||
|
||||
def __init__(self, parent):
|
||||
def __init__(self, _xmlui_parent):
|
||||
sat_widgets.TabsContainer.__init__(self)
|
||||
|
||||
def _xmluiAppend(self, widget):
|
||||
|
|
@ -249,7 +251,7 @@ class PrimitivusTabsContainer(xmlui.TabsContainer, sat_widgets.TabsContainer):
|
|||
class PrimitivusVerticalContainer(xmlui.VerticalContainer, urwid.ListBox):
|
||||
BOX_HEIGHT = 5
|
||||
|
||||
def __init__(self, parent):
|
||||
def __init__(self, _xmlui_parent):
|
||||
urwid.ListBox.__init__(self, urwid.SimpleListWalker([]))
|
||||
self._last_size = None
|
||||
|
||||
|
|
@ -269,24 +271,81 @@ class PrimitivusVerticalContainer(xmlui.VerticalContainer, urwid.ListBox):
|
|||
return super(PrimitivusVerticalContainer, self).render(size, focus)
|
||||
|
||||
|
||||
class WidgetFactory(object):
|
||||
### Dialogs ###
|
||||
|
||||
|
||||
class PrimitivusDialog(object):
|
||||
|
||||
def __init__(self, _xmlui_parent):
|
||||
self.host = _xmlui_parent.host
|
||||
|
||||
def _xmluiShow(self):
|
||||
self.host.showPopUp(self)
|
||||
|
||||
def _xmluiClose(self):
|
||||
self.host.removePopUp()
|
||||
|
||||
|
||||
class PrimitivusMessageDialog(PrimitivusDialog, xmlui.MessageDialog, sat_widgets.Alert):
|
||||
|
||||
def __init__(self, _xmlui_parent, title, message, level):
|
||||
PrimitivusDialog.__init__(self, _xmlui_parent)
|
||||
xmlui.MessageDialog.__init__(self, _xmlui_parent)
|
||||
sat_widgets.Alert.__init__(self, title, message, ok_cb=lambda dummy: self._xmluiValidated())
|
||||
|
||||
|
||||
class PrimitivusNoteDialog(xmlui.NoteDialog, PrimitivusMessageDialog):
|
||||
# TODO: separate NoteDialog
|
||||
pass
|
||||
|
||||
|
||||
class PrimitivusConfirmDialog(PrimitivusDialog, xmlui.ConfirmDialog, sat_widgets.ConfirmDialog):
|
||||
|
||||
def __init__(self, _xmlui_parent, title, message, level, buttons_set):
|
||||
PrimitivusDialog.__init__(self, _xmlui_parent)
|
||||
xmlui.ConfirmDialog.__init__(self, _xmlui_parent)
|
||||
sat_widgets.ConfirmDialog.__init__(self, title, message, no_cb=lambda dummy: self._xmluiCancelled(), yes_cb=lambda dummy: self._xmluiValidated())
|
||||
|
||||
|
||||
class PrimitivusFileDialog(PrimitivusDialog, xmlui.FileDialog, files_management.FileDialog):
|
||||
|
||||
def __init__(self, _xmlui_parent, title, message, level, filetype):
|
||||
# TODO: message is not managed yet
|
||||
PrimitivusDialog.__init__(self, _xmlui_parent)
|
||||
xmlui.FileDialog.__init__(self, _xmlui_parent)
|
||||
style = []
|
||||
if filetype == C.XMLUI_DATA_FILETYPE_DIR:
|
||||
style.append('dir')
|
||||
files_management.FileDialog.__init__(self, ok_cb=lambda path: self._xmluiValidated({'path': path}), cancel_cb=lambda dummy: self._xmluiCancelled(), title=title)
|
||||
|
||||
|
||||
class GenericFactory(object):
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if attr.startswith("create"):
|
||||
cls = globals()["Primitivus" + attr[6:]] # XXX: we prefix with "Primitivus" to work around an Urwid bug, WidgetMeta in Urwid don't manage multiple inheritance with same names
|
||||
return cls
|
||||
|
||||
|
||||
class WidgetFactory(GenericFactory):
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if attr.startswith("create"):
|
||||
cls = GenericFactory.__getattr__(self, attr)
|
||||
cls._xmlui_main = self._xmlui_main
|
||||
return cls
|
||||
|
||||
class XMLUI(xmlui.XMLUI, urwid.WidgetWrap):
|
||||
|
||||
class XMLUIPanel(xmlui.XMLUIPanel, urwid.WidgetWrap):
|
||||
widget_factory = WidgetFactory()
|
||||
|
||||
def __init__(self, host, xml_data, title = None, flags = None):
|
||||
def __init__(self, host, parsed_xml, title = None, flags = None):
|
||||
self.widget_factory._xmlui_main = self
|
||||
self._dest = None
|
||||
xmlui.XMLUI.__init__(self, host, xml_data, title, flags)
|
||||
xmlui.XMLUIPanel.__init__(self, host, parsed_xml, title, flags)
|
||||
urwid.WidgetWrap.__init__(self, self.main_cont)
|
||||
|
||||
def constructUI(self, xml_data):
|
||||
def constructUI(self, parsed_dom):
|
||||
def postTreat():
|
||||
assert self.main_cont.body
|
||||
|
||||
|
|
@ -311,7 +370,7 @@ class XMLUI(xmlui.XMLUI, urwid.WidgetWrap):
|
|||
grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center')
|
||||
tabs_cont.addFooter(grid_wid)
|
||||
|
||||
super(XMLUI, self).constructUI(xml_data, postTreat)
|
||||
xmlui.XMLUIPanel.constructUI(self, parsed_dom, postTreat)
|
||||
urwid.WidgetWrap.__init__(self, self.main_cont)
|
||||
|
||||
def show(self, show_type=None, valign='middle'):
|
||||
|
|
@ -321,7 +380,7 @@ class XMLUI(xmlui.XMLUI, urwid.WidgetWrap):
|
|||
- 'popup'
|
||||
- 'window'
|
||||
@param valign: vertical alignment when show_type is 'popup'.
|
||||
Ignored when show_type is 'window'.
|
||||
Ignored when show_type is 'window'.
|
||||
|
||||
"""
|
||||
if show_type is None:
|
||||
|
|
@ -343,9 +402,17 @@ class XMLUI(xmlui.XMLUI, urwid.WidgetWrap):
|
|||
assert(False)
|
||||
self.host.redraw()
|
||||
|
||||
|
||||
def _xmluiClose(self):
|
||||
if self._dest == 'window':
|
||||
self.host.removeWindow()
|
||||
else:
|
||||
self.host.removePopUp()
|
||||
|
||||
|
||||
class XMLUIDialog(xmlui.XMLUIDialog):
|
||||
dialog_factory = GenericFactory()
|
||||
|
||||
|
||||
xmlui.registerClass(xmlui.CLASS_PANEL, XMLUIPanel)
|
||||
xmlui.registerClass(xmlui.CLASS_DIALOG, XMLUIDialog)
|
||||
create = xmlui.create
|
||||
|
|
|
|||
Loading…
Reference in a new issue