Mercurial > libervia-web
comparison browser_side/xmlui.py @ 337:ea1be522ba88
browser side: XMLUI fixes:
- wholeText is now managed in nativedom.Node
- fixed Button label
- fixed AdvancedListContainer row index
- fixed JidWidget
- added _xmluiLaunchAction and _xmluiSetParam
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 04 Feb 2014 16:49:20 +0100 |
parents | e8c26e24a6c7 |
children | 2067d6241927 |
comparison
equal
deleted
inserted
replaced
336:629c99bbd031 | 337:ea1be522ba88 |
---|---|
33 from pyjamas.ui.ListBox import ListBox | 33 from pyjamas.ui.ListBox import ListBox |
34 from pyjamas.ui.Button import Button | 34 from pyjamas.ui.Button import Button |
35 from pyjamas.ui.HTML import HTML | 35 from pyjamas.ui.HTML import HTML |
36 from nativedom import NativeDOM | 36 from nativedom import NativeDOM |
37 from sat_frontends.tools import xmlui | 37 from sat_frontends.tools import xmlui |
38 from sat.core.i18n import _ | |
38 | 39 |
39 | 40 |
40 class EmptyWidget(xmlui.EmptyWidget, Label): | 41 class EmptyWidget(xmlui.EmptyWidget, Label): |
41 | 42 |
42 def __init__(self, parent): | 43 def __init__(self, parent): |
54 def __init__(self, parent, value): | 55 def __init__(self, parent, value): |
55 TextWidget.__init__(self, parent, value+": ") | 56 TextWidget.__init__(self, parent, value+": ") |
56 | 57 |
57 | 58 |
58 class JidWidget(xmlui.JidWidget, TextWidget): | 59 class JidWidget(xmlui.JidWidget, TextWidget): |
59 pass | 60 |
61 def __init__(self, parent, value): | |
62 TextWidget.__init__(self, parent, value) | |
60 | 63 |
61 | 64 |
62 class DividerWidget(xmlui.DividerWidget, HTML): | 65 class DividerWidget(xmlui.DividerWidget, HTML): |
63 | 66 |
64 def __init__(self, parent, style='line'): | 67 def __init__(self, parent, style='line'): |
118 | 121 |
119 | 122 |
120 class ButtonWidget(xmlui.ButtonWidget, Button): | 123 class ButtonWidget(xmlui.ButtonWidget, Button): |
121 | 124 |
122 def __init__(self, parent, value, click_callback): | 125 def __init__(self, parent, value, click_callback): |
123 Button.__init__(self) | 126 Button.__init__(self, value) |
124 | 127 |
125 def _xmluiOnClick(self, event): | 128 def _xmluiOnClick(self, event): |
126 self.addClickListener(callback) | 129 self.addClickListener(callback) |
127 | 130 |
128 | 131 |
130 | 133 |
131 def __init__(self, parent, options, flags): | 134 def __init__(self, parent, options, flags): |
132 ListBox.__init__(self) | 135 ListBox.__init__(self) |
133 self.setMultipleSelect('single' not in flags) | 136 self.setMultipleSelect('single' not in flags) |
134 for option in options: | 137 for option in options: |
135 self.addItem(option[0]) | 138 self.addItem(option[1]) |
136 self._xmlui_attr_map = {label: value for value, label in options} | 139 self._xmlui_attr_map = {label: value for value, label in options} |
137 | 140 |
138 def _xmluiSelectValue(self, value): | 141 def _xmluiSelectValue(self, value): |
139 try: | 142 try: |
140 label = [label for label, _value in self._xmlui_attr_map.items() if _value == value][0] | 143 label = [label for label, _value in self._xmlui_attr_map.items() if _value == value][0] |
160 | 163 |
161 | 164 |
162 class AdvancedListContainer(xmlui.AdvancedListContainer, Grid): | 165 class AdvancedListContainer(xmlui.AdvancedListContainer, Grid): |
163 | 166 |
164 def __init__(self, parent, columns, selectable='no'): | 167 def __init__(self, parent, columns, selectable='no'): |
165 Grid.__init_(self, 0, columns) | 168 Grid.__init__(self, 0, columns) |
166 self.columns = columns | 169 self.columns = columns |
167 self.row = 0 | 170 self.row = -1 |
168 self.col = 0 | 171 self.col = 0 |
169 self._xmlui_rows_idx = [] | 172 self._xmlui_rows_idx = [] |
170 self._xmlui_selectable = selectable != 'no' | 173 self._xmlui_selectable = selectable != 'no' |
171 self._xmlui_selected_row = None | 174 self._xmlui_selected_row = None |
172 self.addTableListener(self) | 175 self.addTableListener(self) |
184 def _xmluiAppend(self, widget): | 187 def _xmluiAppend(self, widget): |
185 self.setWidget(self.row, self.col, widget) | 188 self.setWidget(self.row, self.col, widget) |
186 self.col += 1 | 189 self.col += 1 |
187 | 190 |
188 def _xmluiAddRow(self, idx): | 191 def _xmluiAddRow(self, idx): |
189 self._xmlui_rows_idx.insert(self.row, idx) | |
190 self.row += 1 | 192 self.row += 1 |
191 self.col = 0 | 193 self.col = 0 |
192 self.resizeRows(self.row) | 194 self._xmlui_rows_idx.insert(self.row, idx) |
195 self.resizeRows(self.row+1) | |
193 | 196 |
194 def _xmluiGetSelectedWidgets(self): | 197 def _xmluiGetSelectedWidgets(self): |
195 return [self.getWidget(self._xmlui_selected_row, col) for col in range(self.columns)] | 198 return [self.getWidget(self._xmlui_selected_row, col) for col in range(self.columns)] |
196 | 199 |
197 def _xmluiGetSelectedIndex(self): | 200 def _xmluiGetSelectedIndex(self): |
259 def createTabsContainer(self, *args, **kwargs): | 262 def createTabsContainer(self, *args, **kwargs): |
260 instance = TabsContainer(*args, **kwargs) | 263 instance = TabsContainer(*args, **kwargs) |
261 instance._xmlui_main = self._xmlui_main | 264 instance._xmlui_main = self._xmlui_main |
262 return instance | 265 return instance |
263 | 266 |
267 def createAdvancedListContainer(self, *args, **kwargs): | |
268 instance = AdvancedListContainer(*args, **kwargs) | |
269 instance._xmlui_main = self._xmlui_main | |
270 return instance | |
271 | |
264 def createEmptyWidget(self, *args, **kwargs): | 272 def createEmptyWidget(self, *args, **kwargs): |
265 instance = EmptyWidget(*args, **kwargs) | 273 instance = EmptyWidget(*args, **kwargs) |
266 instance._xmlui_main = self._xmlui_main | 274 instance._xmlui_main = self._xmlui_main |
267 return instance | 275 return instance |
268 | 276 |
329 | 337 |
330 def __init__(self, host, xml_data, title = None, flags = None): | 338 def __init__(self, host, xml_data, title = None, flags = None): |
331 self.widget_factory._xmlui_main = self | 339 self.widget_factory._xmlui_main = self |
332 self.dom = NativeDOM() | 340 self.dom = NativeDOM() |
333 dom_parse = lambda xml_data: self.dom.parseString(xml_data) | 341 dom_parse = lambda xml_data: self.dom.parseString(xml_data) |
334 self._dest = "window" | |
335 VerticalPanel.__init__(self) | 342 VerticalPanel.__init__(self) |
336 self.setSize('100%', '100%') | 343 self.setSize('100%', '100%') |
337 xmlui.XMLUI.__init__(self, host, xml_data, title, flags, dom_parse) | 344 xmlui.XMLUI.__init__(self, host, xml_data, title, flags, dom_parse) |
338 | 345 |
339 def setCloseCb(self, close_cb): | 346 def setCloseCb(self, close_cb): |
342 def _xmluiClose(self): | 349 def _xmluiClose(self): |
343 if self.close_cb: | 350 if self.close_cb: |
344 self.close_cb() | 351 self.close_cb() |
345 else: | 352 else: |
346 print "WARNING: no close method defined" | 353 print "WARNING: no close method defined" |
354 | |
355 def _xmluiLaunchAction(self, action_id, data): | |
356 self.host.launchAction(action_id, data) | |
357 | |
358 def _xmluiSetParam(self, name, value, category): | |
359 self.host.bridge.call('setParam', None, name, value, category) | |
347 | 360 |
348 def constructUI(self, xml_data): | 361 def constructUI(self, xml_data): |
349 super(XMLUI, self).constructUI(xml_data) | 362 super(XMLUI, self).constructUI(xml_data) |
350 self.add(self.main_cont) | 363 self.add(self.main_cont) |
351 self.setCellHeight(self.main_cont, '100%') | 364 self.setCellHeight(self.main_cont, '100%') |
359 assert(isinstance(self.children[0][0],TabPanel)) | 372 assert(isinstance(self.children[0][0],TabPanel)) |
360 hpanel = HorizontalPanel() | 373 hpanel = HorizontalPanel() |
361 hpanel.add(Button('Cancel', lambda ignore: self._xmluiClose())) | 374 hpanel.add(Button('Cancel', lambda ignore: self._xmluiClose())) |
362 hpanel.add(Button('Save', self.onSaveParams)) | 375 hpanel.add(Button('Save', self.onSaveParams)) |
363 self.add(hpanel) | 376 self.add(hpanel) |
364 | |
365 ##EVENTS## | |
366 | |
367 def onSaveParams(self, ignore=None): | |
368 def postTreat(name, value, category): | |
369 self.host.bridge.call('setParam', None, name, value, category) | |
370 xmlui.XMLUI.onSaveParams(self, ignore, postTreat) |