comparison sat_frontends/primitivus/xmlui.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 1209a5d83082
children 5c2ed8a5ae22
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
22 import copy 22 import copy
23 from sat.core import exceptions 23 from sat.core import exceptions
24 from urwid_satext import sat_widgets 24 from urwid_satext import sat_widgets
25 from urwid_satext import files_management 25 from urwid_satext import files_management
26 from sat.core.log import getLogger 26 from sat.core.log import getLogger
27
27 log = getLogger(__name__) 28 log = getLogger(__name__)
28 from sat_frontends.primitivus.constants import Const as C 29 from sat_frontends.primitivus.constants import Const as C
29 from sat_frontends.primitivus.widget import PrimitivusWidget 30 from sat_frontends.primitivus.widget import PrimitivusWidget
30 from sat_frontends.tools import xmlui 31 from sat_frontends.tools import xmlui
31 32
37 """" Call xmlui callback and ignore any extra argument """ 38 """" Call xmlui callback and ignore any extra argument """
38 args[-1](ctrl) 39 args[-1](ctrl)
39 40
40 def _xmluiOnChange(self, callback): 41 def _xmluiOnChange(self, callback):
41 """ Call callback with widget as only argument """ 42 """ Call callback with widget as only argument """
42 urwid.connect_signal(self, 'change', self._event_callback, callback) 43 urwid.connect_signal(self, "change", self._event_callback, callback)
43 44
44 45
45 class PrimitivusEmptyWidget(xmlui.EmptyWidget, urwid.Text): 46 class PrimitivusEmptyWidget(xmlui.EmptyWidget, urwid.Text):
46
47 def __init__(self, _xmlui_parent): 47 def __init__(self, _xmlui_parent):
48 urwid.Text.__init__(self, '') 48 urwid.Text.__init__(self, "")
49 49
50 50
51 class PrimitivusTextWidget(xmlui.TextWidget, urwid.Text): 51 class PrimitivusTextWidget(xmlui.TextWidget, urwid.Text):
52
53 def __init__(self, _xmlui_parent, value, read_only=False): 52 def __init__(self, _xmlui_parent, value, read_only=False):
54 urwid.Text.__init__(self, value) 53 urwid.Text.__init__(self, value)
55 54
56 55
57 class PrimitivusLabelWidget(xmlui.LabelWidget, PrimitivusTextWidget): 56 class PrimitivusLabelWidget(xmlui.LabelWidget, PrimitivusTextWidget):
58
59 def __init__(self, _xmlui_parent, value): 57 def __init__(self, _xmlui_parent, value):
60 super(PrimitivusLabelWidget, self).__init__(_xmlui_parent, value+": ") 58 super(PrimitivusLabelWidget, self).__init__(_xmlui_parent, value + ": ")
61 59
62 60
63 class PrimitivusJidWidget(xmlui.JidWidget, PrimitivusTextWidget): 61 class PrimitivusJidWidget(xmlui.JidWidget, PrimitivusTextWidget):
64 pass 62 pass
65 63
66 64
67 class PrimitivusDividerWidget(xmlui.DividerWidget, urwid.Divider): 65 class PrimitivusDividerWidget(xmlui.DividerWidget, urwid.Divider):
68 66 def __init__(self, _xmlui_parent, style="line"):
69 def __init__(self, _xmlui_parent, style='line'): 67 if style == "line":
70 if style == 'line': 68 div_char = u"─"
71 div_char = u'─' 69 elif style == "dot":
72 elif style == 'dot': 70 div_char = u"·"
73 div_char = u'·' 71 elif style == "dash":
74 elif style == 'dash': 72 div_char = u"-"
75 div_char = u'-' 73 elif style == "plain":
76 elif style == 'plain': 74 div_char = u"█"
77 div_char = u'█' 75 elif style == "blank":
78 elif style == 'blank': 76 div_char = " "
79 div_char = ' '
80 else: 77 else:
81 log.warning(_("Unknown div_char")) 78 log.warning(_("Unknown div_char"))
82 div_char = u'─' 79 div_char = u"─"
83 80
84 urwid.Divider.__init__(self, div_char) 81 urwid.Divider.__init__(self, div_char)
85 82
86 83
87 class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, PrimitivusEvents): 84 class PrimitivusStringWidget(
88 85 xmlui.StringWidget, sat_widgets.AdvancedEdit, PrimitivusEvents
86 ):
89 def __init__(self, _xmlui_parent, value, read_only=False): 87 def __init__(self, _xmlui_parent, value, read_only=False):
90 sat_widgets.AdvancedEdit.__init__(self, edit_text=value) 88 sat_widgets.AdvancedEdit.__init__(self, edit_text=value)
91 self.read_only = read_only 89 self.read_only = read_only
92 90
93 def selectable(self): 91 def selectable(self):
104 102
105 class PrimitivusJidInputWidget(xmlui.JidInputWidget, PrimitivusStringWidget): 103 class PrimitivusJidInputWidget(xmlui.JidInputWidget, PrimitivusStringWidget):
106 pass 104 pass
107 105
108 106
109 class PrimitivusPasswordWidget(xmlui.PasswordWidget, sat_widgets.Password, PrimitivusEvents): 107 class PrimitivusPasswordWidget(
110 108 xmlui.PasswordWidget, sat_widgets.Password, PrimitivusEvents
109 ):
111 def __init__(self, _xmlui_parent, value, read_only=False): 110 def __init__(self, _xmlui_parent, value, read_only=False):
112 sat_widgets.Password.__init__(self, edit_text=value) 111 sat_widgets.Password.__init__(self, edit_text=value)
113 self.read_only = read_only 112 self.read_only = read_only
114 113
115 def selectable(self): 114 def selectable(self):
122 121
123 def _xmluiGetValue(self): 122 def _xmluiGetValue(self):
124 return self.get_edit_text() 123 return self.get_edit_text()
125 124
126 125
127 class PrimitivusTextBoxWidget(xmlui.TextBoxWidget, sat_widgets.AdvancedEdit, PrimitivusEvents): 126 class PrimitivusTextBoxWidget(
128 127 xmlui.TextBoxWidget, sat_widgets.AdvancedEdit, PrimitivusEvents
128 ):
129 def __init__(self, _xmlui_parent, value, read_only=False): 129 def __init__(self, _xmlui_parent, value, read_only=False):
130 sat_widgets.AdvancedEdit.__init__(self, edit_text=value, multiline=True) 130 sat_widgets.AdvancedEdit.__init__(self, edit_text=value, multiline=True)
131 self.read_only = read_only 131 self.read_only = read_only
132 132
133 def selectable(self): 133 def selectable(self):
141 def _xmluiGetValue(self): 141 def _xmluiGetValue(self):
142 return self.get_edit_text() 142 return self.get_edit_text()
143 143
144 144
145 class PrimitivusBoolWidget(xmlui.BoolWidget, urwid.CheckBox, PrimitivusEvents): 145 class PrimitivusBoolWidget(xmlui.BoolWidget, urwid.CheckBox, PrimitivusEvents):
146
147 def __init__(self, _xmlui_parent, state, read_only=False): 146 def __init__(self, _xmlui_parent, state, read_only=False):
148 urwid.CheckBox.__init__(self, '', state=state) 147 urwid.CheckBox.__init__(self, "", state=state)
149 self.read_only = read_only 148 self.read_only = read_only
150 149
151 def selectable(self): 150 def selectable(self):
152 if self.read_only: 151 if self.read_only:
153 return False 152 return False
159 def _xmluiGetValue(self): 158 def _xmluiGetValue(self):
160 return C.BOOL_TRUE if self.get_state() else C.BOOL_FALSE 159 return C.BOOL_TRUE if self.get_state() else C.BOOL_FALSE
161 160
162 161
163 class PrimitivusIntWidget(xmlui.IntWidget, sat_widgets.AdvancedEdit, PrimitivusEvents): 162 class PrimitivusIntWidget(xmlui.IntWidget, sat_widgets.AdvancedEdit, PrimitivusEvents):
164
165 def __init__(self, _xmlui_parent, value, read_only=False): 163 def __init__(self, _xmlui_parent, value, read_only=False):
166 sat_widgets.AdvancedEdit.__init__(self, edit_text=value) 164 sat_widgets.AdvancedEdit.__init__(self, edit_text=value)
167 self.read_only = read_only 165 self.read_only = read_only
168 166
169 def selectable(self): 167 def selectable(self):
176 174
177 def _xmluiGetValue(self): 175 def _xmluiGetValue(self):
178 return self.get_edit_text() 176 return self.get_edit_text()
179 177
180 178
181 class PrimitivusButtonWidget(xmlui.ButtonWidget, sat_widgets.CustomButton, PrimitivusEvents): 179 class PrimitivusButtonWidget(
182 180 xmlui.ButtonWidget, sat_widgets.CustomButton, PrimitivusEvents
181 ):
183 def __init__(self, _xmlui_parent, value, click_callback): 182 def __init__(self, _xmlui_parent, value, click_callback):
184 sat_widgets.CustomButton.__init__(self, value, on_press=click_callback) 183 sat_widgets.CustomButton.__init__(self, value, on_press=click_callback)
185 184
186 def _xmluiOnClick(self, callback): 185 def _xmluiOnClick(self, callback):
187 urwid.connect_signal(self, 'click', callback) 186 urwid.connect_signal(self, "click", callback)
188 187
189 188
190 class PrimitivusListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents): 189 class PrimitivusListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents):
191
192 def __init__(self, _xmlui_parent, options, selected, flags): 190 def __init__(self, _xmlui_parent, options, selected, flags):
193 sat_widgets.List.__init__(self, options=options, style=flags) 191 sat_widgets.List.__init__(self, options=options, style=flags)
194 self._xmluiSelectValues(selected) 192 self._xmluiSelectValues(selected)
195 193
196 def _xmluiSelectValue(self, value): 194 def _xmluiSelectValue(self, value):
215 for value in values: 213 for value in values:
216 if value not in selected: 214 if value not in selected:
217 selected.append(value) 215 selected.append(value)
218 self._xmluiSelectValues(selected) 216 self._xmluiSelectValues(selected)
219 217
218
220 class PrimitivusJidsListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents): 219 class PrimitivusJidsListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents):
221
222 def __init__(self, _xmlui_parent, jids, styles): 220 def __init__(self, _xmlui_parent, jids, styles):
223 sat_widgets.List.__init__(self, options=jids+[''], # the empty field is here to add new jids if needed 221 sat_widgets.List.__init__(
224 option_type=lambda txt, align: sat_widgets.AdvancedEdit(edit_text=txt, align=align), 222 self,
225 on_change=self._onChange) 223 options=jids + [""], # the empty field is here to add new jids if needed
226 self.delete=0 224 option_type=lambda txt, align: sat_widgets.AdvancedEdit(
225 edit_text=txt, align=align
226 ),
227 on_change=self._onChange,
228 )
229 self.delete = 0
227 230
228 def _onChange(self, list_widget, jid_widget=None, text=None): 231 def _onChange(self, list_widget, jid_widget=None, text=None):
229 if jid_widget is not None: 232 if jid_widget is not None:
230 if jid_widget != list_widget.contents[-1] and not text: 233 if jid_widget != list_widget.contents[-1] and not text:
231 # if a field is empty, we delete the line (except for the last line) 234 # if a field is empty, we delete the line (except for the last line)
237 def _xmluiGetSelectedValues(self): 240 def _xmluiGetSelectedValues(self):
238 # XXX: there is not selection in this list, so we return all non empty values 241 # XXX: there is not selection in this list, so we return all non empty values
239 return [jid_ for jid_ in self.getAllValues() if jid_] 242 return [jid_ for jid_ in self.getAllValues() if jid_]
240 243
241 244
242 class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer, PrimitivusEvents): 245 class PrimitivusAdvancedListContainer(
243 246 xmlui.AdvancedListContainer, sat_widgets.TableContainer, PrimitivusEvents
244 def __init__(self, _xmlui_parent, columns, selectable='no'): 247 ):
245 options = {'ADAPT':()} 248 def __init__(self, _xmlui_parent, columns, selectable="no"):
246 if selectable != 'no': 249 options = {"ADAPT": ()}
247 options['HIGHLIGHT'] = () 250 if selectable != "no":
248 sat_widgets.TableContainer.__init__(self, columns=columns, options=options, row_selectable = selectable!='no') 251 options["HIGHLIGHT"] = ()
252 sat_widgets.TableContainer.__init__(
253 self, columns=columns, options=options, row_selectable=selectable != "no"
254 )
249 255
250 def _xmluiAppend(self, widget): 256 def _xmluiAppend(self, widget):
251 self.addWidget(widget) 257 self.addWidget(widget)
252 258
253 def _xmluiAddRow(self, idx): 259 def _xmluiAddRow(self, idx):
259 def _xmluiGetSelectedIndex(self): 265 def _xmluiGetSelectedIndex(self):
260 return self.getSelectedIndex() 266 return self.getSelectedIndex()
261 267
262 def _xmluiOnSelect(self, callback): 268 def _xmluiOnSelect(self, callback):
263 """ Call callback with widget as only argument """ 269 """ Call callback with widget as only argument """
264 urwid.connect_signal(self, 'click', self._event_callback, callback) 270 urwid.connect_signal(self, "click", self._event_callback, callback)
265 271
266 272
267 class PrimitivusPairsContainer(xmlui.PairsContainer, sat_widgets.TableContainer): 273 class PrimitivusPairsContainer(xmlui.PairsContainer, sat_widgets.TableContainer):
268
269 def __init__(self, _xmlui_parent): 274 def __init__(self, _xmlui_parent):
270 options = {'ADAPT':(0,), 'HIGHLIGHT':(0,)} 275 options = {"ADAPT": (0,), "HIGHLIGHT": (0,)}
271 if self._xmlui_main.type == 'param': 276 if self._xmlui_main.type == "param":
272 options['FOCUS_ATTR'] = 'param_selected' 277 options["FOCUS_ATTR"] = "param_selected"
273 sat_widgets.TableContainer.__init__(self, columns=2, options=options) 278 sat_widgets.TableContainer.__init__(self, columns=2, options=options)
274 279
275 def _xmluiAppend(self, widget): 280 def _xmluiAppend(self, widget):
276 if isinstance(widget, PrimitivusEmptyWidget): 281 if isinstance(widget, PrimitivusEmptyWidget):
277 # we don't want highlight on empty widgets 282 # we don't want highlight on empty widgets
278 widget = urwid.AttrMap(widget, 'default') 283 widget = urwid.AttrMap(widget, "default")
279 self.addWidget(widget) 284 self.addWidget(widget)
280 285
281 286
282 class PrimitivusLabelContainer(PrimitivusPairsContainer, xmlui.LabelContainer): 287 class PrimitivusLabelContainer(PrimitivusPairsContainer, xmlui.LabelContainer):
283 pass 288 pass
284 289
285 290
286 class PrimitivusTabsContainer(xmlui.TabsContainer, sat_widgets.TabsContainer): 291 class PrimitivusTabsContainer(xmlui.TabsContainer, sat_widgets.TabsContainer):
287
288 def __init__(self, _xmlui_parent): 292 def __init__(self, _xmlui_parent):
289 sat_widgets.TabsContainer.__init__(self) 293 sat_widgets.TabsContainer.__init__(self)
290 294
291 def _xmluiAppend(self, widget): 295 def _xmluiAppend(self, widget):
292 self.body.append(widget) 296 self.body.append(widget)
303 def __init__(self, _xmlui_parent): 307 def __init__(self, _xmlui_parent):
304 urwid.ListBox.__init__(self, urwid.SimpleListWalker([])) 308 urwid.ListBox.__init__(self, urwid.SimpleListWalker([]))
305 self._last_size = None 309 self._last_size = None
306 310
307 def _xmluiAppend(self, widget): 311 def _xmluiAppend(self, widget):
308 if 'flow' not in widget.sizing(): 312 if "flow" not in widget.sizing():
309 widget = urwid.BoxAdapter(widget, self.BOX_HEIGHT) 313 widget = urwid.BoxAdapter(widget, self.BOX_HEIGHT)
310 self.body.append(widget) 314 self.body.append(widget)
311 315
312 def render(self, size, focus=False): 316 def render(self, size, focus=False):
313 if size != self._last_size: 317 if size != self._last_size:
322 326
323 ### Dialogs ### 327 ### Dialogs ###
324 328
325 329
326 class PrimitivusDialog(object): 330 class PrimitivusDialog(object):
327
328 def __init__(self, _xmlui_parent): 331 def __init__(self, _xmlui_parent):
329 self.host = _xmlui_parent.host 332 self.host = _xmlui_parent.host
330 333
331 def _xmluiShow(self): 334 def _xmluiShow(self):
332 self.host.showPopUp(self) 335 self.host.showPopUp(self)
334 def _xmluiClose(self): 337 def _xmluiClose(self):
335 self.host.removePopUp(self) 338 self.host.removePopUp(self)
336 339
337 340
338 class PrimitivusMessageDialog(PrimitivusDialog, xmlui.MessageDialog, sat_widgets.Alert): 341 class PrimitivusMessageDialog(PrimitivusDialog, xmlui.MessageDialog, sat_widgets.Alert):
339
340 def __init__(self, _xmlui_parent, title, message, level): 342 def __init__(self, _xmlui_parent, title, message, level):
341 PrimitivusDialog.__init__(self, _xmlui_parent) 343 PrimitivusDialog.__init__(self, _xmlui_parent)
342 xmlui.MessageDialog.__init__(self, _xmlui_parent) 344 xmlui.MessageDialog.__init__(self, _xmlui_parent)
343 sat_widgets.Alert.__init__(self, title, message, ok_cb=lambda dummy: self._xmluiClose()) 345 sat_widgets.Alert.__init__(
346 self, title, message, ok_cb=lambda dummy: self._xmluiClose()
347 )
344 348
345 349
346 class PrimitivusNoteDialog(xmlui.NoteDialog, PrimitivusMessageDialog): 350 class PrimitivusNoteDialog(xmlui.NoteDialog, PrimitivusMessageDialog):
347 # TODO: separate NoteDialog 351 # TODO: separate NoteDialog
348 pass 352 pass
349 353
350 354
351 class PrimitivusConfirmDialog(PrimitivusDialog, xmlui.ConfirmDialog, sat_widgets.ConfirmDialog): 355 class PrimitivusConfirmDialog(
352 356 PrimitivusDialog, xmlui.ConfirmDialog, sat_widgets.ConfirmDialog
357 ):
353 def __init__(self, _xmlui_parent, title, message, level, buttons_set): 358 def __init__(self, _xmlui_parent, title, message, level, buttons_set):
354 PrimitivusDialog.__init__(self, _xmlui_parent) 359 PrimitivusDialog.__init__(self, _xmlui_parent)
355 xmlui.ConfirmDialog.__init__(self, _xmlui_parent) 360 xmlui.ConfirmDialog.__init__(self, _xmlui_parent)
356 sat_widgets.ConfirmDialog.__init__(self, title, message, no_cb=lambda dummy: self._xmluiCancelled(), yes_cb=lambda dummy: self._xmluiValidated()) 361 sat_widgets.ConfirmDialog.__init__(
357 362 self,
358 363 title,
359 class PrimitivusFileDialog(PrimitivusDialog, xmlui.FileDialog, files_management.FileDialog): 364 message,
360 365 no_cb=lambda dummy: self._xmluiCancelled(),
366 yes_cb=lambda dummy: self._xmluiValidated(),
367 )
368
369
370 class PrimitivusFileDialog(
371 PrimitivusDialog, xmlui.FileDialog, files_management.FileDialog
372 ):
361 def __init__(self, _xmlui_parent, title, message, level, filetype): 373 def __init__(self, _xmlui_parent, title, message, level, filetype):
362 # TODO: message is not managed yet 374 # TODO: message is not managed yet
363 PrimitivusDialog.__init__(self, _xmlui_parent) 375 PrimitivusDialog.__init__(self, _xmlui_parent)
364 xmlui.FileDialog.__init__(self, _xmlui_parent) 376 xmlui.FileDialog.__init__(self, _xmlui_parent)
365 style = [] 377 style = []
366 if filetype == C.XMLUI_DATA_FILETYPE_DIR: 378 if filetype == C.XMLUI_DATA_FILETYPE_DIR:
367 style.append('dir') 379 style.append("dir")
368 files_management.FileDialog.__init__(self, 380 files_management.FileDialog.__init__(
369 ok_cb=lambda path: self._xmluiValidated({'path': path}), 381 self,
382 ok_cb=lambda path: self._xmluiValidated({"path": path}),
370 cancel_cb=lambda dummy: self._xmluiCancelled(), 383 cancel_cb=lambda dummy: self._xmluiCancelled(),
371 message=message, 384 message=message,
372 title=title, 385 title=title,
373 style=style) 386 style=style,
387 )
374 388
375 389
376 class GenericFactory(object): 390 class GenericFactory(object):
377
378 def __getattr__(self, attr): 391 def __getattr__(self, attr):
379 if attr.startswith("create"): 392 if attr.startswith("create"):
380 cls = globals()["Primitivus" + attr[6:]] # XXX: we prefix with "Primitivus" to work around an Urwid bug, WidgetMeta in Urwid don't manage multiple inheritance with same names 393 cls = globals()[
394 "Primitivus" + attr[6:]
395 ] # XXX: we prefix with "Primitivus" to work around an Urwid bug, WidgetMeta in Urwid don't manage multiple inheritance with same names
381 return cls 396 return cls
382 397
383 398
384 class WidgetFactory(GenericFactory): 399 class WidgetFactory(GenericFactory):
385
386 def __getattr__(self, attr): 400 def __getattr__(self, attr):
387 if attr.startswith("create"): 401 if attr.startswith("create"):
388 cls = GenericFactory.__getattr__(self, attr) 402 cls = GenericFactory.__getattr__(self, attr)
389 cls._xmlui_main = self._xmlui_main 403 cls._xmlui_main = self._xmlui_main
390 return cls 404 return cls
391 405
392 406
393 class XMLUIPanel(xmlui.XMLUIPanel, PrimitivusWidget): 407 class XMLUIPanel(xmlui.XMLUIPanel, PrimitivusWidget):
394 widget_factory = WidgetFactory() 408 widget_factory = WidgetFactory()
395 409
396 def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, ignore=None, whitelist=None, profile=C.PROF_KEY_NONE): 410 def __init__(
411 self,
412 host,
413 parsed_xml,
414 title=None,
415 flags=None,
416 callback=None,
417 ignore=None,
418 whitelist=None,
419 profile=C.PROF_KEY_NONE,
420 ):
397 self.widget_factory._xmlui_main = self 421 self.widget_factory._xmlui_main = self
398 self._dest = None 422 self._dest = None
399 xmlui.XMLUIPanel.__init__(self, 423 xmlui.XMLUIPanel.__init__(
400 host, 424 self,
401 parsed_xml, 425 host,
402 title = title, 426 parsed_xml,
403 flags = flags, 427 title=title,
404 callback = callback, 428 flags=flags,
405 ignore = ignore, 429 callback=callback,
406 profile = profile) 430 ignore=ignore,
431 profile=profile,
432 )
407 PrimitivusWidget.__init__(self, self.main_cont, self.xmlui_title) 433 PrimitivusWidget.__init__(self, self.main_cont, self.xmlui_title)
408 434
409 def constructUI(self, parsed_dom): 435 def constructUI(self, parsed_dom):
410 def postTreat(): 436 def postTreat():
411 assert self.main_cont.body 437 assert self.main_cont.body
412 438
413 if self.type in ('form', 'popup'): 439 if self.type in ("form", "popup"):
414 buttons = [] 440 buttons = []
415 if self.type == 'form': 441 if self.type == "form":
416 buttons.append(urwid.Button(_('Submit'), self.onFormSubmitted)) 442 buttons.append(urwid.Button(_("Submit"), self.onFormSubmitted))
417 if not 'NO_CANCEL' in self.flags: 443 if not "NO_CANCEL" in self.flags:
418 buttons.append(urwid.Button(_('Cancel'), self.onFormCancelled)) 444 buttons.append(urwid.Button(_("Cancel"), self.onFormCancelled))
419 else: 445 else:
420 buttons.append(urwid.Button(_('OK'), on_press=lambda dummy: self._xmluiClose())) 446 buttons.append(
447 urwid.Button(_("OK"), on_press=lambda dummy: self._xmluiClose())
448 )
421 max_len = max([len(button.get_label()) for button in buttons]) 449 max_len = max([len(button.get_label()) for button in buttons])
422 grid_wid = urwid.GridFlow(buttons, max_len + 4, 1, 0, 'center') 450 grid_wid = urwid.GridFlow(buttons, max_len + 4, 1, 0, "center")
423 self.main_cont.body.append(grid_wid) 451 self.main_cont.body.append(grid_wid)
424 elif self.type == 'param': 452 elif self.type == "param":
425 tabs_cont = self.main_cont.body[0].base_widget 453 tabs_cont = self.main_cont.body[0].base_widget
426 assert isinstance(tabs_cont,sat_widgets.TabsContainer) 454 assert isinstance(tabs_cont, sat_widgets.TabsContainer)
427 buttons = [] 455 buttons = []
428 buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams)) 456 buttons.append(sat_widgets.CustomButton(_("Save"), self.onSaveParams))
429 buttons.append(sat_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow())) 457 buttons.append(
458 sat_widgets.CustomButton(
459 _("Cancel"), lambda x: self.host.removeWindow()
460 )
461 )
430 max_len = max([button.getSize() for button in buttons]) 462 max_len = max([button.getSize() for button in buttons])
431 grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center') 463 grid_wid = urwid.GridFlow(buttons, max_len, 1, 0, "center")
432 tabs_cont.addFooter(grid_wid) 464 tabs_cont.addFooter(grid_wid)
433 465
434 xmlui.XMLUIPanel.constructUI(self, parsed_dom, postTreat) 466 xmlui.XMLUIPanel.constructUI(self, parsed_dom, postTreat)
435 urwid.WidgetWrap.__init__(self, self.main_cont) 467 urwid.WidgetWrap.__init__(self, self.main_cont)
436 468
437 def show(self, show_type=None, valign='middle'): 469 def show(self, show_type=None, valign="middle"):
438 """Show the constructed UI 470 """Show the constructed UI
439 @param show_type: how to show the UI: 471 @param show_type: how to show the UI:
440 - None (follow XMLUI's recommendation) 472 - None (follow XMLUI's recommendation)
441 - 'popup' 473 - 'popup'
442 - 'window' 474 - 'window'
443 @param valign: vertical alignment when show_type is 'popup'. 475 @param valign: vertical alignment when show_type is 'popup'.
444 Ignored when show_type is 'window'. 476 Ignored when show_type is 'window'.
445 477
446 """ 478 """
447 if show_type is None: 479 if show_type is None:
448 if self.type in ('window', 'param'): 480 if self.type in ("window", "param"):
449 show_type = 'window' 481 show_type = "window"
450 elif self.type in ('popup', 'form'): 482 elif self.type in ("popup", "form"):
451 show_type = 'popup' 483 show_type = "popup"
452 484
453 if show_type not in ('popup', 'window'): 485 if show_type not in ("popup", "window"):
454 raise ValueError('Invalid show_type [%s]' % show_type) 486 raise ValueError("Invalid show_type [%s]" % show_type)
455 487
456 self._dest = show_type 488 self._dest = show_type
457 if show_type == 'popup': 489 if show_type == "popup":
458 self.host.showPopUp(self, valign=valign) 490 self.host.showPopUp(self, valign=valign)
459 elif show_type == 'window': 491 elif show_type == "window":
460 self.host.newWidget(self) 492 self.host.newWidget(self)
461 else: 493 else:
462 assert False 494 assert False
463 self.host.redraw() 495 self.host.redraw()
464 496
465 def _xmluiClose(self): 497 def _xmluiClose(self):
466 if self._dest == 'window': 498 if self._dest == "window":
467 self.host.removeWindow() 499 self.host.removeWindow()
468 elif self._dest == 'popup': 500 elif self._dest == "popup":
469 self.host.removePopUp(self) 501 self.host.removePopUp(self)
470 else: 502 else:
471 raise exceptions.InternalError("self._dest unknown, are you sure you have called XMLUI.show ?") 503 raise exceptions.InternalError(
504 "self._dest unknown, are you sure you have called XMLUI.show ?"
505 )
472 506
473 507
474 class XMLUIDialog(xmlui.XMLUIDialog): 508 class XMLUIDialog(xmlui.XMLUIDialog):
475 dialog_factory = GenericFactory() 509 dialog_factory = GenericFactory()
476 510