diff frontends/primitivus/custom_widgets.py @ 128:2240f34f6452

Primitivus: misc fixes + menubar first draft - Menu bar: first draft of class - Password widget fixed - change some str to unicode, notably for JID
author Goffi <goffi@goffi.org>
date Tue, 13 Jul 2010 02:24:59 +0800
parents 8d611eb9ae48
children 6cad483a6d84
line wrap: on
line diff
--- a/frontends/primitivus/custom_widgets.py	Mon Jul 12 18:55:27 2010 +0800
+++ b/frontends/primitivus/custom_widgets.py	Tue Jul 13 02:24:59 2010 +0800
@@ -23,6 +23,7 @@
 from urwid.escape import utf8decode
 
 class Password(urwid.Edit):
+    toto=0
     """Edit box which doesn't show what is entered (show '*' or other char instead)"""
 
     def __init__(self, *args, **kwargs):
@@ -41,6 +42,18 @@
     def get_edit_text(self):
         return self.__real_text
 
+    def insert_text(self, text):
+        self._edit_text = self.__real_text
+        super(Password,self).insert_text(text)
+
+    def render(self, size, focus=False):
+        Password.toto+=1
+        if Password.toto==30:
+            import os,pdb
+            os.system('reset')
+            pdb.set_trace()
+        return super(Password, self).render(size, focus)
+
 class AdvancedEdit(urwid.Edit):
     """Edit box with some custom improvments
     new chars:
@@ -327,6 +340,49 @@
         height = min(list_size,self.max_height) or 1 
         return urwid.BoxAdapter(self.genericList, height)
 
+## MISC ##
+
+class Menu(urwid.FlowWidget):
+
+    def __init__(self):
+        super(Menu, self).__init__()
+        self.menu_keys = ['test']
+        self.menu = {'test':[('top',None)]}
+        self.shortcuts = {} #keyboard shortcuts
+
+    def checkShortcuts(self, key):
+        for shortcut in self.shortcuts.keys():
+            if key == shortcut:
+                category, item, callback = self.shortcuts[shortcuts]
+                callback((category, item))
+        return key
+
+    def addMenu(self, category, item, callback, shortcut=None):
+        """Add a menu item, create the category if new
+        @param category: category of the menu (e.g. File/Edit)
+        @param item: menu item (e.g. new/close/about)
+        @callback: method to call when item is selected"""
+        if not category in self.menu.keys():
+            self.menu_keys.append(category)
+            self.menu[category] = []
+        self.menu[category].append[(item, callback)]
+        if shortcut:
+            assert(shortcut not in self.shortcuts.keys())
+            self.shortcuts[shortcut] = (category, item, callback)
+
+    def rows(self,size,focus=False):
+        return self.display_widget(size, focus).rows(size, focus)
+
+    def render(self, size, focus=False):
+        return self.display_widget(size, focus).render(size, focus)
+
+    def display_widget(self, size, focus):
+        render_txt = []
+        for menu in self.menu_keys:
+            render_txt.append('[ %s ] ' % menu) 
+        return urwid.AttrMap(urwid.Text(render_txt), 'menubar')
+
+
 ## DIALOGS ##
 
 class GenericDialog(urwid.WidgetWrap):