Mercurial > libervia-backend
comparison frontends/src/primitivus/xmlui.py @ 587:952322b1d490
Remove trailing whitespaces.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 18 Jan 2013 17:55:34 +0100 |
parents | ca13633d3b6b |
children | c123dddaea6b |
comparison
equal
deleted
inserted
replaced
586:6a718ede8be1 | 587:952322b1d490 |
---|---|
42 self._w.set_focus(1) | 42 self._w.set_focus(1) |
43 else: | 43 else: |
44 pile.widget_list.append(widget) | 44 pile.widget_list.append(widget) |
45 pile.item_types.append(('weight',getattr(self,'weight_'+str(self.idx)))) | 45 pile.item_types.append(('weight',getattr(self,'weight_'+str(self.idx)))) |
46 self.idx = (self.idx + 1) % 2 | 46 self.idx = (self.idx + 1) % 2 |
47 | 47 |
48 class InvalidXMLUI(Exception): | 48 class InvalidXMLUI(Exception): |
49 pass | 49 pass |
50 | 50 |
51 class XMLUI(urwid.WidgetWrap): | 51 class XMLUI(urwid.WidgetWrap): |
52 | 52 |
53 def __init__(self, host, xml_data, title = None, options = None, misc = None): | 53 def __init__(self, host, xml_data, title = None, options = None, misc = None): |
54 self.host = host | 54 self.host = host |
55 self.title = title | 55 self.title = title |
56 self.options = options or [] | 56 self.options = options or [] |
57 self.misc = misc or {} | 57 self.misc = misc or {} |
70 id = elem.getAttribute("id") | 70 id = elem.getAttribute("id") |
71 name = elem.getAttribute("name") | 71 name = elem.getAttribute("name") |
72 type = elem.getAttribute("type") | 72 type = elem.getAttribute("type") |
73 value = elem.getAttribute("value") if elem.hasAttribute('value') else u'' | 73 value = elem.getAttribute("value") if elem.hasAttribute('value') else u'' |
74 if type=="empty": | 74 if type=="empty": |
75 ctrl = urwid.Text('') | 75 ctrl = urwid.Text('') |
76 elif type=="text": | 76 elif type=="text": |
77 try: | 77 try: |
78 value = elem.childNodes[0].wholeText | 78 value = elem.childNodes[0].wholeText |
79 except IndexError: | 79 except IndexError: |
80 warning (_("text node has no child !")) | 80 warning (_("text node has no child !")) |
133 current.append(pairs) | 133 current.append(pairs) |
134 else: | 134 else: |
135 warning(_("Unknown layout, using default one")) | 135 warning(_("Unknown layout, using default one")) |
136 self.__parseElems(node, current) | 136 self.__parseElems(node, current) |
137 elif node.nodeName == "category": | 137 elif node.nodeName == "category": |
138 name = node.getAttribute('name') | 138 name = node.getAttribute('name') |
139 label = node.getAttribute('label') | 139 label = node.getAttribute('label') |
140 if not name or not isinstance(data,sat_widgets.TabsContainer): | 140 if not name or not isinstance(data,sat_widgets.TabsContainer): |
141 raise InvalidXMLUI | 141 raise InvalidXMLUI |
142 if self.type == 'param': | 142 if self.type == 'param': |
143 self._current_category = name #XXX: awful hack because params need category and we don't keep parent | 143 self._current_category = name #XXX: awful hack because params need category and we don't keep parent |
144 tab_cont = data | 144 tab_cont = data |
145 listbox = tab_cont.addTab(label or name) | 145 listbox = tab_cont.addTab(label or name) |
146 self.__parseChilds(listbox.body, node, ['layout']) | 146 self.__parseChilds(listbox.body, node, ['layout']) |
148 message=_("Unknown tag") | 148 message=_("Unknown tag") |
149 error(message) | 149 error(message) |
150 raise NotImplementedError | 150 raise NotImplementedError |
151 | 151 |
152 def constructUI(self, xml_data): | 152 def constructUI(self, xml_data): |
153 | 153 |
154 ret_wid = urwid.ListBox(urwid.SimpleListWalker([])) | 154 ret_wid = urwid.ListBox(urwid.SimpleListWalker([])) |
155 | 155 |
156 cat_dom = minidom.parseString(xml_data.encode('utf-8')) | 156 cat_dom = minidom.parseString(xml_data.encode('utf-8')) |
157 top=cat_dom.documentElement | 157 top=cat_dom.documentElement |
158 self.type = top.getAttribute("type") | 158 self.type = top.getAttribute("type") |
159 self.title = top.getAttribute("title") or self.title | 159 self.title = top.getAttribute("title") or self.title |
160 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: | 160 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: |
164 self.param_changed = set() | 164 self.param_changed = set() |
165 | 165 |
166 self.__parseChilds(ret_wid.body, cat_dom.documentElement) | 166 self.__parseChilds(ret_wid.body, cat_dom.documentElement) |
167 | 167 |
168 assert ret_wid.body | 168 assert ret_wid.body |
169 | 169 |
170 if isinstance(ret_wid.body[0],sat_widgets.TabsContainer): | 170 if isinstance(ret_wid.body[0],sat_widgets.TabsContainer): |
171 ret_wid = ret_wid.body[0] #xxx: awfull hack cause TabsContainer is a BoxWidget, can't be inside a ListBox | 171 ret_wid = ret_wid.body[0] #xxx: awfull hack cause TabsContainer is a BoxWidget, can't be inside a ListBox |
172 | 172 |
173 | 173 |
174 if self.type == 'form': | 174 if self.type == 'form': |
175 buttons = [] | 175 buttons = [] |
176 buttons.append(urwid.Button(_('Submit'),self.onFormSubmitted)) | 176 buttons.append(urwid.Button(_('Submit'),self.onFormSubmitted)) |
177 if not 'NO_CANCEL' in self.options: | 177 if not 'NO_CANCEL' in self.options: |
178 buttons.append(urwid.Button(_('Cancel'),self.onFormCancelled)) | 178 buttons.append(urwid.Button(_('Cancel'),self.onFormCancelled)) |
193 """Show the constructed UI | 193 """Show the constructed UI |
194 @param show_type: how to show the UI: | 194 @param show_type: how to show the UI: |
195 - popup | 195 - popup |
196 - window""" | 196 - window""" |
197 self.__dest = "popup" | 197 self.__dest = "popup" |
198 decorated = sat_widgets.LabelLine(self, sat_widgets.SurroundedText(self.title or '')) | 198 decorated = sat_widgets.LabelLine(self, sat_widgets.SurroundedText(self.title or '')) |
199 if show_type == 'popup': | 199 if show_type == 'popup': |
200 self.host.showPopUp(decorated) | 200 self.host.showPopUp(decorated) |
201 elif show_type == 'window': | 201 elif show_type == 'window': |
202 self.host.addWindow(decorated) | 202 self.host.addWindow(decorated) |
203 else: | 203 else: |
242 elif self.misc.has_key('callback'): | 242 elif self.misc.has_key('callback'): |
243 self.misc['callback'](data) | 243 self.misc['callback'](data) |
244 else: | 244 else: |
245 warning (_("The form data is not sent back, the type is not managed properly")) | 245 warning (_("The form data is not sent back, the type is not managed properly")) |
246 self.host.removePopUp() | 246 self.host.removePopUp() |
247 | 247 |
248 def onFormCancelled(self, button): | 248 def onFormCancelled(self, button): |
249 if self.__dest == 'window': | 249 if self.__dest == 'window': |
250 self.host.removeWindow() | 250 self.host.removeWindow() |
251 else: | 251 else: |
252 self.host.removePopUp() | 252 self.host.removePopUp() |