changeset 8:ec01505ec109

primitivus chat window - management of one 2 one / group chat - timestamp displayed - added shortcuts for showing/hiding panels - color used - fixed vcard bug (contact displayed even if not from current profile if vcard changed/not in cache) - added VerticalSeparator widget - *List widgets can now use an other widget than SelectableText - new UnselectableText widget
author Goffi <goffi@goffi.org>
date Thu, 08 Jul 2010 19:47:54 +0800
parents 94868f58850b
children 6650747dfdcb
files frontends/primitivus/custom_widgets.py
diffstat 1 files changed, 28 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/primitivus/custom_widgets.py	Thu Jul 08 14:19:30 2010 +0800
+++ b/frontends/primitivus/custom_widgets.py	Thu Jul 08 19:47:54 2010 +0800
@@ -137,10 +137,15 @@
             attr+="_focus"
         return urwid.Text((attr,self.text), align=self.align)
 
+class UnselectableText(SelectableText):
+    
+    def setState(self, selected, invisible=False):
+        pass
+
 class GenericList(urwid.WidgetWrap):
     signals = ['click','change']
 
-    def __init__(self, options, style=[], align='left', on_click=None, on_change=None, user_data=None):
+    def __init__(self, options, style=[], align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None):
         """
         Widget managing list of string and their selection
         @param options: list of strings used for options
@@ -156,6 +161,7 @@
         self.no_first_select = 'no_first_select' in style
         self.can_select_none = 'can_select_none' in style
         self.align = align
+        self.option_type = option_type
         self.first_display = True
         
         if on_click:
@@ -222,11 +228,14 @@
             old_selected = self.getSelectedValues()
         widgets = []
         for option in new_values:
-            widget = SelectableText(option, self.align)
+            widget = self.option_type(option, self.align)
             if not self.first_display and option in old_selected:
                 widget.setState(True)
             widgets.append(widget)
-            urwid.connect_signal(widget, 'change', self.__onStateChange)
+            try:
+                urwid.connect_signal(widget, 'change', self.__onStateChange)
+            except NameError:
+                pass #the widget given doesn't support 'change' signal
         self.content[:] = widgets
         if self.first_display and self.single and new_values and not self.no_first_select:
             self.content[0].setState(True)
@@ -249,8 +258,8 @@
     """FlowWidget list, same arguments as GenericList, with an additional one 'max_height'"""
     signals = ['click','change']
 
-    def __init__(self, options, style=[], max_height=5, align='left', on_click=None, on_change=None, user_data=None):
-        self.genericList = GenericList(options, style, align, on_click, on_change, user_data)
+    def __init__(self, options, style=[], max_height=5, align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None):
+        self.genericList = GenericList(options, style, align, option_type, on_click, on_change, user_data)
         self.max_height = max_height 
 
     def selectable(self):
@@ -365,4 +374,18 @@
         urwid.LineBox.__init__(self, original_widget)
         top_columns = self._w.widget_list[0]
         top_columns.widget_list[1] = label_widget
+
+class VerticalSeparator(urwid.WidgetDecoration, urwid.WidgetWrap):
+    def __init__(self, original_widget, left_char = utf8decode("│"), right_char = ''):
+        """Draw a separator on left and/or of original_widget."""
         
+        widgets = [original_widget]
+        if left_char:
+            widgets.insert(0, ('fixed', 1, urwid.SolidFill(left_char)))
+        if right_char:
+            widgets.append(('fixed', 1, urwid.SolidFill(right_char)))
+        columns = urwid.Columns(widgets, box_columns = [0,2], focus_column = 1)
+        urwid.WidgetDecoration.__init__(self, original_widget)
+        urwid.WidgetWrap.__init__(self, columns)
+
+