Mercurial > libervia-web
diff src/browser/sat_browser/xmlui.py @ 720:bf0a7da558e8
browser side (xmlui): factory is instantiated on Panel init + main panel is passed as first argument to widgets
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 21 Aug 2015 15:37:21 +0200 |
parents | 9a9e2fcc6347 |
children | 102bab805ec1 |
line wrap: on
line diff
--- a/src/browser/sat_browser/xmlui.py Tue Aug 18 10:47:59 2015 +0200 +++ b/src/browser/sat_browser/xmlui.py Fri Aug 21 15:37:21 2015 +0200 @@ -43,34 +43,34 @@ class EmptyWidget(xmlui.EmptyWidget, Label): - def __init__(self, _xmlui_parent): + def __init__(self, xmlui_main, xmlui_parent): Label.__init__(self, '') class TextWidget(xmlui.TextWidget, Label): - def __init__(self, _xmlui_parent, value): + def __init__(self, xmlui_main, xmlui_parent, value): Label.__init__(self, value) class LabelWidget(xmlui.LabelWidget, TextWidget): - def __init__(self, _xmlui_parent, value): - TextWidget.__init__(self, _xmlui_parent, value + ": ") + def __init__(self, xmlui_main, xmlui_parent, value): + TextWidget.__init__(self, xmlui_main, xmlui_parent, value + ": ") class JidWidget(xmlui.JidWidget, TextWidget): - def __init__(self, _xmlui_parent, value): - TextWidget.__init__(self, _xmlui_parent, value) + def __init__(self, xmlui_main, xmlui_parent, value): + TextWidget.__init__(self, xmlui_main, xmlui_parent, value) class DividerWidget(xmlui.DividerWidget, HTML): - def __init__(self, _xmlui_parent, style='line'): + def __init__(self, xmlui_main, xmlui_parent, style='line'): """Add a divider - @param _xmlui_parent + @param xmlui_parent @param style (unicode): one of: - line: a simple line - dot: a line of dots @@ -84,7 +84,7 @@ class StringWidget(xmlui.StringWidget, TextBox): - def __init__(self, _xmlui_parent, value, read_only=False): + def __init__(self, xmlui_main, xmlui_parent, value, read_only=False): TextBox.__init__(self) self.setText(value) self.setReadonly(read_only) @@ -101,13 +101,13 @@ class JidInputWidget(xmlui.JidInputWidget, StringWidget): - def __init__(self, _xmlui_parent, value, read_only=False): - StringWidget.__init__(self, _xmlui_parent, value, read_only) + def __init__(self, xmlui_main, xmlui_parent, value, read_only=False): + StringWidget.__init__(self, xmlui_main, xmlui_parent, value, read_only) class PasswordWidget(xmlui.PasswordWidget, PasswordTextBox): - def __init__(self, _xmlui_parent, value, read_only=False): + def __init__(self, xmlui_main, xmlui_parent, value, read_only=False): PasswordTextBox.__init__(self) self.setText(value) self.setReadonly(read_only) @@ -124,7 +124,7 @@ class TextBoxWidget(xmlui.TextBoxWidget, TextArea): - def __init__(self, _xmlui_parent, value, read_only=False): + def __init__(self, xmlui_main, xmlui_parent, value, read_only=False): TextArea.__init__(self) self.setText(value) self.setReadonly(read_only) @@ -141,7 +141,7 @@ class BoolWidget(xmlui.BoolWidget, CheckBox): - def __init__(self, _xmlui_parent, state, read_only=False): + def __init__(self, xmlui_main, xmlui_parent, state, read_only=False): CheckBox.__init__(self) self.setChecked(state) self.setReadonly(read_only) @@ -158,7 +158,7 @@ class IntWidget(xmlui.IntWidget, TextBox): - def __init__(self, _xmlui_parent, value, read_only=False): + def __init__(self, xmlui_main, xmlui_parent, value, read_only=False): TextBox.__init__(self) self.setText(value) self.setReadonly(read_only) @@ -175,7 +175,7 @@ class ButtonWidget(xmlui.ButtonWidget, Button): - def __init__(self, _xmlui_parent, value, click_callback): + def __init__(self, xmlui_main, xmlui_parent, value, click_callback): Button.__init__(self, value, click_callback) def _xmluiOnClick(self, callback): @@ -184,7 +184,7 @@ class ListWidget(xmlui.ListWidget, ListBox): - def __init__(self, _xmlui_parent, options, selected, flags): + def __init__(self, xmlui_main, xmlui_parent, options, selected, flags): ListBox.__init__(self) multi_selection = 'single' not in flags self.setMultipleSelect(multi_selection) @@ -236,7 +236,7 @@ class AdvancedListContainer(xmlui.AdvancedListContainer, Grid): - def __init__(self, _xmlui_parent, columns, selectable='no'): + def __init__(self, xmlui_main, xmlui_parent, columns, selectable='no'): Grid.__init__(self, 0, columns) self.columns = columns self.row = -1 @@ -282,7 +282,7 @@ class PairsContainer(xmlui.PairsContainer, Grid): - def __init__(self, _xmlui_parent): + def __init__(self, xmlui_main, xmlui_parent): Grid.__init__(self, 0, 0) self.row = 0 self.col = 0 @@ -299,7 +299,7 @@ class TabsContainer(LiberviaContainer, xmlui.TabsContainer, TabPanel): - def __init__(self, _xmlui_parent): + def __init__(self, xmlui_main, xmlui_parent): TabPanel.__init__(self) self.setStyleName('liberviaTabPanel') @@ -314,7 +314,7 @@ class VerticalContainer(LiberviaContainer, xmlui.VerticalContainer, VerticalPanel): __bases__ = (LiberviaContainer, xmlui.VerticalContainer, VerticalPanel) - def __init__(self, _xmlui_parent): + def __init__(self, xmlui_main, xmlui_parent): VerticalPanel.__init__(self) @@ -332,30 +332,30 @@ class MessageDialog(Dlg, xmlui.MessageDialog, dialog.InfoDialog): - def __init__(self, _xmlui_parent, title, message, level): + def __init__(self, xmlui_main, xmlui_parent, title, message, level): #TODO: level is not managed title = html_tools.html_sanitize(title) message = strings.addURLToText(html_tools.XHTML2Text(message)) Dlg.__init__(self) - xmlui.MessageDialog.__init__(self, _xmlui_parent) + xmlui.MessageDialog.__init__(self, xmlui_main, xmlui_parent) dialog.InfoDialog.__init__(self, title, message, self._xmluiValidated()) class NoteDialog(xmlui.NoteDialog, MessageDialog): # TODO: separate NoteDialog - def __init__(self, _xmlui_parent, title, message, level): - xmlui.NoteDialog.__init__(self, _xmlui_parent) - MessageDialog.__init__(self, _xmlui_parent, title, message, level) + def __init__(self, xmlui_main, xmlui_parent, title, message, level): + xmlui.NoteDialog.__init__(self, xmlui_main, xmlui_parent) + MessageDialog.__init__(self, xmlui_main, xmlui_parent, title, message, level) class ConfirmDialog(xmlui.ConfirmDialog, Dlg, dialog.ConfirmDialog): - def __init__(self, _xmlui_parent, title, message, level): + def __init__(self, xmlui_main, xmlui_parent, title, message, level): #TODO: level is not managed title = html_tools.html_sanitize(title) message = strings.addURLToText(html_tools.XHTML2Text(message)) - xmlui.ConfirmDialog.__init__(self, _xmlui_parent) + xmlui.ConfirmDialog.__init__(self, xmlui_main, xmlui_parent) Dlg.__init__(self) dialog.ConfirmDialog.__init__(self, self.answered, message, title) @@ -369,7 +369,7 @@ class FileDialog(xmlui.FileDialog, Dlg): #TODO: - def __init__(self, _xmlui_parent, title, message, level, filetype): + def __init__(self, xmlui_main, xmlui_parent, title, message, level, filetype): raise NotImplementedError("FileDialog is not implemented in Libervia yet") @@ -377,8 +377,8 @@ # XXX: __getattr__ doens't work here with pyjamas for an unknown reason # so an introspection workaround is used - def __init__(self): - + def __init__(self, xmlui_main): + self.xmlui_main = xmlui_main for name, cls in globals().items(): if name.endswith("Widget") or name.endswith("Container") or name.endswith("Dialog"): log.info("registering: %s" % name) @@ -387,7 +387,7 @@ setattr(self, "create%s" % name, createCreater(cls)) def _genericCreate(self, cls, *args, **kwargs): - instance = cls(*args, **kwargs) + instance = cls(self.xmlui_main, *args, **kwargs) return instance # def __getattr__(self, attr): @@ -401,7 +401,6 @@ def _genericCreate(self, cls, *args, **kwargs): instance = GenericFactory._genericCreate(self, cls, *args, **kwargs) - instance._xmlui_main = self._xmlui_main return instance class LiberviaXMLUIBase(object): @@ -411,10 +410,10 @@ class XMLUIPanel(LiberviaXMLUIBase, xmlui.XMLUIPanel, VerticalPanel): - widget_factory = WidgetFactory() def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE): - self.widget_factory._xmlui_main = self + self.widget_factory = WidgetFactory(self) + self.host = host VerticalPanel.__init__(self) self.setSize('100%', '100%') xmlui.XMLUIPanel.__init__(self, host, parsed_xml, title, flags, callback, profile) @@ -460,7 +459,9 @@ dialog_factory = GenericFactory() def __init__(self, host, parsed_dom, title = None, flags = None, callback=None, profile=C.PROF_KEY_NONE): + self.dialog_factory = GenericFactory(self) xmlui.XMLUIDialog.__init__(self, host, parsed_dom, title, flags, callback, profile) + self.host = host xmlui.registerClass(xmlui.CLASS_PANEL, XMLUIPanel) xmlui.registerClass(xmlui.CLASS_DIALOG, XMLUIDialog)