comparison urwid_satext/sat_widgets.py @ 127:88722f920b3c

added edit to access edit widget in InputDialog, and text property + minor docstring fixes
author Goffi <goffi@goffi.org>
date Sun, 24 Jul 2016 18:57:35 +0200
parents db9bc68ca0a8
children 144bdf877d21
comparison
equal deleted inserted replaced
126:5ab6a5ebd3b5 127:88722f920b3c
218 218
219 def __init__(self, text, align='left', header='', focus_attr='default_focus', selected_text=None, selected=False, data=None): 219 def __init__(self, text, align='left', header='', focus_attr='default_focus', selected_text=None, selected=False, data=None):
220 """ 220 """
221 @param text: same as urwid.Text's text parameter 221 @param text: same as urwid.Text's text parameter
222 @param align: same as urwid.Text's align parameter 222 @param align: same as urwid.Text's align parameter
223 @select_attr: attrbute to use when selected 223 @param selected_text: text to display when selected
224 @param selected: is the text selected ? 224 @param selected: is the text selected ?
225 """ 225 """
226 self.focus_attr = focus_attr 226 self.focus_attr = focus_attr
227 self._selected = False 227 self._selected = False
228 self._was_focused = False 228 self._was_focused = False
253 self.text = text 253 self.text = text
254 self.setState(self._selected,invisible=True) 254 self.setState(self._selected,invisible=True)
255 255
256 def setSelectedText(self, text=None): 256 def setSelectedText(self, text=None):
257 """Text to display when selected 257 """Text to display when selected
258 @text: text as in urwid.Text or None for default value""" 258
259 @text: text as in urwid.Text or None for default value
260 """
259 if text == None: 261 if text == None:
260 text = ('selected',self.getValue()) 262 text = ('selected',self.getValue())
261 self.selected_txt = text 263 self.selected_txt = text
262 if self._selected: 264 if self._selected:
263 self.setState(self._selected) 265 self.setState(self._selected)
1148 urwid.WidgetWrap.__init__(self, decorated_frame) 1150 urwid.WidgetWrap.__init__(self, decorated_frame)
1149 1151
1150 def setCallback(self, name, callback, data=None): 1152 def setCallback(self, name, callback, data=None):
1151 """Set the callback associated with a button press 1153 """Set the callback associated with a button press
1152 1154
1153 @param name: one of "ok", "cancel", "yest", "no" 1155 @param name: one of "ok", "cancel", "yes", "no"
1154 @aram callback(callable): method to call on requested action 1156 @aram callback(callable): method to call on requested action
1155 @param data: argument to send to the callback (first one will be the button widget) 1157 @param data: argument to send to the callback (first one will be the button widget)
1156 @raise KeyError if name is invalid 1158 @raise KeyError if name is invalid
1157 """ 1159 """
1158 button = self.buttons[name] 1160 button = self.buttons[name]
1164 1166
1165 def __init__(self, title, instrucions, style=None, default_txt = '', **kwargs): 1167 def __init__(self, title, instrucions, style=None, default_txt = '', **kwargs):
1166 if style is None: 1168 if style is None:
1167 style = ['OK/CANCEL'] 1169 style = ['OK/CANCEL']
1168 instr_wid = urwid.Text(instrucions+':') 1170 instr_wid = urwid.Text(instrucions+':')
1169 edit_box = AdvancedEdit(edit_text=default_txt) 1171 self.edit = AdvancedEdit(edit_text=default_txt)
1170 GenericDialog.__init__(self, [instr_wid,edit_box], title, style, ok_value=edit_box, **kwargs) 1172 GenericDialog.__init__(self, [instr_wid, self.edit], title, style, ok_value=self.edit, **kwargs)
1171 self._w.base_widget.focusposition = 'body' 1173 self._w.base_widget.focusposition = 'body'
1174
1175 @property
1176 def text(self):
1177 return self.edit.text
1172 1178
1173 1179
1174 class ConfirmDialog(GenericDialog): 1180 class ConfirmDialog(GenericDialog):
1175 """Dialog with buttons for confirm or cancel an action""" 1181 """Dialog with buttons for confirm or cancel an action"""
1176 1182