Mercurial > libervia-backend
comparison frontends/src/wix/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 |
---|---|
129 for label in labels: | 129 for label in labels: |
130 ret.append(self._xmlui_attr_map[label]) | 130 ret.append(self._xmlui_attr_map[label]) |
131 return ret | 131 return ret |
132 | 132 |
133 | 133 |
134 class AdvancedListWidget(ListWidget): | |
135 #TODO | |
136 | |
137 def __init__(self, parent, options, flags): | |
138 super(ListWidget, self).__init__(parent, options, flags) | |
139 | |
140 | |
141 class WixContainer(object): | 134 class WixContainer(object): |
142 _xmlui_proportion = 1 | 135 _xmlui_proportion = 1 |
143 | 136 |
144 def _xmluiAppend(self, widget): | 137 def _xmluiAppend(self, widget): |
145 self.sizer.Add(widget, self._xmlui_proportion, flag=wx.EXPAND) | 138 self.sizer.Add(widget, self._xmlui_proportion, flag=wx.EXPAND) |
183 cls = globals()[attr[6:]] | 176 cls = globals()[attr[6:]] |
184 cls._xmlui_main = self._xmlui_main | 177 cls._xmlui_main = self._xmlui_main |
185 return cls | 178 return cls |
186 | 179 |
187 | 180 |
188 class XMLUI(xmlui.XMLUI, wx.Frame, WixContainer): | 181 class XMLUI(xmlui.XMLUI, wx.Frame): |
189 """Create an user interface from a SàT XML""" | 182 """Create an user interface from a SàT XML""" |
190 widget_factory = WidgetFactory() | 183 widget_factory = WidgetFactory() |
191 | 184 |
192 def __init__(self, host, xml_data, title=None, flags = None,): | 185 def __init__(self, host, xml_data, title=None, flags = None,): |
193 self.widget_factory._xmlui_main = self | 186 self.widget_factory._xmlui_main = self |
197 style = wx.DEFAULT_FRAME_STYLE & ~wx.CLOSE_BOX if 'NO_CANCEL' in self.flags else wx.DEFAULT_FRAME_STYLE | 190 style = wx.DEFAULT_FRAME_STYLE & ~wx.CLOSE_BOX if 'NO_CANCEL' in self.flags else wx.DEFAULT_FRAME_STYLE |
198 wx.Frame.__init__(self, None, style=style) | 191 wx.Frame.__init__(self, None, style=style) |
199 self.sizer = wx.BoxSizer(wx.VERTICAL) | 192 self.sizer = wx.BoxSizer(wx.VERTICAL) |
200 self.SetSizer(self.sizer) | 193 self.SetSizer(self.sizer) |
201 | 194 |
202 def postTreat(ret_wid): | 195 def postTreat(): |
203 if self.title: | 196 if self.title: |
204 self.SetTitle(self.title) | 197 self.SetTitle(self.title) |
205 | 198 |
206 if self.type == 'form': | 199 if self.type == 'form': |
207 dialogButtons = wx.StdDialogButtonSizer() | 200 dialogButtons = wx.StdDialogButtonSizer() |
208 submitButton = wx.Button(ret_wid,wx.ID_OK, label=_("Submit")) | 201 submitButton = wx.Button(self.main_cont,wx.ID_OK, label=_("Submit")) |
209 dialogButtons.AddButton(submitButton) | 202 dialogButtons.AddButton(submitButton) |
210 ret_wid.Bind(wx.EVT_BUTTON, self.onFormSubmitted, submitButton) | 203 self.main_cont.Bind(wx.EVT_BUTTON, self.onFormSubmitted, submitButton) |
211 if not 'NO_CANCEL' in self.flags: | 204 if not 'NO_CANCEL' in self.flags: |
212 cancelButton = wx.Button(ret_wid,wx.ID_CANCEL) | 205 cancelButton = wx.Button(self.main_cont,wx.ID_CANCEL) |
213 dialogButtons.AddButton(cancelButton) | 206 dialogButtons.AddButton(cancelButton) |
214 ret_wid.Bind(wx.EVT_BUTTON, self.onFormCancelled, cancelButton) | 207 self.main_cont.Bind(wx.EVT_BUTTON, self.onFormCancelled, cancelButton) |
215 dialogButtons.Realize() | 208 dialogButtons.Realize() |
216 ret_wid.sizer.Add(dialogButtons, flag=wx.ALIGN_CENTER_HORIZONTAL) | 209 self.main_cont.sizer.Add(dialogButtons, flag=wx.ALIGN_CENTER_HORIZONTAL) |
217 | 210 |
218 self._xmluiAppend(ret_wid) | 211 self.sizer.Add(self.main_cont, 1, flag=wx.EXPAND) |
219 self.sizer.Fit(self) | 212 self.sizer.Fit(self) |
220 self.Show() | 213 self.Show() |
221 return ret_wid | |
222 | 214 |
223 super(XMLUI, self).constructUI(xml_data, postTreat) | 215 super(XMLUI, self).constructUI(xml_data, postTreat) |
224 if not 'NO_CANCEL' in self.flags: | 216 if not 'NO_CANCEL' in self.flags: |
225 self.Bind(wx.EVT_CLOSE, self.onClose, self) | 217 self.Bind(wx.EVT_CLOSE, self.onClose, self) |
226 self.MakeModal() | 218 self.MakeModal() |
249 def onClose(self, event): | 241 def onClose(self, event): |
250 """Close event: we have to send the form.""" | 242 """Close event: we have to send the form.""" |
251 debug(_("close")) | 243 debug(_("close")) |
252 if self.type == 'param': | 244 if self.type == 'param': |
253 self.onSaveParams() | 245 self.onSaveParams() |
246 else: | |
247 self._xmluiClose() | |
254 event.Skip() | 248 event.Skip() |
255 | 249 |