Mercurial > libervia-backend
diff frontends/primitivus/custom_widgets.py @ 118:76055a209ed9
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 | 1f0fd6f03e2b |
children | ded2431cea5a |
line wrap: on
line diff
--- a/frontends/primitivus/custom_widgets.py Sat Jul 03 12:01:01 2010 +0800 +++ b/frontends/primitivus/custom_widgets.py Sat Jul 03 13:56:44 2010 +0800 @@ -36,6 +36,26 @@ def get_edit_text(self): return self.__real_text +class AdvancedEdit(urwid.Edit): + """Edit box with some custom improvments""" + + def keypress(self, size, key): + #TODO: insert mode is not managed yet + if key == 'ctrl a': + key = 'home' + elif key == 'ctrl e': + key = 'end' + elif key == 'ctrl k': + self._delete_highlighted() + self.set_edit_text(self.edit_text[:self.edit_pos]) + elif key == 'ctrl w': + before = self.edit_text[:self.edit_pos] + pos = before.rstrip().rfind(" ")+1 + self.set_edit_text(before[:pos] + self.edit_text[self.edit_pos:]) + self.set_edit_pos(pos) + return super(AdvancedEdit, self).keypress(size, key) + + class SelectableText(urwid.FlowWidget): signals = ['change'] @@ -93,6 +113,7 @@ self.content = urwid.SimpleListWalker([]) self.list_box = urwid.ListBox(self.content) + urwid.WidgetWrap.__init__(self, self.list_box) self.changeValues(options) def __onStateChange(self, widget, selected): @@ -141,7 +162,7 @@ if self.single and new_values: self.content[0].setState(True) display_widget = urwid.BoxAdapter(self.list_box, min(len(new_values),5) or 1) - urwid.WidgetWrap.__init__(self, display_widget) + self._set_w(display_widget) def selectValue(self, value): self.unselectAll()