Mercurial > libervia-backend
comparison frontends/src/primitivus/xmlui.py @ 802:9007bb133009
core, frontends: XMLUI refactoring:
- XMLUI now use objects with 2 main classes: widgets (button, label, etc), and container which contain widgets according to a layout
- widgets and containers classes are found through introspection, thereby it's really easy to add a new one
- there is still the AddWidgetName helper, for example AddText('jid', 'test@example.net') will add a StringWidget with name "jid" and default value "test@example.net"
- container can be inside other containers. changeContainer change the first parent container
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 04 Feb 2014 18:19:00 +0100 |
parents | 46aa5ada61bf |
children | f100fd8d279f |
comparison
equal
deleted
inserted
replaced
801:02ee9ef95277 | 802:9007bb133009 |
---|---|
99 def _xmluiSelectValue(self, value): | 99 def _xmluiSelectValue(self, value): |
100 return self.selectValue(value) | 100 return self.selectValue(value) |
101 | 101 |
102 def _xmluiGetSelectedValues(self): | 102 def _xmluiGetSelectedValues(self): |
103 return [option.value for option in self.getSelectedValues()] | 103 return [option.value for option in self.getSelectedValues()] |
104 | |
105 | |
106 class PrimitivusAdvancedListWidget(PrimitivusListWidget, PrimitivusEvents): | |
107 | |
108 def __init__(self, parent, options, flags): | |
109 sat_widgets.List.__init__(self, options=options, style=flags, max_height=20) | |
110 | 104 |
111 | 105 |
112 class PrimitivusPairsContainer(xmlui.PairsContainer, urwid.WidgetWrap): | 106 class PrimitivusPairsContainer(xmlui.PairsContainer, urwid.WidgetWrap): |
113 | 107 |
114 def __init__(self, parent, weight_0='1', weight_1='1'): | 108 def __init__(self, parent, weight_0='1', weight_1='1'): |
146 return list_box | 140 return list_box |
147 | 141 |
148 | 142 |
149 class PrimitivusVerticalContainer(xmlui.VerticalContainer, urwid.ListBox): | 143 class PrimitivusVerticalContainer(xmlui.VerticalContainer, urwid.ListBox): |
150 | 144 |
151 | |
152 def __init__(self, parent): | 145 def __init__(self, parent): |
153 urwid.ListBox.__init__(self, urwid.SimpleListWalker([])) | 146 urwid.ListBox.__init__(self, urwid.SimpleListWalker([])) |
154 | 147 |
155 def _xmluiAppend(self, widget): | 148 def _xmluiAppend(self, widget): |
156 self.body.append(widget) | 149 self.body.append(widget) |
167 widget_factory = WidgetFactory() | 160 widget_factory = WidgetFactory() |
168 | 161 |
169 def __init__(self, host, xml_data, title = None, flags = None): | 162 def __init__(self, host, xml_data, title = None, flags = None): |
170 self._dest = "window" | 163 self._dest = "window" |
171 xmlui.XMLUI.__init__(self, host, xml_data, title, flags) | 164 xmlui.XMLUI.__init__(self, host, xml_data, title, flags) |
165 urwid.WidgetWrap.__init__(self, self.main_cont) | |
172 | 166 |
173 def constructUI(self, xml_data): | 167 def constructUI(self, xml_data): |
174 def postTreat(ret_wid): | 168 def postTreat(): |
175 assert ret_wid.body | 169 assert self.main_cont.body |
176 | 170 |
177 if isinstance(ret_wid.body[0],sat_widgets.TabsContainer): | 171 if isinstance(self.main_cont.body[0],sat_widgets.TabsContainer): |
178 ret_wid = ret_wid.body[0] #xxx: awfull hack cause TabsContainer is a BoxWidget, can't be inside a ListBox | 172 self._main_cont = self.main_cont.body[0] #xxx: awfull hack cause TabsContainer is a BoxWidget, can't be inside a ListBox |
179 | 173 |
180 if self.type == 'form': | 174 if self.type == 'form': |
181 buttons = [] | 175 buttons = [] |
182 buttons.append(urwid.Button(_('Submit'),self.onFormSubmitted)) | 176 buttons.append(urwid.Button(_('Submit'),self.onFormSubmitted)) |
183 if not 'NO_CANCEL' in self.flags: | 177 if not 'NO_CANCEL' in self.flags: |
184 buttons.append(urwid.Button(_('Cancel'),self.onFormCancelled)) | 178 buttons.append(urwid.Button(_('Cancel'),self.onFormCancelled)) |
185 max_len = max([len(button.get_label()) for button in buttons]) | 179 max_len = max([len(button.get_label()) for button in buttons]) |
186 grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center') | 180 grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center') |
187 ret_wid.body.append(grid_wid) | 181 self.main_cont.body.append(grid_wid) |
188 elif self.type == 'param': | 182 elif self.type == 'param': |
189 assert(isinstance(ret_wid,sat_widgets.TabsContainer)) | 183 assert(isinstance(self.main_cont,sat_widgets.TabsContainer)) |
190 buttons = [] | 184 buttons = [] |
191 buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams)) | 185 buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams)) |
192 buttons.append(sat_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow())) | 186 buttons.append(sat_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow())) |
193 max_len = max([button.getSize() for button in buttons]) | 187 max_len = max([button.getSize() for button in buttons]) |
194 grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center') | 188 grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center') |
195 ret_wid.addFooter(grid_wid) | 189 self.main_cont.addFooter(grid_wid) |
196 return ret_wid | 190 |
197 | 191 super(XMLUI, self).constructUI(xml_data, postTreat) |
198 widget = super(XMLUI, self).constructUI(xml_data, postTreat) | 192 urwid.WidgetWrap.__init__(self, self.main_cont) |
199 urwid.WidgetWrap.__init__(self, widget) | |
200 | 193 |
201 def show(self, show_type='popup', valign='middle'): | 194 def show(self, show_type='popup', valign='middle'): |
202 """Show the constructed UI | 195 """Show the constructed UI |
203 @param show_type: how to show the UI: | 196 @param show_type: how to show the UI: |
204 - popup | 197 - popup |