comparison frontends/src/primitivus/status.py @ 737:378af36155c2

frontends: set and retrieve your own presence and status
author souliane <souliane@mailoo.org>
date Mon, 25 Nov 2013 01:56:07 +0100
parents
children 6c36149524ed
comparison
equal deleted inserted replaced
736:6246eb6d64a0 737:378af36155c2
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Primitivus: a SAT frontend
5 # Copyright (C) 2013 Adrien Cossa (souliane@mailoo.org)
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 import urwid
21 import copy
22 from urwid_satext import sat_widgets
23 from sat_frontends.primitivus.xmlui import XMLUI
24 from sat_frontends.constants import Const as commonConst
25 from sat_frontends.primitivus.constants import Const
26
27
28 class StatusBar(urwid.Columns):
29
30 def __init__(self, host):
31 self.host = host
32 self.presence = sat_widgets.ClickableText('')
33 status_prefix = urwid.Text('[')
34 status_suffix = urwid.Text(']')
35 self.status = sat_widgets.ClickableText('')
36 self.setPresenceStatus('', '')
37 urwid.Columns.__init__(self, [('weight', 1, self.presence), ('weight', 1, status_prefix),
38 ('weight', 9, self.status), ('weight', 1, status_suffix)])
39 urwid.connect_signal(self.presence, 'click', self.onPresenceClick)
40 urwid.connect_signal(self.status, 'click', self.onStatusClick)
41
42 def onPresenceClick(self, sender=None):
43 options = [commonConst.PRESENCE[presence] for presence in commonConst.PRESENCE]
44 list_widget = sat_widgets.GenericList(options=options, option_type=sat_widgets.ClickableText, on_click=self.onChange)
45 decorated = sat_widgets.LabelLine(list_widget, sat_widgets.SurroundedText(_('Set your presence')))
46 self.host.showPopUp(decorated)
47
48 def onStatusClick(self, sender=None):
49 pop_up_widget = sat_widgets.InputDialog(_('Set your status'), _('New status'), default_txt=self.status.get_text(),
50 cancel_cb=lambda dummy: self.host.removePopUp, ok_cb=self.onChange)
51 self.host.showPopUp(pop_up_widget)
52
53 def onChange(self, sender=None, user_data=None):
54 new_value = user_data.get_text()
55 previous = ([key for key in Const.PRESENCE if Const.PRESENCE[key][0] == self.presence.get_text()][0], self.status.get_text())
56 if isinstance(user_data, sat_widgets.ClickableText):
57 new = ([key for key in commonConst.PRESENCE if commonConst.PRESENCE[key] == new_value][0], previous[1])
58 elif isinstance(user_data, sat_widgets.AdvancedEdit):
59 new = (previous[0], new_value[0])
60 if new != previous:
61 self.host.bridge.setPresence(show=new[0], statuses={'default': new[1]}, profile_key=self.host.profile) #FIXME: manage multilingual statuses
62 self.setPresenceStatus(new[0], new[1])
63 self.host.removePopUp()
64
65 def setPresenceStatus(self, show, status):
66 show_icon, show_attr = Const.PRESENCE.get(show)
67 self.presence.set_text(('show_normal', show_icon))
68 self.status.set_text((show_attr, status))