annotate libervia/tui/status.py @ 4275:29fda1340078

plugin XEP-0176: Send ICE candidates buffer for initiator: - ICE buffer is now sent also for initiator. - If `ice_candidates_new_cb` is set in `session`, it will be used instead of using the `ice_candidates_new` signal. This is useful to handle internally the workflow, and will be used in incoming `Conferences` component. rel 445
author Goffi <goffi@goffi.org>
date Fri, 05 Jul 2024 17:18:32 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3010
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3010
diff changeset
2
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
3
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
4 # Libervia TUI
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
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
20 from libervia.backend.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
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
23 from libervia.frontends.quick_frontend.constants import Const as commonConst
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
24 from libervia.tui.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 def __init__(self, host):
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
29 self.host = host
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
30 self.presence = sat_widgets.ClickableText("")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
31 status_prefix = urwid.Text("[")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
32 status_suffix = urwid.Text("]")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
33 self.status = sat_widgets.ClickableText("")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
34 self.set_presence_status(C.PRESENCE_UNAVAILABLE, "")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
35 urwid.Columns.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
36 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
37 [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
38 ("weight", 1, self.presence),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
39 ("weight", 1, status_prefix),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
40 ("weight", 9, self.status),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 ("weight", 1, status_suffix),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
42 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
43 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
44 urwid.connect_signal(self.presence, "click", self.on_presence_click)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
45 urwid.connect_signal(self.status, "click", self.on_status_click)
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
46
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
47 def on_presence_click(self, sender=None):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
48 if not self.host.bridge.is_connected(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 self.host.current_profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
50 ): # 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 options = [commonConst.PRESENCE[presence] for presence in commonConst.PRESENCE]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 list_widget = sat_widgets.GenericList(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
54 options=options,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
55 option_type=sat_widgets.ClickableText,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
56 on_click=self.on_change,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 decorated = sat_widgets.LabelLine(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 list_widget, sat_widgets.SurroundedText(_("Set your presence"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
61 self.host.show_pop_up(decorated)
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
62
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
63 def on_status_click(self, sender=None):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
64 if not self.host.bridge.is_connected(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 self.host.current_profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 ): # 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
67 return
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 pop_up_widget = sat_widgets.InputDialog(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 _("Set your status"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 _("New status"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 default_txt=self.status.get_text(),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
72 cancel_cb=lambda _: self.host.remove_pop_up(),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
73 ok_cb=self.on_change,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
75 self.host.show_pop_up(pop_up_widget)
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
76
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
77 def on_change(self, sender=None, user_data=None):
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
78 new_value = user_data.get_text()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 previous = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 [key for key in C.PRESENCE if C.PRESENCE[key][0] == self.presence.get_text()][
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81 0
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
83 self.status.get_text(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
84 )
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
85 if isinstance(user_data, sat_widgets.ClickableText):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
86 new = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
88 key
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 for key in commonConst.PRESENCE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
90 if commonConst.PRESENCE[key] == new_value
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 ][0],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
92 previous[1],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
93 )
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
94 elif isinstance(user_data, sat_widgets.AdvancedEdit):
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
95 new = (previous[0], new_value[0])
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
96 if new != previous:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 statuses = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
98 C.PRESENCE_STATUSES_DEFAULT: new[1]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 } # FIXME: manage multilingual statuses
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 for (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
101 profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
102 ) in (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
103 self.host.profiles
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
104 ): # FIXME: for now all the profiles share the same status
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
105 self.host.bridge.presence_set(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
106 show=new[0], statuses=statuses, profile_key=profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
107 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
108 self.set_presence_status(new[0], new[1])
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
109 self.host.remove_pop_up()
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
110
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
111 def set_presence_status(self, show, status):
1417
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
112 show_icon, show_attr = C.PRESENCE.get(show)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
113 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
114 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
115 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
116 self.host.redraw()