Mercurial > urwid-satext
comparison frontends/primitivus/custom_widgets.py @ 9:6650747dfdcb
primitivus: contact list enhancement
- primitivus: contact list now display groups and sexy name (instead of bare jid)
- primitivus: contact list now show an alert when somebody want to contact you, and its chat window is not on the screen
- primitivus: cursor is now visible when going to chat window (useful to go back in logs)
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 12 Jul 2010 17:50:00 +0800 |
parents | ec01505ec109 |
children | 024b79b61a31 |
comparison
equal
deleted
inserted
replaced
8:ec01505ec109 | 9:6650747dfdcb |
---|---|
93 | 93 |
94 class SelectableText(urwid.FlowWidget): | 94 class SelectableText(urwid.FlowWidget): |
95 """Text which can be selected with space""" | 95 """Text which can be selected with space""" |
96 signals = ['change'] | 96 signals = ['change'] |
97 | 97 |
98 def __init__(self, text, align='left'): | 98 def __init__(self, text, align='left', header='', select_attr=None, default_attr=None, selected = False, data=None): |
99 self.text=unicode(text) | 99 self.text=unicode(text) |
100 self.header=header | |
101 if data: | |
102 self.data=data | |
103 if select_attr: | |
104 self.selected = select_attr | |
105 if default_attr: | |
106 self.default = default_attr | |
100 self.align = align | 107 self.align = align |
101 self.__selected=False | 108 self.__selected=selected |
102 | 109 |
103 def getValue(self): | 110 def getValue(self): |
104 return self.text | 111 return self.text |
112 | |
113 def setAttribute(self, name, value): | |
114 """Change attribut used for rendering widget | |
115 @param name: one of | |
116 -default: when not selected | |
117 -selected: when selected | |
118 @param value: name of the attribute | |
119 /!\ the attribute name followed by _focus is used when widget has focus""" | |
120 assert name in ['default', 'selected'] | |
121 self.__setattr__(name,value) | |
122 self._invalidate() | |
105 | 123 |
106 def setState(self, selected, invisible=False): | 124 def setState(self, selected, invisible=False): |
107 """Change state | 125 """Change state |
108 @param selected: boolean state value | 126 @param selected: boolean state value |
109 @param invisible: don't emit change signal if True""" | 127 @param invisible: don't emit change signal if True""" |
130 | 148 |
131 def render(self, size, focus=False): | 149 def render(self, size, focus=False): |
132 return self.display_widget(size, focus).render(size, focus) | 150 return self.display_widget(size, focus).render(size, focus) |
133 | 151 |
134 def display_widget(self, size, focus): | 152 def display_widget(self, size, focus): |
135 attr = 'selected' if self.__selected else 'default' | 153 try: |
154 select_attr = self.selected | |
155 except AttributeError: | |
156 select_attr = 'selected' | |
157 try: | |
158 default_attr = self.default | |
159 except AttributeError: | |
160 default_attr = 'default' | |
161 attr = select_attr if self.__selected else default_attr | |
136 if focus: | 162 if focus: |
137 attr+="_focus" | 163 attr+="_focus" |
138 return urwid.Text((attr,self.text), align=self.align) | 164 return urwid.Text((attr,self.header+self.text), align=self.align) |
139 | 165 |
140 class UnselectableText(SelectableText): | 166 class ClickableText(SelectableText): |
167 signals = SelectableText.signals + ['click'] | |
141 | 168 |
142 def setState(self, selected, invisible=False): | 169 def setState(self, selected, invisible=False): |
143 pass | 170 self._emit('click') |
144 | 171 |
145 class GenericList(urwid.WidgetWrap): | 172 class GenericList(urwid.WidgetWrap): |
146 signals = ['click','change'] | 173 signals = ['click','change'] |
147 | 174 |
148 def __init__(self, options, style=[], align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None): | 175 def __init__(self, options, style=[], align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None): |