comparison frontends/src/primitivus/xmlui.py @ 969:5c7707c958d8

tools, frontends (xmlui): add setter methods for widgets + new widget InternalButton to process UI operations
author souliane <souliane@mailoo.org>
date Tue, 01 Apr 2014 21:30:21 +0200
parents 75f3b3b430ff
children b37b1d183ac3
comparison
equal deleted inserted replaced
968:75f3b3b430ff 969:5c7707c958d8
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 import urwid 21 import urwid
22 import copy
22 from urwid_satext import sat_widgets 23 from urwid_satext import sat_widgets
23 from logging import debug, info, warning, error 24 from logging import debug, info, warning, error
24 from xml.dom import minidom 25 from xml.dom import minidom
25 from sat_frontends.tools import xmlui 26 from sat_frontends.tools import xmlui
26 27
76 warning(_("Unknown div_char")) 77 warning(_("Unknown div_char"))
77 div_char = u'─' 78 div_char = u'─'
78 79
79 urwid.Divider.__init__(self, div_char) 80 urwid.Divider.__init__(self, div_char)
80 81
82
81 class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, PrimitivusEvents): 83 class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, PrimitivusEvents):
82 84
83 def __init__(self, parent, value): 85 def __init__(self, parent, value):
84 sat_widgets.AdvancedEdit.__init__(self, edit_text=value) 86 sat_widgets.AdvancedEdit.__init__(self, edit_text=value)
87
88 def _xmluiSetValue(self, value):
89 self.set_edit_text(value)
85 90
86 def _xmluiGetValue(self): 91 def _xmluiGetValue(self):
87 return self.get_edit_text() 92 return self.get_edit_text()
88 93
89 94
90 class PrimitivusPasswordWidget(xmlui.PasswordWidget, sat_widgets.Password, PrimitivusEvents): 95 class PrimitivusPasswordWidget(xmlui.PasswordWidget, sat_widgets.Password, PrimitivusEvents):
91 96
92 def __init__(self, parent, value): 97 def __init__(self, parent, value):
93 sat_widgets.Password.__init__(self, edit_text=value) 98 sat_widgets.Password.__init__(self, edit_text=value)
94 99
100 def _xmluiSetValue(self, value):
101 self.set_edit_text(value)
102
95 def _xmluiGetValue(self): 103 def _xmluiGetValue(self):
96 return self.get_edit_text() 104 return self.get_edit_text()
97 105
98 106
99 class PrimitivusTextBoxWidget(xmlui.TextBoxWidget, sat_widgets.AdvancedEdit, PrimitivusEvents): 107 class PrimitivusTextBoxWidget(xmlui.TextBoxWidget, sat_widgets.AdvancedEdit, PrimitivusEvents):
100 108
101 def __init__(self, parent, value): 109 def __init__(self, parent, value):
102 sat_widgets.AdvancedEdit.__init__(self, edit_text=value, multiline=True) 110 sat_widgets.AdvancedEdit.__init__(self, edit_text=value, multiline=True)
103 111
112 def _xmluiSetValue(self, value):
113 self.set_edit_text(value)
114
104 def _xmluiGetValue(self): 115 def _xmluiGetValue(self):
105 return self.get_edit_text() 116 return self.get_edit_text()
106 117
107 118
108 class PrimitivusBoolWidget(xmlui.BoolWidget, urwid.CheckBox, PrimitivusEvents): 119 class PrimitivusBoolWidget(xmlui.BoolWidget, urwid.CheckBox, PrimitivusEvents):
109 120
110 def __init__(self, parent, state): 121 def __init__(self, parent, state):
111 urwid.CheckBox.__init__(self, '', state=state) 122 urwid.CheckBox.__init__(self, '', state=state)
123
124 def _xmluiSetValue(self, value):
125 self.set_state(value == "true")
112 126
113 def _xmluiGetValue(self): 127 def _xmluiGetValue(self):
114 return "true" if self.get_state() else "false" 128 return "true" if self.get_state() else "false"
115 129
116 130
132 def _xmluiSelectValues(self, values): 146 def _xmluiSelectValues(self, values):
133 return self.selectValues(values) 147 return self.selectValues(values)
134 148
135 def _xmluiGetSelectedValues(self): 149 def _xmluiGetSelectedValues(self):
136 return [option.value for option in self.getSelectedValues()] 150 return [option.value for option in self.getSelectedValues()]
151
152 def _xmluiAddValues(self, values, select=True):
153 current_values = self.getAllValues()
154 new_values = copy.deepcopy(current_values)
155 for value in values:
156 if value not in current_values:
157 new_values.append(value)
158 if select:
159 selected = self._xmluiGetSelectedValues()
160 self.changeValues(new_values)
161 if select:
162 for value in values:
163 if value not in selected:
164 selected.append(value)
165 self._xmluiSelectValues(selected)
137 166
138 167
139 class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer, PrimitivusEvents): 168 class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer, PrimitivusEvents):
140 169
141 def __init__(self, parent, columns, selectable='no'): 170 def __init__(self, parent, columns, selectable='no'):