comparison sat_frontends/primitivus/status.py @ 2562:26edcf3a30eb

core, setup: huge cleaning: - moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention - move twisted directory to root - removed all hacks from setup.py, and added missing dependencies, it is now clean - use https URL for website in setup.py - removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed - renamed sat.sh to sat and fixed its installation - added python_requires to specify Python version needed - replaced glib2reactor which use deprecated code by gtk3reactor sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author Goffi <goffi@goffi.org>
date Mon, 02 Apr 2018 19:44:50 +0200
parents frontends/src/primitivus/status.py@2daf7b4c6756
children 56f94936df1e
comparison
equal deleted inserted replaced
2561:bd30dc3ffe5a 2562:26edcf3a30eb
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3
4 # Primitivus: a SAT frontend
5 # Copyright (C) 2013-2016 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 from sat.core.i18n import _
21 import urwid
22 from urwid_satext import sat_widgets
23 from sat_frontends.quick_frontend.constants import Const as commonConst
24 from sat_frontends.primitivus.constants import Const as C
25
26
27 class StatusBar(urwid.Columns):
28
29 def __init__(self, host):
30 self.host = host
31 self.presence = sat_widgets.ClickableText('')
32 status_prefix = urwid.Text('[')
33 status_suffix = urwid.Text(']')
34 self.status = sat_widgets.ClickableText('')
35 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '')
36 urwid.Columns.__init__(self, [('weight', 1, self.presence), ('weight', 1, status_prefix),
37 ('weight', 9, self.status), ('weight', 1, status_suffix)])
38 urwid.connect_signal(self.presence, 'click', self.onPresenceClick)
39 urwid.connect_signal(self.status, 'click', self.onStatusClick)
40
41 def onPresenceClick(self, sender=None):
42 if not self.host.bridge.isConnected(self.host.current_profile): # FIXME: manage multi-profiles
43 return
44 options = [commonConst.PRESENCE[presence] for presence in commonConst.PRESENCE]
45 list_widget = sat_widgets.GenericList(options=options, option_type=sat_widgets.ClickableText, on_click=self.onChange)
46 decorated = sat_widgets.LabelLine(list_widget, sat_widgets.SurroundedText(_('Set your presence')))
47 self.host.showPopUp(decorated)
48
49 def onStatusClick(self, sender=None):
50 if not self.host.bridge.isConnected(self.host.current_profile): # FIXME: manage multi-profiles
51 return
52 pop_up_widget = sat_widgets.InputDialog(_('Set your status'), _('New status'), default_txt=self.status.get_text(),
53 cancel_cb=self.host.removePopUp, ok_cb=self.onChange)
54 self.host.showPopUp(pop_up_widget)
55
56 def onChange(self, sender=None, user_data=None):
57 new_value = user_data.get_text()
58 previous = ([key for key in C.PRESENCE if C.PRESENCE[key][0] == self.presence.get_text()][0], self.status.get_text())
59 if isinstance(user_data, sat_widgets.ClickableText):
60 new = ([key for key in commonConst.PRESENCE if commonConst.PRESENCE[key] == new_value][0], previous[1])
61 elif isinstance(user_data, sat_widgets.AdvancedEdit):
62 new = (previous[0], new_value[0])
63 if new != previous:
64 statuses = {C.PRESENCE_STATUSES_DEFAULT: new[1]} # FIXME: manage multilingual statuses
65 for profile in self.host.profiles: # FIXME: for now all the profiles share the same status
66 self.host.bridge.setPresence(show=new[0], statuses=statuses, profile_key=profile)
67 self.setPresenceStatus(new[0], new[1])
68 self.host.removePopUp()
69
70 def setPresenceStatus(self, show, status):
71 show_icon, show_attr = C.PRESENCE.get(show)
72 self.presence.set_text(('show_normal', show_icon))
73 if status is not None:
74 self.status.set_text((show_attr, status))
75 self.host.redraw()