annotate frontends/src/primitivus/status.py @ 942:598fc223cf59

core: more organisation in constants.py
author Goffi <goffi@goffi.org>
date Fri, 28 Mar 2014 18:07:13 +0100
parents 255e6953b2c3
children aa15453ec54d
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):
937
255e6953b2c3 primitivus: do not display the presence/status dialog if the profile is not connected
souliane <souliane@mailoo.org>
parents: 811
diff changeset
44 if not self.host.bridge.isConnected(self.host.profile):
255e6953b2c3 primitivus: do not display the presence/status dialog if the profile is not connected
souliane <souliane@mailoo.org>
parents: 811
diff changeset
45 return
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
46 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
47 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
48 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
49 self.host.showPopUp(decorated)
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
50
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
51 def onStatusClick(self, sender=None):
937
255e6953b2c3 primitivus: do not display the presence/status dialog if the profile is not connected
souliane <souliane@mailoo.org>
parents: 811
diff changeset
52 if not self.host.bridge.isConnected(self.host.profile):
255e6953b2c3 primitivus: do not display the presence/status dialog if the profile is not connected
souliane <souliane@mailoo.org>
parents: 811
diff changeset
53 return
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
54 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
55 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
56 self.host.showPopUp(pop_up_widget)
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
57
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
58 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
59 new_value = user_data.get_text()
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
60 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
61 if isinstance(user_data, sat_widgets.ClickableText):
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
62 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
63 elif isinstance(user_data, sat_widgets.AdvancedEdit):
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
64 new = (previous[0], new_value[0])
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
65 if new != previous:
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
66 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
67 self.setPresenceStatus(new[0], new[1])
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
68 self.host.removePopUp()
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
69
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
70 def setPresenceStatus(self, show, status):
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
71 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
72 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
73 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
74 self.host.redraw()