changeset 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
files frontends/primitivus/custom_widgets.py frontends/primitivus/primitivus
diffstat 2 files changed, 27 insertions(+), 3 deletions(-) [+]
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()
--- a/frontends/primitivus/primitivus	Sat Jul 03 12:01:01 2010 +0800
+++ b/frontends/primitivus/primitivus	Sat Jul 03 13:56:44 2010 +0800
@@ -27,6 +27,7 @@
 import urwid
 from profile_manager import ProfileManager
 from contact_list import ContactList
+from custom_widgets import AdvancedEdit
 import pdb
 """from window import Window
 from editbox import EditBox
@@ -78,10 +79,12 @@
 
     def __buildMainWidget(self):
         self.contactList = ContactList(self, self.CM)
-        return self.contactList
+        self.center_part = urwid.Columns([self.contactList])
+        self.main_widget = urwid.Frame(self.center_part, footer=AdvancedEdit('> '), focus_part='footer')
+        return self.main_widget
 
     def plug_profile(self, profile_key='@DEFAULT@'):
-        self.main_widget = self.loop.widget = self.__buildMainWidget() 
+        self.loop.widget = self.__buildMainWidget() 
         QuickApp.plug_profile(self, profile_key)
     
     def removePopUp(self):