Mercurial > libervia-backend
comparison frontends/primitivus/xmlui.py @ 170:2ea8dab08160
Primitivus: XMLUI's show method now manage window and popup
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 12 Aug 2010 12:31:45 +0800 |
parents | 6fd053c99421 |
children | 9ee4a1d0d7fb |
comparison
equal
deleted
inserted
replaced
169:06985b6ad23a | 170:2ea8dab08160 |
---|---|
53 def __init__(self, host, xml_data, title = None, options = [], misc={}): | 53 def __init__(self, host, xml_data, title = None, options = [], misc={}): |
54 self.host = host | 54 self.host = host |
55 self.title = title | 55 self.title = title |
56 self.options = options | 56 self.options = options |
57 self.misc = misc | 57 self.misc = misc |
58 self.__dest = "window" | |
58 self.ctrl_list = {} # usefull to access ctrl | 59 self.ctrl_list = {} # usefull to access ctrl |
59 widget = self.constructUI(xml_data) | 60 widget = self.constructUI(xml_data) |
60 urwid.WidgetWrap.__init__(self,widget) | 61 urwid.WidgetWrap.__init__(self,widget) |
61 | 62 |
62 def __parseElems(self, node, parent): | 63 def __parseElems(self, node, parent): |
149 ret_wid = urwid.ListBox(urwid.SimpleListWalker([])) | 150 ret_wid = urwid.ListBox(urwid.SimpleListWalker([])) |
150 | 151 |
151 cat_dom = minidom.parseString(xml_data.encode('utf-8')) | 152 cat_dom = minidom.parseString(xml_data.encode('utf-8')) |
152 top=cat_dom.documentElement | 153 top=cat_dom.documentElement |
153 self.type = top.getAttribute("type") | 154 self.type = top.getAttribute("type") |
154 if not self.title: | 155 self.title = top.getAttribute("title") or self.title |
155 self.title = top.getAttribute("title") #TODO: manage title | |
156 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: | 156 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: |
157 raise InvalidXMLUI | 157 raise InvalidXMLUI |
158 | 158 |
159 if self.type == 'param': | 159 if self.type == 'param': |
160 self.param_changed = set() | 160 self.param_changed = set() |
183 max_len = max([button.getSize() for button in buttons]) | 183 max_len = max([button.getSize() for button in buttons]) |
184 grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center') | 184 grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center') |
185 ret_wid.addFooter(grid_wid) | 185 ret_wid.addFooter(grid_wid) |
186 return ret_wid | 186 return ret_wid |
187 | 187 |
188 def show(self): | 188 def show(self,show_type = 'popup'): |
189 """Show the constructed UI""" | 189 """Show the constructed UI |
190 @param show_type: how to show the UI: | |
191 - popup | |
192 - window""" | |
193 self.__dest = "popup" | |
190 decorated = custom_widgets.LabelLine(self, custom_widgets.SurroundedText(self.title or '')) | 194 decorated = custom_widgets.LabelLine(self, custom_widgets.SurroundedText(self.title or '')) |
191 self.host.showPopUp(decorated) | 195 if show_type == 'popup': |
196 self.host.showPopUp(decorated) | |
197 elif show_type == 'window': | |
198 self.host.addWindow(decorated) | |
199 else: | |
200 error(_('INTERNAL ERROR: Unmanaged show_type (%s)') % show_type) | |
201 assert(False) | |
192 self.host.redraw() | 202 self.host.redraw() |
193 | 203 |
194 | 204 |
195 ##EVENTS## | 205 ##EVENTS## |
196 | 206 |
228 else: | 238 else: |
229 warning (_("The form data is not sent back, the type is not managed properly")) | 239 warning (_("The form data is not sent back, the type is not managed properly")) |
230 self.host.removePopUp() | 240 self.host.removePopUp() |
231 | 241 |
232 def onFormCancelled(self, button): | 242 def onFormCancelled(self, button): |
233 self.host.removePopUp() | 243 if self.__dest == 'window': |
244 self.host.removeWindow() | |
245 else: | |
246 self.host.removePopUp() | |
234 | 247 |
235 def onSaveParams(self, button): | 248 def onSaveParams(self, button): |
236 for ctrl in self.param_changed: | 249 for ctrl in self.param_changed: |
237 self.host.bridge.setParam(ctrl._param_name, ctrl.get_edit_text(), ctrl._param_category, profile_key = self.host.profile) | 250 self.host.bridge.setParam(ctrl._param_name, ctrl.get_edit_text(), ctrl._param_category, profile_key = self.host.profile) |
238 self.host.removeWindow() | 251 self.host.removeWindow() |