Mercurial > urwid-satext
comparison frontends/primitivus/custom_widgets.py @ 4:c94cdbfdf3e8
primitivus: added edition zone at the bottom
- primitivus: new AdvancedEdit widget, which is like Edit but manage some new keys (C-a, C-e, C-k, C-w)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 03 Jul 2010 13:56:44 +0800 |
parents | 6290022ae74d |
children | 592cd64933dd |
comparison
equal
deleted
inserted
replaced
3:6290022ae74d | 4:c94cdbfdf3e8 |
---|---|
33 hidden_txt = len(text)*'*' | 33 hidden_txt = len(text)*'*' |
34 super(Password, self).set_edit_text(hidden_txt) | 34 super(Password, self).set_edit_text(hidden_txt) |
35 | 35 |
36 def get_edit_text(self): | 36 def get_edit_text(self): |
37 return self.__real_text | 37 return self.__real_text |
38 | |
39 class AdvancedEdit(urwid.Edit): | |
40 """Edit box with some custom improvments""" | |
41 | |
42 def keypress(self, size, key): | |
43 #TODO: insert mode is not managed yet | |
44 if key == 'ctrl a': | |
45 key = 'home' | |
46 elif key == 'ctrl e': | |
47 key = 'end' | |
48 elif key == 'ctrl k': | |
49 self._delete_highlighted() | |
50 self.set_edit_text(self.edit_text[:self.edit_pos]) | |
51 elif key == 'ctrl w': | |
52 before = self.edit_text[:self.edit_pos] | |
53 pos = before.rstrip().rfind(" ")+1 | |
54 self.set_edit_text(before[:pos] + self.edit_text[self.edit_pos:]) | |
55 self.set_edit_pos(pos) | |
56 return super(AdvancedEdit, self).keypress(size, key) | |
57 | |
38 | 58 |
39 class SelectableText(urwid.FlowWidget): | 59 class SelectableText(urwid.FlowWidget): |
40 signals = ['change'] | 60 signals = ['change'] |
41 | 61 |
42 def __init__(self, text, align='left'): | 62 def __init__(self, text, align='left'): |
91 if on_state_change: | 111 if on_state_change: |
92 urwid.connect_signal(self, 'change', on_state_change, user_data) | 112 urwid.connect_signal(self, 'change', on_state_change, user_data) |
93 | 113 |
94 self.content = urwid.SimpleListWalker([]) | 114 self.content = urwid.SimpleListWalker([]) |
95 self.list_box = urwid.ListBox(self.content) | 115 self.list_box = urwid.ListBox(self.content) |
116 urwid.WidgetWrap.__init__(self, self.list_box) | |
96 self.changeValues(options) | 117 self.changeValues(options) |
97 | 118 |
98 def __onStateChange(self, widget, selected): | 119 def __onStateChange(self, widget, selected): |
99 if self.single: | 120 if self.single: |
100 if not selected: | 121 if not selected: |
139 urwid.connect_signal(widget, 'change', self.__onStateChange) | 160 urwid.connect_signal(widget, 'change', self.__onStateChange) |
140 self.content[:] = widgets | 161 self.content[:] = widgets |
141 if self.single and new_values: | 162 if self.single and new_values: |
142 self.content[0].setState(True) | 163 self.content[0].setState(True) |
143 display_widget = urwid.BoxAdapter(self.list_box, min(len(new_values),5) or 1) | 164 display_widget = urwid.BoxAdapter(self.list_box, min(len(new_values),5) or 1) |
144 urwid.WidgetWrap.__init__(self, display_widget) | 165 self._set_w(display_widget) |
145 | 166 |
146 def selectValue(self, value): | 167 def selectValue(self, value): |
147 self.unselectAll() | 168 self.unselectAll() |
148 idx = 0 | 169 idx = 0 |
149 for widget in self.content: | 170 for widget in self.content: |