annotate frontends/src/primitivus/status.py @ 891:a7b2aacf22ac

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