comparison sat_frontends/primitivus/status.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children e6806aaab16d
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
23 from sat_frontends.quick_frontend.constants import Const as commonConst 23 from sat_frontends.quick_frontend.constants import Const as commonConst
24 from sat_frontends.primitivus.constants import Const as C 24 from sat_frontends.primitivus.constants import Const as C
25 25
26 26
27 class StatusBar(urwid.Columns): 27 class StatusBar(urwid.Columns):
28
29 def __init__(self, host): 28 def __init__(self, host):
30 self.host = host 29 self.host = host
31 self.presence = sat_widgets.ClickableText('') 30 self.presence = sat_widgets.ClickableText("")
32 status_prefix = urwid.Text('[') 31 status_prefix = urwid.Text("[")
33 status_suffix = urwid.Text(']') 32 status_suffix = urwid.Text("]")
34 self.status = sat_widgets.ClickableText('') 33 self.status = sat_widgets.ClickableText("")
35 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '') 34 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, "")
36 urwid.Columns.__init__(self, [('weight', 1, self.presence), ('weight', 1, status_prefix), 35 urwid.Columns.__init__(
37 ('weight', 9, self.status), ('weight', 1, status_suffix)]) 36 self,
38 urwid.connect_signal(self.presence, 'click', self.onPresenceClick) 37 [
39 urwid.connect_signal(self.status, 'click', self.onStatusClick) 38 ("weight", 1, self.presence),
39 ("weight", 1, status_prefix),
40 ("weight", 9, self.status),
41 ("weight", 1, status_suffix),
42 ],
43 )
44 urwid.connect_signal(self.presence, "click", self.onPresenceClick)
45 urwid.connect_signal(self.status, "click", self.onStatusClick)
40 46
41 def onPresenceClick(self, sender=None): 47 def onPresenceClick(self, sender=None):
42 if not self.host.bridge.isConnected(self.host.current_profile): # FIXME: manage multi-profiles 48 if not self.host.bridge.isConnected(
49 self.host.current_profile
50 ): # FIXME: manage multi-profiles
43 return 51 return
44 options = [commonConst.PRESENCE[presence] for presence in commonConst.PRESENCE] 52 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) 53 list_widget = sat_widgets.GenericList(
46 decorated = sat_widgets.LabelLine(list_widget, sat_widgets.SurroundedText(_('Set your presence'))) 54 options=options, option_type=sat_widgets.ClickableText, on_click=self.onChange
55 )
56 decorated = sat_widgets.LabelLine(
57 list_widget, sat_widgets.SurroundedText(_("Set your presence"))
58 )
47 self.host.showPopUp(decorated) 59 self.host.showPopUp(decorated)
48 60
49 def onStatusClick(self, sender=None): 61 def onStatusClick(self, sender=None):
50 if not self.host.bridge.isConnected(self.host.current_profile): # FIXME: manage multi-profiles 62 if not self.host.bridge.isConnected(
63 self.host.current_profile
64 ): # FIXME: manage multi-profiles
51 return 65 return
52 pop_up_widget = sat_widgets.InputDialog(_('Set your status'), _('New status'), default_txt=self.status.get_text(), 66 pop_up_widget = sat_widgets.InputDialog(
53 cancel_cb=self.host.removePopUp, ok_cb=self.onChange) 67 _("Set your status"),
68 _("New status"),
69 default_txt=self.status.get_text(),
70 cancel_cb=self.host.removePopUp,
71 ok_cb=self.onChange,
72 )
54 self.host.showPopUp(pop_up_widget) 73 self.host.showPopUp(pop_up_widget)
55 74
56 def onChange(self, sender=None, user_data=None): 75 def onChange(self, sender=None, user_data=None):
57 new_value = user_data.get_text() 76 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()) 77 previous = (
78 [key for key in C.PRESENCE if C.PRESENCE[key][0] == self.presence.get_text()][
79 0
80 ],
81 self.status.get_text(),
82 )
59 if isinstance(user_data, sat_widgets.ClickableText): 83 if isinstance(user_data, sat_widgets.ClickableText):
60 new = ([key for key in commonConst.PRESENCE if commonConst.PRESENCE[key] == new_value][0], previous[1]) 84 new = (
85 [
86 key
87 for key in commonConst.PRESENCE
88 if commonConst.PRESENCE[key] == new_value
89 ][0],
90 previous[1],
91 )
61 elif isinstance(user_data, sat_widgets.AdvancedEdit): 92 elif isinstance(user_data, sat_widgets.AdvancedEdit):
62 new = (previous[0], new_value[0]) 93 new = (previous[0], new_value[0])
63 if new != previous: 94 if new != previous:
64 statuses = {C.PRESENCE_STATUSES_DEFAULT: new[1]} # FIXME: manage multilingual statuses 95 statuses = {
65 for profile in self.host.profiles: # FIXME: for now all the profiles share the same status 96 C.PRESENCE_STATUSES_DEFAULT: new[1]
66 self.host.bridge.setPresence(show=new[0], statuses=statuses, profile_key=profile) 97 } # FIXME: manage multilingual statuses
98 for (
99 profile
100 ) in (
101 self.host.profiles
102 ): # FIXME: for now all the profiles share the same status
103 self.host.bridge.setPresence(
104 show=new[0], statuses=statuses, profile_key=profile
105 )
67 self.setPresenceStatus(new[0], new[1]) 106 self.setPresenceStatus(new[0], new[1])
68 self.host.removePopUp() 107 self.host.removePopUp()
69 108
70 def setPresenceStatus(self, show, status): 109 def setPresenceStatus(self, show, status):
71 show_icon, show_attr = C.PRESENCE.get(show) 110 show_icon, show_attr = C.PRESENCE.get(show)
72 self.presence.set_text(('show_normal', show_icon)) 111 self.presence.set_text(("show_normal", show_icon))
73 if status is not None: 112 if status is not None:
74 self.status.set_text((show_attr, status)) 113 self.status.set_text((show_attr, status))
75 self.host.redraw() 114 self.host.redraw()