annotate frontends/src/primitivus/status.py @ 2372:95a41c5f67c0

plugin tickets import: specialized importer for tickets, first draft: import tickets in a node with schema. Comments are not handled yet.
author Goffi <goffi@goffi.org>
date Fri, 06 Oct 2017 10:55:54 +0200
parents 2daf7b4c6756
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
1 #!/usr/bin/env python2
737
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
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1434
diff changeset
5 # Copyright (C) 2013-2016 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 from urwid_satext import sat_widgets
1327
89dc29afe01c frontends: merge sat_frontends.constants to sat_frontends.quick_frontend.constants
souliane <souliane@mailoo.org>
parents: 1184
diff changeset
23 from sat_frontends.quick_frontend.constants import Const as commonConst
1417
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
24 from sat_frontends.primitivus.constants import Const as C
737
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('')
1417
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
35 self.setPresenceStatus(C.PRESENCE_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):
1354
14fc88275e65 frontends (primitivus): fixes setting the presence and status (for now all the profiles share the same info)
souliane <souliane@mailoo.org>
parents: 1327
diff changeset
42 if not self.host.bridge.isConnected(self.host.current_profile): # FIXME: manage multi-profiles
937
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):
1354
14fc88275e65 frontends (primitivus): fixes setting the presence and status (for now all the profiles share the same info)
souliane <souliane@mailoo.org>
parents: 1327
diff changeset
50 if not self.host.bridge.isConnected(self.host.current_profile): # FIXME: manage multi-profiles
937
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()
1417
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
58 previous = ([key for key in C.PRESENCE if C.PRESENCE[key][0] == self.presence.get_text()][0], self.status.get_text())
737
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:
1434
b06047e1c1fb primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents: 1417
diff changeset
64 statuses = {C.PRESENCE_STATUSES_DEFAULT: new[1]} # FIXME: manage multilingual statuses
1354
14fc88275e65 frontends (primitivus): fixes setting the presence and status (for now all the profiles share the same info)
souliane <souliane@mailoo.org>
parents: 1327
diff changeset
65 for profile in self.host.profiles: # FIXME: for now all the profiles share the same status
1434
b06047e1c1fb primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents: 1417
diff changeset
66 self.host.bridge.setPresence(show=new[0], statuses=statuses, profile_key=profile)
737
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):
1417
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
71 show_icon, show_attr = C.PRESENCE.get(show)
737
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))
1417
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
73 if status is not None:
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
74 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
75 self.host.redraw()