Mercurial > libervia-backend
annotate frontends/src/primitivus/status.py @ 1288:7cf32aeeebdb frontends_multi_profiles
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 24 Jan 2015 00:14:58 +0100 |
parents | 62cba918cc63 |
children | 89dc29afe01c |
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 | 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 | 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 from urwid_satext import sat_widgets |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 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
|
24 from sat_frontends.primitivus.constants import Const |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
25 |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
26 |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
27 class StatusBar(urwid.Columns): |
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 def __init__(self, host): |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 self.host = host |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 self.presence = sat_widgets.ClickableText('') |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 status_prefix = urwid.Text('[') |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
33 status_suffix = urwid.Text(']') |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
34 self.status = sat_widgets.ClickableText('') |
1060
aa15453ec54d
core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents:
937
diff
changeset
|
35 self.setPresenceStatus('unavailable', '') |
737
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
36 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
|
37 ('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
|
38 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
|
39 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
|
40 |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
41 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
|
42 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
|
43 return |
737
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): |
937
255e6953b2c3
primitivus: do not display the presence/status dialog if the profile is not connected
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
50 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
|
51 return |
737
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
52 pop_up_widget = sat_widgets.InputDialog(_('Set your status'), _('New status'), default_txt=self.status.get_text(), |
1184
62cba918cc63
Primitivus: fixed cancel button for status change
Goffi <goffi@goffi.org>
parents:
1106
diff
changeset
|
53 cancel_cb=self.host.removePopUp, ok_cb=self.onChange) |
737
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
54 self.host.showPopUp(pop_up_widget) |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
55 |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
56 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
|
57 new_value = user_data.get_text() |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
58 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
|
59 if isinstance(user_data, sat_widgets.ClickableText): |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
60 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
|
61 elif isinstance(user_data, sat_widgets.AdvancedEdit): |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
62 new = (previous[0], new_value[0]) |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
63 if new != previous: |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
64 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
|
65 self.setPresenceStatus(new[0], new[1]) |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
66 self.host.removePopUp() |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
67 |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
68 def setPresenceStatus(self, show, status): |
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 self.host.redraw() |