Mercurial > libervia-backend
comparison frontends/src/primitivus/xmlui.py @ 912:b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
/!\ Urwid SàText need to be updated /!\
- updated PrimitivusTabsContainer._xmluiAddTab to manage Urwid SàText changes
- if a box widget is added to PrimitivusVerticalContainer, if will use the full available space if it is alone, else it we have a height of 5 rows
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 21 Mar 2014 15:04:13 +0100 |
parents | 1fe00f0c9a91 |
children | 75f3b3b430ff |
comparison
equal
deleted
inserted
replaced
911:b12706d164d7 | 912:b70fb2ac5997 |
---|---|
178 | 178 |
179 def _xmluiAppend(self, widget): | 179 def _xmluiAppend(self, widget): |
180 self.body.append(widget) | 180 self.body.append(widget) |
181 | 181 |
182 def _xmluiAddTab(self, label): | 182 def _xmluiAddTab(self, label): |
183 list_box = super(PrimitivusTabsContainer, self).addTab(label) | 183 tab = PrimitivusVerticalContainer(None) |
184 if hasattr(PrimitivusVerticalContainer, "_PrimitivusVerticalContainer__super"): # workaround for Urwid's metaclass baviour | 184 self.addTab(label, tab) |
185 del PrimitivusVerticalContainer._PrimitivusVerticalContainer__super | 185 return tab |
186 PrimitivusVerticalContainer._xmluiAdapt(list_box) | |
187 return list_box | |
188 | 186 |
189 | 187 |
190 class PrimitivusVerticalContainer(xmlui.VerticalContainer, urwid.ListBox): | 188 class PrimitivusVerticalContainer(xmlui.VerticalContainer, urwid.ListBox): |
189 BOX_HEIGHT = 5 | |
191 | 190 |
192 def __init__(self, parent): | 191 def __init__(self, parent): |
193 urwid.ListBox.__init__(self, urwid.SimpleListWalker([])) | 192 urwid.ListBox.__init__(self, urwid.SimpleListWalker([])) |
194 | 193 self._last_size = None |
195 def _xmluiAppend(self, widget): | 194 |
195 def _xmluiAppend(self, widget): | |
196 if 'flow' not in widget.sizing(): | |
197 widget = urwid.BoxAdapter(widget, self.BOX_HEIGHT) | |
196 self.body.append(widget) | 198 self.body.append(widget) |
199 | |
200 def render(self, size, focus=False): | |
201 if size != self._last_size: | |
202 (maxcol, maxrow) = size | |
203 if self.body: | |
204 widget = self.body[0] | |
205 if isinstance(widget, urwid.BoxAdapter): | |
206 widget.height = maxrow | |
207 self._last_size = size | |
208 return super(PrimitivusVerticalContainer, self).render(size, focus) | |
197 | 209 |
198 | 210 |
199 class WidgetFactory(object): | 211 class WidgetFactory(object): |
200 | 212 |
201 def __getattr__(self, attr): | 213 def __getattr__(self, attr): |
214 urwid.WidgetWrap.__init__(self, self.main_cont) | 226 urwid.WidgetWrap.__init__(self, self.main_cont) |
215 | 227 |
216 def constructUI(self, xml_data): | 228 def constructUI(self, xml_data): |
217 def postTreat(): | 229 def postTreat(): |
218 assert self.main_cont.body | 230 assert self.main_cont.body |
219 | |
220 if isinstance(self.main_cont.body[0],sat_widgets.TabsContainer): | |
221 self._main_cont = self.main_cont.body[0] #xxx: awfull hack cause TabsContainer is a BoxWidget, can't be inside a ListBox | |
222 | 231 |
223 if self.type == 'form': | 232 if self.type == 'form': |
224 buttons = [] | 233 buttons = [] |
225 buttons.append(urwid.Button(_('Submit'),self.onFormSubmitted)) | 234 buttons.append(urwid.Button(_('Submit'),self.onFormSubmitted)) |
226 if not 'NO_CANCEL' in self.flags: | 235 if not 'NO_CANCEL' in self.flags: |
227 buttons.append(urwid.Button(_('Cancel'),self.onFormCancelled)) | 236 buttons.append(urwid.Button(_('Cancel'),self.onFormCancelled)) |
228 max_len = max([len(button.get_label()) for button in buttons]) | 237 max_len = max([len(button.get_label()) for button in buttons]) |
229 grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center') | 238 grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center') |
230 self.main_cont.body.append(grid_wid) | 239 self.main_cont.body.append(grid_wid) |
231 elif self.type == 'param': | 240 elif self.type == 'param': |
232 assert(isinstance(self.main_cont,sat_widgets.TabsContainer)) | 241 tabs_cont = self.main_cont.body[0].base_widget |
242 assert(isinstance(tabs_cont,sat_widgets.TabsContainer)) | |
233 buttons = [] | 243 buttons = [] |
234 buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams)) | 244 buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams)) |
235 buttons.append(sat_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow())) | 245 buttons.append(sat_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow())) |
236 max_len = max([button.getSize() for button in buttons]) | 246 max_len = max([button.getSize() for button in buttons]) |
237 grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center') | 247 grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center') |
238 self.main_cont.addFooter(grid_wid) | 248 tabs_cont.addFooter(grid_wid) |
239 | 249 |
240 super(XMLUI, self).constructUI(xml_data, postTreat) | 250 super(XMLUI, self).constructUI(xml_data, postTreat) |
241 urwid.WidgetWrap.__init__(self, self.main_cont) | 251 urwid.WidgetWrap.__init__(self, self.main_cont) |
242 | 252 |
243 def show(self, show_type=None, valign='middle'): | 253 def show(self, show_type=None, valign='middle'): |