Mercurial > urwid-satext
changeset 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 |
files | frontends/primitivus/custom_widgets.py |
diffstat | 1 files changed, 33 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/primitivus/custom_widgets.py Thu Jul 08 19:47:54 2010 +0800 +++ b/frontends/primitivus/custom_widgets.py Mon Jul 12 17:50:00 2010 +0800 @@ -95,13 +95,31 @@ """Text which can be selected with space""" signals = ['change'] - def __init__(self, text, align='left'): + def __init__(self, text, align='left', header='', select_attr=None, default_attr=None, selected = False, data=None): self.text=unicode(text) + self.header=header + if data: + self.data=data + if select_attr: + self.selected = select_attr + if default_attr: + self.default = default_attr self.align = align - self.__selected=False + self.__selected=selected def getValue(self): return self.text + + def setAttribute(self, name, value): + """Change attribut used for rendering widget + @param name: one of + -default: when not selected + -selected: when selected + @param value: name of the attribute + /!\ the attribute name followed by _focus is used when widget has focus""" + assert name in ['default', 'selected'] + self.__setattr__(name,value) + self._invalidate() def setState(self, selected, invisible=False): """Change state @@ -132,15 +150,24 @@ return self.display_widget(size, focus).render(size, focus) def display_widget(self, size, focus): - attr = 'selected' if self.__selected else 'default' + try: + select_attr = self.selected + except AttributeError: + select_attr = 'selected' + try: + default_attr = self.default + except AttributeError: + default_attr = 'default' + attr = select_attr if self.__selected else default_attr if focus: attr+="_focus" - return urwid.Text((attr,self.text), align=self.align) + return urwid.Text((attr,self.header+self.text), align=self.align) -class UnselectableText(SelectableText): +class ClickableText(SelectableText): + signals = SelectableText.signals + ['click'] def setState(self, selected, invisible=False): - pass + self._emit('click') class GenericList(urwid.WidgetWrap): signals = ['click','change']