frontends (xmlui): add setter methods + fixes:
- add _xmluiSetValue for all widgets + _xmluiAddValues for ListWidget
- fix popup dialog OK button + _xmluiOnClick for ButtonWidget
This commit is contained in:
parent
ec579aff81
commit
35d66de820
2 changed files with 64 additions and 10 deletions
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
from sat.core.i18n import _
|
||||
import urwid
|
||||
import copy
|
||||
from urwid_satext import sat_widgets
|
||||
from logging import debug, info, warning, error
|
||||
from xml.dom import minidom
|
||||
|
|
@ -78,11 +79,15 @@ class PrimitivusDividerWidget(xmlui.DividerWidget, urwid.Divider):
|
|||
|
||||
urwid.Divider.__init__(self, div_char)
|
||||
|
||||
|
||||
class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, PrimitivusEvents):
|
||||
|
||||
def __init__(self, parent, value):
|
||||
sat_widgets.AdvancedEdit.__init__(self, edit_text=value)
|
||||
|
||||
def _xmluiSetValue(self, value):
|
||||
self.set_edit_text(value)
|
||||
|
||||
def _xmluiGetValue(self):
|
||||
return self.get_edit_text()
|
||||
|
||||
|
|
@ -92,6 +97,9 @@ class PrimitivusPasswordWidget(xmlui.PasswordWidget, sat_widgets.Password, Primi
|
|||
def __init__(self, parent, value):
|
||||
sat_widgets.Password.__init__(self, edit_text=value)
|
||||
|
||||
def _xmluiSetValue(self, value):
|
||||
self.set_edit_text(value)
|
||||
|
||||
def _xmluiGetValue(self):
|
||||
return self.get_edit_text()
|
||||
|
||||
|
|
@ -101,6 +109,9 @@ class PrimitivusTextBoxWidget(xmlui.TextBoxWidget, sat_widgets.AdvancedEdit, Pri
|
|||
def __init__(self, parent, value):
|
||||
sat_widgets.AdvancedEdit.__init__(self, edit_text=value, multiline=True)
|
||||
|
||||
def _xmluiSetValue(self, value):
|
||||
self.set_edit_text(value)
|
||||
|
||||
def _xmluiGetValue(self):
|
||||
return self.get_edit_text()
|
||||
|
||||
|
|
@ -110,6 +121,9 @@ class PrimitivusBoolWidget(xmlui.BoolWidget, urwid.CheckBox, PrimitivusEvents):
|
|||
def __init__(self, parent, state):
|
||||
urwid.CheckBox.__init__(self, '', state=state)
|
||||
|
||||
def _xmluiSetValue(self, value):
|
||||
self.set_state(value == "true")
|
||||
|
||||
def _xmluiGetValue(self):
|
||||
return "true" if self.get_state() else "false"
|
||||
|
||||
|
|
@ -119,6 +133,9 @@ class PrimitivusButtonWidget(xmlui.ButtonWidget, sat_widgets.CustomButton, Primi
|
|||
def __init__(self, parent, value, click_callback):
|
||||
sat_widgets.CustomButton.__init__(self, value, on_press=click_callback)
|
||||
|
||||
def _xmluiOnClick(self, callback):
|
||||
urwid.connect_signal(self, 'click', callback)
|
||||
|
||||
|
||||
class PrimitivusListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents):
|
||||
|
||||
|
|
@ -135,6 +152,21 @@ class PrimitivusListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents)
|
|||
def _xmluiGetSelectedValues(self):
|
||||
return [option.value for option in self.getSelectedValues()]
|
||||
|
||||
def _xmluiAddValues(self, values, select=True):
|
||||
current_values = self.getAllValues()
|
||||
new_values = copy.deepcopy(current_values)
|
||||
for value in values:
|
||||
if value not in current_values:
|
||||
new_values.append(value)
|
||||
if select:
|
||||
selected = self._xmluiGetSelectedValues()
|
||||
self.changeValues(new_values)
|
||||
if select:
|
||||
for value in values:
|
||||
if value not in selected:
|
||||
selected.append(value)
|
||||
self._xmluiSelectValues(selected)
|
||||
|
||||
|
||||
class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer, PrimitivusEvents):
|
||||
|
||||
|
|
@ -160,6 +192,7 @@ class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.T
|
|||
""" Call callback with widget as only argument """
|
||||
urwid.connect_signal(self, 'click', self._event_callback, callback)
|
||||
|
||||
|
||||
class PrimitivusPairsContainer(xmlui.PairsContainer, sat_widgets.TableContainer):
|
||||
|
||||
def __init__(self, parent):
|
||||
|
|
@ -233,13 +266,16 @@ class XMLUI(xmlui.XMLUI, urwid.WidgetWrap):
|
|||
def postTreat():
|
||||
assert self.main_cont.body
|
||||
|
||||
if self.type == 'form':
|
||||
if self.type in ('form', 'popup'):
|
||||
buttons = []
|
||||
buttons.append(urwid.Button(_('Submit'),self.onFormSubmitted))
|
||||
if not 'NO_CANCEL' in self.flags:
|
||||
buttons.append(urwid.Button(_('Cancel'),self.onFormCancelled))
|
||||
if self.type == 'form':
|
||||
buttons.append(urwid.Button(_('Submit'), self.onFormSubmitted))
|
||||
if not 'NO_CANCEL' in self.flags:
|
||||
buttons.append(urwid.Button(_('Cancel'), self.onFormCancelled))
|
||||
else:
|
||||
buttons.append(urwid.Button(_('OK'), lambda dummy: self._xmluiClose()))
|
||||
max_len = max([len(button.get_label()) for button in buttons])
|
||||
grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center')
|
||||
grid_wid = urwid.GridFlow(buttons, max_len + 4, 1, 0, 'center')
|
||||
self.main_cont.body.append(grid_wid)
|
||||
elif self.type == 'param':
|
||||
tabs_cont = self.main_cont.body[0].base_widget
|
||||
|
|
|
|||
|
|
@ -42,6 +42,10 @@ class WixWidget(object):
|
|||
|
||||
|
||||
class ValueWidget(WixWidget):
|
||||
|
||||
def _xmluiSetValue(self, value):
|
||||
self.SetValue(value)
|
||||
|
||||
def _xmluiGetValue(self):
|
||||
return self.GetValue()
|
||||
|
||||
|
|
@ -106,6 +110,9 @@ class BoolWidget(EventWidget, ValueWidget, xmlui.BoolWidget, wx.CheckBox):
|
|||
self.SetValue(state)
|
||||
self._xmlui_proportion = 1
|
||||
|
||||
def _xmluiSetValue(self, value):
|
||||
self.SetValue(value == 'true')
|
||||
|
||||
def _xmluiGetValue(self):
|
||||
return "true" if self.GetValue() else "false"
|
||||
|
||||
|
|
@ -117,10 +124,10 @@ class ButtonWidget(EventWidget, WixWidget, xmlui.ButtonWidget, wx.Button):
|
|||
wx.Button.__init__(self, parent, -1, value)
|
||||
self._xmlui_click_callback = click_callback
|
||||
parent.Bind(wx.EVT_BUTTON, lambda evt: click_callback(evt.GetEventObject()), self)
|
||||
self.parent = parent
|
||||
|
||||
def _xmluiOnClick(self, event):
|
||||
self._xmlui_click_callback(event.GetEventObject())
|
||||
event.Skip()
|
||||
def _xmluiOnClick(self, callback):
|
||||
self.parent.Bind(wx.EVT_BUTTON, lambda evt: callback(evt.GetEventObject()), self)
|
||||
|
||||
|
||||
class ListWidget(EventWidget, WixWidget, xmlui.ListWidget, wx.ListBox):
|
||||
|
|
@ -143,8 +150,9 @@ class ListWidget(EventWidget, WixWidget, xmlui.ListWidget, wx.ListBox):
|
|||
self.SetSelection(idx, self.GetString(idx) == label)
|
||||
|
||||
def _xmluiSelectValues(self, values):
|
||||
for value in values:
|
||||
self._xmluiSelectValue(value)
|
||||
labels = [label for label, _value in self._xmlui_attr_map.items() if _value in values]
|
||||
for idx in xrange(self.GetCount()):
|
||||
self.SetSelection(idx, self.GetString(idx) in labels)
|
||||
|
||||
def _xmluiGetSelectedValues(self):
|
||||
ret = []
|
||||
|
|
@ -153,6 +161,16 @@ class ListWidget(EventWidget, WixWidget, xmlui.ListWidget, wx.ListBox):
|
|||
ret.append(self._xmlui_attr_map[label])
|
||||
return ret
|
||||
|
||||
def _xmluiAddValues(self, values, select=True):
|
||||
selected = self._xmluiGetSelectedValues()
|
||||
for value in values:
|
||||
if value not in self._xmlui_attr_map.values():
|
||||
wx.ListBox.Append(self, value)
|
||||
self._xmlui_attr_map[value] = value
|
||||
if value not in selected:
|
||||
selected.append(value)
|
||||
self._xmluiSelectValues(selected)
|
||||
|
||||
|
||||
class WixContainer(object):
|
||||
_xmlui_proportion = 1
|
||||
|
|
|
|||
Loading…
Reference in a new issue