Mercurial > libervia-backend
comparison frontends/primitivus/custom_widgets.py @ 121:03d8bcc67182
misc documentation
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 08 Jul 2010 14:19:30 +0800 |
parents | 1ca5f254ce41 |
children | 961e0898271f |
comparison
equal
deleted
inserted
replaced
120:1ca5f254ce41 | 121:03d8bcc67182 |
---|---|
21 | 21 |
22 import urwid | 22 import urwid |
23 from urwid.escape import utf8decode | 23 from urwid.escape import utf8decode |
24 | 24 |
25 class Password(urwid.Edit): | 25 class Password(urwid.Edit): |
26 """Edit box which doesn't show what is entered (show '*' or other char instead)""" | |
26 | 27 |
27 def __init__(self, *args, **kwargs): | 28 def __init__(self, *args, **kwargs): |
29 """Same args than Edit.__init__ with an additional keyword arg 'hidden_char' | |
30 @param hidden_char: char to show instead of what is actually entered: default '*' | |
31 """ | |
28 self.hidden_char=kwargs['hidden_char'] if kwargs.has_key('hidden_char') else '*' | 32 self.hidden_char=kwargs['hidden_char'] if kwargs.has_key('hidden_char') else '*' |
29 self.__real_text='' | 33 self.__real_text='' |
30 super(Password, self).__init__(*args, **kwargs) | 34 super(Password, self).__init__(*args, **kwargs) |
31 | 35 |
32 def set_edit_text(self, text): | 36 def set_edit_text(self, text): |
36 | 40 |
37 def get_edit_text(self): | 41 def get_edit_text(self): |
38 return self.__real_text | 42 return self.__real_text |
39 | 43 |
40 class AdvancedEdit(urwid.Edit): | 44 class AdvancedEdit(urwid.Edit): |
41 """Edit box with some custom improvments""" | 45 """Edit box with some custom improvments |
46 new chars: | |
47 - C-a: like 'home' | |
48 - C-e: like 'end' | |
49 - C-k: remove everything on the right of the cursor | |
50 - C-w: remove the word on the back | |
51 new behaviour: emit a 'click' signal when enter is pressed""" | |
42 signals = urwid.Edit.signals + ['click'] | 52 signals = urwid.Edit.signals + ['click'] |
43 | 53 |
44 def keypress(self, size, key): | 54 def keypress(self, size, key): |
45 #TODO: insert mode is not managed yet | 55 #TODO: insert mode is not managed yet |
46 if key == 'ctrl a': | 56 if key == 'ctrl a': |
59 self._emit('click') | 69 self._emit('click') |
60 return super(AdvancedEdit, self).keypress(size, key) | 70 return super(AdvancedEdit, self).keypress(size, key) |
61 | 71 |
62 | 72 |
63 class SurroundedText(urwid.FlowWidget): | 73 class SurroundedText(urwid.FlowWidget): |
74 """Text centered on a repeated character (like a Divider, but with a text in the center)""" | |
64 | 75 |
65 def __init__(self,text,car=utf8decode('─')): | 76 def __init__(self,text,car=utf8decode('─')): |
66 self.text=text | 77 self.text=text |
67 self.car=car | 78 self.car=car |
68 | 79 |
307 urwid.WidgetWrap.__init__(self, decorated_frame) | 318 urwid.WidgetWrap.__init__(self, decorated_frame) |
308 | 319 |
309 | 320 |
310 | 321 |
311 class InputDialog(GenericDialog): | 322 class InputDialog(GenericDialog): |
323 """Dialog with an edit box""" | |
312 | 324 |
313 def __init__(self, title, instrucions, style=['OK/CANCEL'], default_txt = '', **kwargs): | 325 def __init__(self, title, instrucions, style=['OK/CANCEL'], default_txt = '', **kwargs): |
314 instr_wid = urwid.Text(instrucions+':') | 326 instr_wid = urwid.Text(instrucions+':') |
315 edit_box = urwid.Edit(edit_text=default_txt) | 327 edit_box = urwid.Edit(edit_text=default_txt) |
316 GenericDialog.__init__(self, [instr_wid,edit_box], title, style, ok_value=edit_box, **kwargs) | 328 GenericDialog.__init__(self, [instr_wid,edit_box], title, style, ok_value=edit_box, **kwargs) |
317 | 329 |
318 class ConfirmDialog(GenericDialog): | 330 class ConfirmDialog(GenericDialog): |
331 """Dialog with buttons for confirm or cancel an action""" | |
319 | 332 |
320 def __init__(self, title, style=['YES/NO'], **kwargs): | 333 def __init__(self, title, style=['YES/NO'], **kwargs): |
321 GenericDialog.__init__(self, [], title, style, yes_value=None, **kwargs) | 334 GenericDialog.__init__(self, [], title, style, yes_value=None, **kwargs) |
322 | 335 |
323 class Alert(GenericDialog): | 336 class Alert(GenericDialog): |
337 """Dialog with just a message and a OK button""" | |
324 | 338 |
325 def __init__(self, title, message, style=['OK'], **kwargs): | 339 def __init__(self, title, message, style=['OK'], **kwargs): |
326 GenericDialog.__init__(self, [urwid.Text(message, 'center')], title, style, ok_value=None, **kwargs) | 340 GenericDialog.__init__(self, [urwid.Text(message, 'center')], title, style, ok_value=None, **kwargs) |
327 | 341 |
328 ## CONTAINERS ## | 342 ## CONTAINERS ## |
329 | 343 |
330 class FocusFrame(urwid.Frame): | 344 class FocusFrame(urwid.Frame): |
331 """Frame which manage "tab" key""" | 345 """Frame which manage 'tab' key""" |
332 | 346 |
333 def keypress(self, size, key): | 347 def keypress(self, size, key): |
334 if key == 'tab': | 348 if key == 'tab': |
335 focus_list = ('header','body','footer') | 349 focus_list = ('header','body','footer') |
336 focus_idx = focus_list.index(self.focus_part) | 350 focus_idx = focus_list.index(self.focus_part) |
343 | 357 |
344 return urwid.Frame.keypress(self, size, key) | 358 return urwid.Frame.keypress(self, size, key) |
345 | 359 |
346 ## DECORATORS ## | 360 ## DECORATORS ## |
347 class LabelLine(urwid.LineBox): | 361 class LabelLine(urwid.LineBox): |
362 """Like LineBox, but with a Label centered in the top line""" | |
348 | 363 |
349 def __init__(self, original_widget, label_widget): | 364 def __init__(self, original_widget, label_widget): |
350 urwid.LineBox.__init__(self, original_widget) | 365 urwid.LineBox.__init__(self, original_widget) |
351 top_columns = self._w.widget_list[0] | 366 top_columns = self._w.widget_list[0] |
352 top_columns.widget_list[1] = label_widget | 367 top_columns.widget_list[1] = label_widget |