comparison frontends/primitivus/custom_widgets.py @ 124:961e0898271f

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 03d8bcc67182
children 8d611eb9ae48
comparison
equal deleted inserted replaced
123:34766e0cf970 124:961e0898271f
135 attr = 'selected' if self.__selected else 'default' 135 attr = 'selected' if self.__selected else 'default'
136 if focus: 136 if focus:
137 attr+="_focus" 137 attr+="_focus"
138 return urwid.Text((attr,self.text), align=self.align) 138 return urwid.Text((attr,self.text), align=self.align)
139 139
140 class UnselectableText(SelectableText):
141
142 def setState(self, selected, invisible=False):
143 pass
144
140 class GenericList(urwid.WidgetWrap): 145 class GenericList(urwid.WidgetWrap):
141 signals = ['click','change'] 146 signals = ['click','change']
142 147
143 def __init__(self, options, style=[], align='left', on_click=None, on_change=None, user_data=None): 148 def __init__(self, options, style=[], align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None):
144 """ 149 """
145 Widget managing list of string and their selection 150 Widget managing list of string and their selection
146 @param options: list of strings used for options 151 @param options: list of strings used for options
147 @param style: list of string: 152 @param style: list of string:
148 - 'single' if only one must be selected 153 - 'single' if only one must be selected
154 """ 159 """
155 self.single = 'single' in style 160 self.single = 'single' in style
156 self.no_first_select = 'no_first_select' in style 161 self.no_first_select = 'no_first_select' in style
157 self.can_select_none = 'can_select_none' in style 162 self.can_select_none = 'can_select_none' in style
158 self.align = align 163 self.align = align
164 self.option_type = option_type
159 self.first_display = True 165 self.first_display = True
160 166
161 if on_click: 167 if on_click:
162 urwid.connect_signal(self, 'click', on_click, user_data) 168 urwid.connect_signal(self, 'click', on_click, user_data)
163 169
220 """Change all value in one shot""" 226 """Change all value in one shot"""
221 if not self.first_display: 227 if not self.first_display:
222 old_selected = self.getSelectedValues() 228 old_selected = self.getSelectedValues()
223 widgets = [] 229 widgets = []
224 for option in new_values: 230 for option in new_values:
225 widget = SelectableText(option, self.align) 231 widget = self.option_type(option, self.align)
226 if not self.first_display and option in old_selected: 232 if not self.first_display and option in old_selected:
227 widget.setState(True) 233 widget.setState(True)
228 widgets.append(widget) 234 widgets.append(widget)
229 urwid.connect_signal(widget, 'change', self.__onStateChange) 235 try:
236 urwid.connect_signal(widget, 'change', self.__onStateChange)
237 except NameError:
238 pass #the widget given doesn't support 'change' signal
230 self.content[:] = widgets 239 self.content[:] = widgets
231 if self.first_display and self.single and new_values and not self.no_first_select: 240 if self.first_display and self.single and new_values and not self.no_first_select:
232 self.content[0].setState(True) 241 self.content[0].setState(True)
233 display_widget = self.getDisplayWidget() 242 display_widget = self.getDisplayWidget()
234 self._set_w(display_widget) 243 self._set_w(display_widget)
247 256
248 class List(urwid.FlowWidget): 257 class List(urwid.FlowWidget):
249 """FlowWidget list, same arguments as GenericList, with an additional one 'max_height'""" 258 """FlowWidget list, same arguments as GenericList, with an additional one 'max_height'"""
250 signals = ['click','change'] 259 signals = ['click','change']
251 260
252 def __init__(self, options, style=[], max_height=5, align='left', on_click=None, on_change=None, user_data=None): 261 def __init__(self, options, style=[], max_height=5, align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None):
253 self.genericList = GenericList(options, style, align, on_click, on_change, user_data) 262 self.genericList = GenericList(options, style, align, option_type, on_click, on_change, user_data)
254 self.max_height = max_height 263 self.max_height = max_height
255 264
256 def selectable(self): 265 def selectable(self):
257 return True 266 return True
258 267
363 372
364 def __init__(self, original_widget, label_widget): 373 def __init__(self, original_widget, label_widget):
365 urwid.LineBox.__init__(self, original_widget) 374 urwid.LineBox.__init__(self, original_widget)
366 top_columns = self._w.widget_list[0] 375 top_columns = self._w.widget_list[0]
367 top_columns.widget_list[1] = label_widget 376 top_columns.widget_list[1] = label_widget
368 377
378 class VerticalSeparator(urwid.WidgetDecoration, urwid.WidgetWrap):
379 def __init__(self, original_widget, left_char = utf8decode("│"), right_char = ''):
380 """Draw a separator on left and/or of original_widget."""
381
382 widgets = [original_widget]
383 if left_char:
384 widgets.insert(0, ('fixed', 1, urwid.SolidFill(left_char)))
385 if right_char:
386 widgets.append(('fixed', 1, urwid.SolidFill(right_char)))
387 columns = urwid.Columns(widgets, box_columns = [0,2], focus_column = 1)
388 urwid.WidgetDecoration.__init__(self, original_widget)
389 urwid.WidgetWrap.__init__(self, columns)
390
391