diff frontends/primitivus/custom_widgets.py @ 120:1ca5f254ce41

primitivus group chat & misc primitivus: new widget: SurroundedText (text with a character repeated around it) primitivus: new decorator LabelLine (like lineBox, but with a label on the top line) wix & primitivus & quick_app: group chat method move to quick_chat wix: when new message, window is not raised anymore, but RequestUserAttention is called instead
author Goffi <goffi@goffi.org>
date Thu, 08 Jul 2010 14:12:18 +0800
parents ded2431cea5a
children 03d8bcc67182
line wrap: on
line diff
--- a/frontends/primitivus/custom_widgets.py	Mon Jul 05 19:13:36 2010 +0800
+++ b/frontends/primitivus/custom_widgets.py	Thu Jul 08 14:12:18 2010 +0800
@@ -20,6 +20,7 @@
 """
 
 import urwid
+from urwid.escape import utf8decode
 
 class Password(urwid.Edit):
 
@@ -59,7 +60,28 @@
         return super(AdvancedEdit, self).keypress(size, key) 
        
 
+class SurroundedText(urwid.FlowWidget):
+
+    def __init__(self,text,car=utf8decode('─')):
+        self.text=text
+        self.car=car
+
+    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):
+        (maxcol,) = size
+        middle = (maxcol-len(self.text))/2
+        render_text = middle * self.car + self.text + (maxcol - len(self.text) - middle) * self.car
+        return urwid.Text(render_text)
+
+
+
 class SelectableText(urwid.FlowWidget):
+    """Text which can be selected with space"""
     signals = ['change']
     
     def __init__(self, text, align='left'):
@@ -255,9 +277,11 @@
 
     def displayWidget(self, size, focus):
         list_size = sum([wid.rows(size, focus) for wid in self.genericList.content])
-        height = min(list_size,self.max_height) 
+        height = min(list_size,self.max_height) or 1 
         return urwid.BoxAdapter(self.genericList, height)
 
+## DIALOGS ##
+
 class GenericDialog(urwid.WidgetWrap):
 
     def __init__(self, widgets_lst, title, style=[], **kwargs):
@@ -286,9 +310,9 @@
 
 class InputDialog(GenericDialog):
 
-    def __init__(self, title, instrucions, style=['OK/CANCEL'], **kwargs):
+    def __init__(self, title, instrucions, style=['OK/CANCEL'], default_txt = '', **kwargs):
         instr_wid = urwid.Text(instrucions+':')
-        edit_box = urwid.Edit()
+        edit_box = urwid.Edit(edit_text=default_txt)
         GenericDialog.__init__(self, [instr_wid,edit_box], title, style, ok_value=edit_box, **kwargs)
 
 class ConfirmDialog(GenericDialog):
@@ -301,6 +325,8 @@
     def __init__(self, title, message, style=['OK'], **kwargs):
         GenericDialog.__init__(self, [urwid.Text(message, 'center')], title, style, ok_value=None, **kwargs)
 
+## CONTAINERS ##
+
 class FocusFrame(urwid.Frame):
     """Frame which manage "tab" key"""
 
@@ -316,3 +342,12 @@
                     self.set_focus(focus_name)
 
         return urwid.Frame.keypress(self, size, key)
+
+## DECORATORS ##
+class LabelLine(urwid.LineBox):
+
+    def __init__(self, original_widget, label_widget):
+        urwid.LineBox.__init__(self, original_widget)
+        top_columns = self._w.widget_list[0]
+        top_columns.widget_list[1] = label_widget
+