annotate libervia/tui/chat.py @ 4299:d2deddd6df44

tools (xml_tools): add `namespace` argument to `xmlui_result_to_elt`: this allows to specify resulting Form namespace.
author Goffi <goffi@goffi.org>
date Fri, 06 Sep 2024 17:45:46 +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: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.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
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3190
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
10 # (at your option) any later version.
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
15 # GNU Affero General Public License for more details.
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
19
3159
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
20 from functools import total_ordering
3190
1c6dacbfcf27 primitivus (chat) Q&D way to see attachments
Goffi <goffi@goffi.org>
parents: 3159
diff changeset
21 from pathlib import Path
3159
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
22 import bisect
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
23 import urwid
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
24 from urwid_satext import sat_widgets
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
25 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
26 from libervia.backend.core import log as logging
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
27 from libervia.frontends.quick_frontend import quick_widgets
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
28 from libervia.frontends.quick_frontend import quick_chat
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
29 from libervia.frontends.quick_frontend import quick_games
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
30 from libervia.tui import game_tarot
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
31 from libervia.tui.constants import Const as C
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
32 from libervia.tui.keys import action_key_map as a_key
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
33 from libervia.tui.widget import LiberviaTUIWidget
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
34 from libervia.tui.contact_list import ContactList
3159
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
35
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
36
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
37 log = logging.getLogger(__name__)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
38
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
39
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
40 OCCUPANTS_FOOTER = _("{} occupants")
1987
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
41
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
42
2881
13e0a260e7b8 primitivus (chat): use the factorised code for user moved info messages.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
43 class MessageWidget(urwid.WidgetWrap, quick_chat.MessageWidget):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
44 def __init__(self, mess_data):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
45 """
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
46 @param mess_data(quick_chat.Message, None): message data
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
47 None: used only for non text widgets (e.g.: focus separator)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
48 """
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
49 self.mess_data = mess_data
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
50 mess_data.widgets.add(self)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
51 super(MessageWidget, self).__init__(urwid.Text(self.markup))
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
52
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
53 @property
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
54 def markup(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 return (
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
56 self._generate_info_markup()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 if self.mess_data.type == C.MESS_TYPE_INFO
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
58 else self._generate_markup()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
60
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
61 @property
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
62 def info_type(self):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
63 return self.mess_data.info_type
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
64
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
65 @property
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
66 def parent(self):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
67 return self.mess_data.parent
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
68
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
69 @property
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
70 def message(self):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
71 """Return currently displayed message"""
1993
981e2abbb56c quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents: 1988
diff changeset
72 return self.mess_data.main_message
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
73
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
74 @message.setter
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
75 def message(self, value):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 self.mess_data.message = {"": value}
1979
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
77 self.redraw()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
78
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
79 @property
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
80 def type(self):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
81 try:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
82 return self.mess_data.type
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
83 except AttributeError:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
84 return C.MESS_TYPE_INFO
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
85
1979
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
86 def redraw(self):
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
87 self._w.set_text(self.markup)
2024
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
88 self.mess_data.parent.host.redraw() # FIXME: should not be necessary
1979
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
89
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
90 def selectable(self):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
91 return True
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
92
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
93 def keypress(self, size, key):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
94 return key
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
95
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
96 def get_cursor_coords(self, size):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
97 return 0, 0
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
98
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
99 def render(self, size, focus=False):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
100 # Text widget doesn't render cursor, but we want one
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
101 # so we add it here
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
102 canvas = urwid.CompositeCanvas(self._w.render(size, focus))
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
103 if focus:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
104 canvas.set_cursor(self.get_cursor_coords(size))
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
105 return canvas
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
106
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
107 def _generate_info_markup(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
108 return ("info_msg", self.message)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
109
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
110 def _generate_markup(self):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
111 """Generate text markup according to message data and Widget options"""
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
112 markup = []
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
113 d = self.mess_data
1980
2a85c818751a primitivus (chat): mention is now visible by date in red instead of body (or a "[*]" if date is hidden)
Goffi <goffi@goffi.org>
parents: 1979
diff changeset
114 mention = d.mention
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
115
2024
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
116 # message status
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
117 if d.status is None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
118 markup.append(" ")
2024
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
119 elif d.status == "delivered":
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
120 markup.append(("msg_status_received", "✔"))
2024
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
121 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
122 log.warning("Unknown status: {}".format(d.status))
2024
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
123
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
124 # timestamp
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
125 if self.parent.show_timestamp:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 attr = "msg_mention" if mention else "date"
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
127 markup.append((attr, "[{}]".format(d.time_text)))
1980
2a85c818751a primitivus (chat): mention is now visible by date in red instead of body (or a "[*]" if date is hidden)
Goffi <goffi@goffi.org>
parents: 1979
diff changeset
128 else:
2a85c818751a primitivus (chat): mention is now visible by date in red instead of body (or a "[*]" if date is hidden)
Goffi <goffi@goffi.org>
parents: 1979
diff changeset
129 if mention:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 markup.append(("msg_mention", "[*]"))
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
131
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
132 # nickname
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
133 if self.parent.show_short_nick:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 markup.append(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
135 ("my_nick" if d.own_mess else "other_nick", "**" if d.own_mess else "*")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
136 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
137 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
138 markup.append(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
139 ("my_nick" if d.own_mess else "other_nick", "[{}] ".format(d.nick or ""))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
141
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
142 msg = self.message # needed to generate self.selected_lang
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
143
1993
981e2abbb56c quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents: 1988
diff changeset
144 if d.selected_lang:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
145 markup.append(("msg_lang", "[{}] ".format(d.selected_lang)))
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
146
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
147 # message body
1980
2a85c818751a primitivus (chat): mention is now visible by date in red instead of body (or a "[*]" if date is hidden)
Goffi <goffi@goffi.org>
parents: 1979
diff changeset
148 markup.append(msg)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
149
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
150 return markup
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
151
2024
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
152 # events
2075
4f3ebf786fbc quick_frontend, primitivus (chat): renamed updated to update, using a dict as argument + fixed Primitivus group chat
Goffi <goffi@goffi.org>
parents: 2067
diff changeset
153 def update(self, update_dict=None):
4f3ebf786fbc quick_frontend, primitivus (chat): renamed updated to update, using a dict as argument + fixed Primitivus group chat
Goffi <goffi@goffi.org>
parents: 2067
diff changeset
154 """update all the linked message widgets
4f3ebf786fbc quick_frontend, primitivus (chat): renamed updated to update, using a dict as argument + fixed Primitivus group chat
Goffi <goffi@goffi.org>
parents: 2067
diff changeset
155
4f3ebf786fbc quick_frontend, primitivus (chat): renamed updated to update, using a dict as argument + fixed Primitivus group chat
Goffi <goffi@goffi.org>
parents: 2067
diff changeset
156 @param update_dict(dict, None): key=attribute updated value=new_value
4f3ebf786fbc quick_frontend, primitivus (chat): renamed updated to update, using a dict as argument + fixed Primitivus group chat
Goffi <goffi@goffi.org>
parents: 2067
diff changeset
157 """
2024
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
158 self.redraw()
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
159
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
161 @total_ordering
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
162 class OccupantWidget(urwid.WidgetWrap):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
163 def __init__(self, occupant_data):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
164 self.occupant_data = occupant_data
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
165 occupant_data.widgets.add(self)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
166 markup = self._generate_markup()
2020
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2018
diff changeset
167 text = sat_widgets.ClickableText(markup)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
168 urwid.connect_signal(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 text,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
170 "click",
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
171 self.occupant_data.parent._occupants_clicked,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
172 user_args=[self.occupant_data],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 )
2020
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2018
diff changeset
174 super(OccupantWidget, self).__init__(text)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
175
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
176 def __hash__(self):
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
177 return id(self)
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
178
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
179 def __eq__(self, other):
1988
3f0d22565684 primitivus (chat): fixed a crash when page-up was pressed on room contacts list
Goffi <goffi@goffi.org>
parents: 1987
diff changeset
180 if other is None:
3f0d22565684 primitivus (chat): fixed a crash when page-up was pressed on room contacts list
Goffi <goffi@goffi.org>
parents: 1987
diff changeset
181 return False
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
182 return self.occupant_data.nick == other.occupant_data.nick
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
183
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
184 def __lt__(self, other):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
185 return self.occupant_data.nick.lower() < other.occupant_data.nick.lower()
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
186
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
187 @property
2007
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
188 def markup(self):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
189 return self._generate_markup()
2007
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
190
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
191 @property
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
192 def parent(self):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
193 return self.mess_data.parent
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
194
1971
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
195 @property
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
196 def nick(self):
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
197 return self.occupant_data.nick
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
198
2007
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
199 def redraw(self):
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
200 self._w.set_text(self.markup)
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
201 self.occupant_data.parent.host.redraw() # FIXME: should not be necessary
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
202
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
203 def selectable(self):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
204 return True
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
205
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
206 def keypress(self, size, key):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
207 return key
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
208
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
209 def get_cursor_coords(self, size):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
210 return 0, 0
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
211
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
212 def render(self, size, focus=False):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
213 # Text widget doesn't render cursor, but we want one
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
214 # so we add it here
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
215 canvas = urwid.CompositeCanvas(self._w.render(size, focus))
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
216 if focus:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
217 canvas.set_cursor(self.get_cursor_coords(size))
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
218 return canvas
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
219
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
220 def _generate_markup(self):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
221 # TODO: role and affiliation are shown in a Q&D way
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
222 # should be more intuitive and themable
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
223 o = self.occupant_data
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
224 markup = []
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
225 markup.append(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
226 ("info_msg", "{}{} ".format(o.role[0].upper(), o.affiliation[0].upper()))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
227 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
228 markup.append(o.nick)
2007
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
229 if o.state is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
230 markup.append(" {}".format(C.CHAT_STATE_ICON[o.state]))
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
231 return markup
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
232
2007
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
233 # events
2075
4f3ebf786fbc quick_frontend, primitivus (chat): renamed updated to update, using a dict as argument + fixed Primitivus group chat
Goffi <goffi@goffi.org>
parents: 2067
diff changeset
234 def update(self, update_dict=None):
2007
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
235 self.redraw()
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
236
638
6821fc06a324 misc: a few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 637
diff changeset
237
1987
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
238 class OccupantsWidget(urwid.WidgetWrap):
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
239 def __init__(self, parent):
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
240 self.parent = parent
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
241 self.occupants_walker = urwid.SimpleListWalker([])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
242 self.occupants_footer = urwid.Text("", align="center")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
243 self.update_footer()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
244 occupants_widget = urwid.Frame(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
245 urwid.ListBox(self.occupants_walker), footer=self.occupants_footer
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
246 )
1987
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
247 super(OccupantsWidget, self).__init__(occupants_widget)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
248 occupants_list = sorted(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
249 list(self.parent.occupants.keys()), key=lambda o: o.lower()
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
250 )
1987
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
251 for occupant in occupants_list:
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
252 occupant_data = self.parent.occupants[occupant]
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
253 self.occupants_walker.append(OccupantWidget(occupant_data))
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
254
2988
b5f8cb26ef6f quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents: 2904
diff changeset
255 def clear(self):
b5f8cb26ef6f quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents: 2904
diff changeset
256 del self.occupants_walker[:]
b5f8cb26ef6f quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents: 2904
diff changeset
257
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
258 def update_footer(self):
1987
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
259 """update footer widget"""
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
260 txt = OCCUPANTS_FOOTER.format(len(self.parent.occupants))
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
261 self.occupants_footer.set_text(txt)
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
262
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
263 def get_nicks(self, start=""):
1987
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
264 """Return nicks of all occupants
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
265
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
266 @param start(unicode): only return nicknames which start with this text
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
267 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
268 return [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
269 w.nick
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
270 for w in self.occupants_walker
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
271 if isinstance(w, OccupantWidget) and w.nick.startswith(start)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
272 ]
1987
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
273
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
274 def addUser(self, occupant_data):
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
275 """add a user to the list"""
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
276 bisect.insort(self.occupants_walker, OccupantWidget(occupant_data))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
277 self.update_footer()
1987
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
278 self.parent.host.redraw() # FIXME: should not be necessary
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
279
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
280 def removeUser(self, occupant_data):
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
281 """remove a user from the list"""
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
282 for widget in occupant_data.widgets:
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
283 self.occupants_walker.remove(widget)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
284 self.update_footer()
1987
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
285 self.parent.host.redraw() # FIXME: should not be necessary
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
286
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
287
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
288 class Chat(LiberviaTUIWidget, quick_chat.QuickChat):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
289 def __init__(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
290 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
291 host,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
292 target,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
293 type_=C.CHAT_ONE2ONE,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
294 nick=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
295 occupants=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
296 subject=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
297 statuses=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
298 profiles=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
299 ):
1966
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
300 self.filters = [] # list of filter callbacks to apply
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
301 self.mess_walker = urwid.SimpleListWalker([])
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
302 self.mess_widgets = urwid.ListBox(self.mess_walker)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
303 self.chat_widget = urwid.Frame(self.mess_widgets)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
304 self.chat_colums = urwid.Columns([("weight", 8, self.chat_widget)])
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
305 self.pile = urwid.Pile([self.chat_colums])
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
306 LiberviaTUIWidget.__init__(self, self.pile, target)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
307 quick_chat.QuickChat.__init__(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
308 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
309 host,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
310 target,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
311 type_,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
312 nick,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
313 occupants,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
314 subject,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
315 statuses,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
316 profiles=profiles,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
317 )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
318
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
319 # we must adapt the behaviour with the type
1762
2e2fb462729a quick_frontend, primitivus (chat): printing the history is left to quick_frontend
souliane <souliane@mailoo.org>
parents: 1751
diff changeset
320 if type_ == C.CHAT_GROUP:
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
321 if len(self.chat_colums.contents) == 1:
1987
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
322 self.occupants_widget = OccupantsWidget(self)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
323 self.occupants_panel = sat_widgets.VerticalSeparator(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
324 self.occupants_widget
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
325 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
326 self._append_occupants_panel()
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
327 self.host.addListener("presence", self.presence_listener, [profiles])
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
328
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
329 # focus marker is a separator indicated last visible message before focus was lost
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
330 self.focus_marker = None # link to current marker
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
331 self.focus_marker_set = None # True if a new marker has been inserted
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
332 self.show_timestamp = True
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
333 self.show_short_nick = False
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
334 self.show_title = 1 # 0: clip title; 1: full title; 2: no title
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
335 self.post_init()
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
336
2881
13e0a260e7b8 primitivus (chat): use the factorised code for user moved info messages.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
337 @property
13e0a260e7b8 primitivus (chat): use the factorised code for user moved info messages.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
338 def message_widgets_rev(self):
13e0a260e7b8 primitivus (chat): use the factorised code for user moved info messages.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
339 return reversed(self.mess_walker)
13e0a260e7b8 primitivus (chat): use the factorised code for user moved info messages.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
340
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
341 def keypress(self, size, key):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
342 if key == a_key["OCCUPANTS_HIDE"]: # user wants to (un)hide the occupants panel
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
343 if self.type == C.CHAT_GROUP:
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
344 widgets = [widget for (widget, options) in self.chat_colums.contents]
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
345 if self.occupants_panel in widgets:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
346 self._remove_occupants_panel()
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
347 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
348 self._append_occupants_panel()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
349 elif key == a_key["TIMESTAMP_HIDE"]: # user wants to (un)hide timestamp
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
350 self.show_timestamp = not self.show_timestamp
1979
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
351 self.redraw()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
352 elif key == a_key["SHORT_NICKNAME"]: # user wants to (not) use short nick
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
353 self.show_short_nick = not self.show_short_nick
1979
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
354 self.redraw()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
355 elif key == a_key["SUBJECT_SWITCH"]:
2881
13e0a260e7b8 primitivus (chat): use the factorised code for user moved info messages.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
356 # user wants to (un)hide group's subject or change its apperance
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
357 if self.subject:
130
5a88ad24ccc0 Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents: 126
diff changeset
358 self.show_title = (self.show_title + 1) % 3
5a88ad24ccc0 Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents: 126
diff changeset
359 if self.show_title == 0:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
360 self.set_subject(self.subject, "clip")
130
5a88ad24ccc0 Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents: 126
diff changeset
361 elif self.show_title == 1:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
362 self.set_subject(self.subject, "space")
130
5a88ad24ccc0 Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents: 126
diff changeset
363 elif self.show_title == 2:
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
364 self.chat_widget.header = None
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
365 self._invalidate()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
366 elif key == a_key["GOTO_BOTTOM"]: # user wants to focus last message
2333
a21b3b31086d primitivus (chat): added "GOTO_BOTTOM" ("G") shortcut to scroll down to last message in history
Goffi <goffi@goffi.org>
parents: 2332
diff changeset
367 self.mess_widgets.focus_position = len(self.mess_walker) - 1
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
368
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
369 return super(Chat, self).keypress(size, key)
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
370
1971
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
371 def completion(self, text, completion_data):
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
372 """Completion method which complete nicknames in group chat
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
373
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
374 for params, see [sat_widgets.AdvancedEdit]
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
375 """
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
376 if self.type != C.CHAT_GROUP:
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
377 return text
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
378
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
379 space = text.rfind(" ")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
380 start = text[space + 1 :]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
381 words = self.occupants_widget.get_nicks(start)
1971
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
382 if not words:
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
383 return text
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
384 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
385 word_idx = words.index(completion_data["last_word"]) + 1
1971
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
386 except (KeyError, ValueError):
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
387 word_idx = 0
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
388 else:
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
389 if word_idx == len(words):
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
390 word_idx = 0
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
391 word = completion_data["last_word"] = words[word_idx]
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
392 return "{}{}{}".format(text[: space + 1], word, ": " if space < 0 else "")
1971
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
393
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
394 def get_menu(self):
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
395 """Return Menu bar"""
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 202
diff changeset
396 menu = sat_widgets.Menu(self.host.loop)
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
397 if self.type == C.CHAT_GROUP:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
398 self.host.add_menus(menu, C.MENU_ROOM, {"room_jid": self.target.bare})
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
399 game = _("Game")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
400 menu.add_menu(game, "Tarot", self.on_tarot_request)
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
401 elif self.type == C.CHAT_ONE2ONE:
1634
95ea323e7d04 primitivus: removed all file menu + temporary workaround to send full jid on C.MENU_SINGLE menu action.
Goffi <goffi@goffi.org>
parents: 1580
diff changeset
402 # FIXME: self.target is a bare jid, we need to check that
95ea323e7d04 primitivus: removed all file menu + temporary workaround to send full jid on C.MENU_SINGLE menu action.
Goffi <goffi@goffi.org>
parents: 1580
diff changeset
403 contact_list = self.host.contact_lists[self.profile]
1637
7751b5a51586 primivitus: fixed crash when self.target is a full jid
Goffi <goffi@goffi.org>
parents: 1634
diff changeset
404 if not self.target.resource:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
405 full_jid = contact_list.get_full_jid(self.target)
1637
7751b5a51586 primivitus: fixed crash when self.target is a full jid
Goffi <goffi@goffi.org>
parents: 1634
diff changeset
406 else:
7751b5a51586 primivitus: fixed crash when self.target is a full jid
Goffi <goffi@goffi.org>
parents: 1634
diff changeset
407 full_jid = self.target
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
408 self.host.add_menus(menu, C.MENU_SINGLE, {"jid": full_jid})
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
409 return menu
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
410
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
411 def set_filter(self, args):
1966
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
412 """set filtering of messages
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
413
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
414 @param args(list[unicode]): filters following syntax "[filter]=[value]"
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
415 empty list to clear all filters
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
416 only lang=XX is handled for now
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
417 """
1967
de6faf9be715 primitivus (chat): fixed filters clearing when changing filter while one already exists
Goffi <goffi@goffi.org>
parents: 1966
diff changeset
418 del self.filters[:]
1966
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
419 if args:
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
420 if args[0].startswith("lang="):
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
421 lang = args[0][5:].strip()
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
422 self.filters.append(lambda mess_data: lang in mess_data.message)
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
423
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
424 self.print_messages()
1966
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
425
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
426 def presence_listener(self, entity, show, priority, statuses, profile):
1388
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
427 """Update entity's presence status
1378
3dae6964c071 quick_frontends, primitivus: move the chat states logic to quick_frontend
souliane <souliane@mailoo.org>
parents: 1377
diff changeset
428
1388
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
429 @param entity (jid.JID): entity updated
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
430 @param show: availability
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
431 @param priority: resource's priority
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
432 @param statuses: dict of statuses
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
433 @param profile: %(doc_profile)s
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
434 """
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
435 # FIXME: disable for refactoring, need to be checked and re-enabled
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
436 return
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
437 # assert self.type == C.CHAT_GROUP
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
438 # if entity.bare != self.target:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
439 # return
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
440 # self.update(entity)
1388
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
441
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
442 def create_message(self, message):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
443 self.appendMessage(message)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
444
2335
b226f545f67e primitivus(chat): fixed scroll down (was broken when Primitivus had not the focus and was receiving messages)
Goffi <goffi@goffi.org>
parents: 2333
diff changeset
445 def _scrollDown(self):
b226f545f67e primitivus(chat): fixed scroll down (was broken when Primitivus had not the focus and was receiving messages)
Goffi <goffi@goffi.org>
parents: 2333
diff changeset
446 """scroll down message only if we are already at the bottom (minus 1)"""
b226f545f67e primitivus(chat): fixed scroll down (was broken when Primitivus had not the focus and was receiving messages)
Goffi <goffi@goffi.org>
parents: 2333
diff changeset
447 current_focus = self.mess_widgets.focus_position
b226f545f67e primitivus(chat): fixed scroll down (was broken when Primitivus had not the focus and was receiving messages)
Goffi <goffi@goffi.org>
parents: 2333
diff changeset
448 bottom = len(self.mess_walker) - 1
b226f545f67e primitivus(chat): fixed scroll down (was broken when Primitivus had not the focus and was receiving messages)
Goffi <goffi@goffi.org>
parents: 2333
diff changeset
449 if current_focus == bottom - 1:
b226f545f67e primitivus(chat): fixed scroll down (was broken when Primitivus had not the focus and was receiving messages)
Goffi <goffi@goffi.org>
parents: 2333
diff changeset
450 self.mess_widgets.focus_position = bottom # scroll down
b226f545f67e primitivus(chat): fixed scroll down (was broken when Primitivus had not the focus and was receiving messages)
Goffi <goffi@goffi.org>
parents: 2333
diff changeset
451 self.host.redraw() # FIXME: should not be necessary
b226f545f67e primitivus(chat): fixed scroll down (was broken when Primitivus had not the focus and was receiving messages)
Goffi <goffi@goffi.org>
parents: 2333
diff changeset
452
2992
4d5b9d4c7448 primitivus (chat): don't show minor notifications (all but mentions) when printing history
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
453 def appendMessage(self, message, minor_notifs=True):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
454 """Create a MessageWidget and append it
1388
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
455
2992
4d5b9d4c7448 primitivus (chat): don't show minor notifications (all but mentions) when printing history
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
456 Can merge info messages together if desirable (e.g.: multiple joined/leave)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
457 @param message(quick_chat.Message): message to add
2992
4d5b9d4c7448 primitivus (chat): don't show minor notifications (all but mentions) when printing history
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
458 @param minor_notifs(boolean): if True, basic notifications are allowed
4d5b9d4c7448 primitivus (chat): don't show minor notifications (all but mentions) when printing history
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
459 If False, notification are not shown except if we have an important one
4d5b9d4c7448 primitivus (chat): don't show minor notifications (all but mentions) when printing history
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
460 (like a mention).
4d5b9d4c7448 primitivus (chat): don't show minor notifications (all but mentions) when printing history
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
461 False is generally used when printing history, when we don't want every
4d5b9d4c7448 primitivus (chat): don't show minor notifications (all but mentions) when printing history
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
462 message to be notified.
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
463 """
3190
1c6dacbfcf27 primitivus (chat) Q&D way to see attachments
Goffi <goffi@goffi.org>
parents: 3159
diff changeset
464 if message.attachments:
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
465 # FIXME: Q&D way to see attachments in LiberviaTUI
3190
1c6dacbfcf27 primitivus (chat) Q&D way to see attachments
Goffi <goffi@goffi.org>
parents: 3159
diff changeset
466 # it should be done in a more user friendly way
1c6dacbfcf27 primitivus (chat) Q&D way to see attachments
Goffi <goffi@goffi.org>
parents: 3159
diff changeset
467 for lang, body in message.message.items():
1c6dacbfcf27 primitivus (chat) Q&D way to see attachments
Goffi <goffi@goffi.org>
parents: 3159
diff changeset
468 for attachment in message.attachments:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
469 if "url" in attachment:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
470 body += f"\n{attachment['url']}"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
471 elif "path" in attachment:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
472 path = Path(attachment["path"])
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
473 body += f"\n{path.as_uri()}"
3190
1c6dacbfcf27 primitivus (chat) Q&D way to see attachments
Goffi <goffi@goffi.org>
parents: 3159
diff changeset
474 else:
1c6dacbfcf27 primitivus (chat) Q&D way to see attachments
Goffi <goffi@goffi.org>
parents: 3159
diff changeset
475 log.warning(f'No "url" nor "path" in attachment: {attachment}')
1c6dacbfcf27 primitivus (chat) Q&D way to see attachments
Goffi <goffi@goffi.org>
parents: 3159
diff changeset
476 message.message[lang] = body
1c6dacbfcf27 primitivus (chat) Q&D way to see attachments
Goffi <goffi@goffi.org>
parents: 3159
diff changeset
477
1966
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
478 if self.filters:
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
479 if not all([f(message) for f in self.filters]):
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
480 return
2881
13e0a260e7b8 primitivus (chat): use the factorised code for user moved info messages.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
481
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
482 if self.handle_user_moved(message):
2881
13e0a260e7b8 primitivus (chat): use the factorised code for user moved info messages.
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
483 return
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
484
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
485 if (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
486 self.host.selected_widget != self or not self.host.x_notify.has_focus()
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
487 ) and self.focus_marker_set is not None:
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
488 if not self.focus_marker_set and not self._locked and self.mess_walker:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
489 if self.focus_marker is not None:
2904
5bba8953061e primitivus (chat): fixed crash when removing focus_marker after a :search or :history command
Goffi <goffi@goffi.org>
parents: 2881
diff changeset
490 try:
5bba8953061e primitivus (chat): fixed crash when removing focus_marker after a :search or :history command
Goffi <goffi@goffi.org>
parents: 2881
diff changeset
491 self.mess_walker.remove(self.focus_marker)
5bba8953061e primitivus (chat): fixed crash when removing focus_marker after a :search or :history command
Goffi <goffi@goffi.org>
parents: 2881
diff changeset
492 except ValueError:
5bba8953061e primitivus (chat): fixed crash when removing focus_marker after a :search or :history command
Goffi <goffi@goffi.org>
parents: 2881
diff changeset
493 # self.focus_marker may not be in mess_walker anymore if
5bba8953061e primitivus (chat): fixed crash when removing focus_marker after a :search or :history command
Goffi <goffi@goffi.org>
parents: 2881
diff changeset
494 # mess_walker has been cleared, e.g. when showing search
5bba8953061e primitivus (chat): fixed crash when removing focus_marker after a :search or :history command
Goffi <goffi@goffi.org>
parents: 2881
diff changeset
495 # result or using :history command
5bba8953061e primitivus (chat): fixed crash when removing focus_marker after a :search or :history command
Goffi <goffi@goffi.org>
parents: 2881
diff changeset
496 pass
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
497 self.focus_marker = urwid.Divider("—")
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
498 self.mess_walker.append(self.focus_marker)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
499 self.focus_marker_set = True
2335
b226f545f67e primitivus(chat): fixed scroll down (was broken when Primitivus had not the focus and was receiving messages)
Goffi <goffi@goffi.org>
parents: 2333
diff changeset
500 self._scrollDown()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
501 else:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
502 if self.focus_marker_set:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
503 self.focus_marker_set = False
1388
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
504
2736
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
505 wid = MessageWidget(message)
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
506 self.mess_walker.append(wid)
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
507 self._scrollDown()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
508 if self.is_user_moved(message):
2736
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
509 return # no notification for moved messages
2010
d2144d04065e primitivus (chat): don't send notification for move messages
Goffi <goffi@goffi.org>
parents: 2008
diff changeset
510
2736
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
511 # notifications
2010
d2144d04065e primitivus (chat): don't send notification for move messages
Goffi <goffi@goffi.org>
parents: 2008
diff changeset
512
2736
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
513 if self._locked:
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
514 # we don't want notifications when locked
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
515 # because that's history messages
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
516 return
2018
7199e6bdb94e quick_frontend, primitivus (chat): fixed widget bad locking + don't send notification when locked
Goffi <goffi@goffi.org>
parents: 2015
diff changeset
517
2736
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
518 if wid.mess_data.mention:
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
519 from_jid = wid.mess_data.from_jid
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
520 msg = _(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
521 "You have been mentioned by {nick} in {room}".format(
2736
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
522 nick=wid.mess_data.nick, room=self.target
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
523 )
2736
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
524 )
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
525 self.host.notify(
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
526 C.NOTIFY_MENTION, from_jid, msg, widget=self, profile=self.profile
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
527 )
2992
4d5b9d4c7448 primitivus (chat): don't show minor notifications (all but mentions) when printing history
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
528 elif not minor_notifs:
4d5b9d4c7448 primitivus (chat): don't show minor notifications (all but mentions) when printing history
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
529 return
2736
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
530 elif self.type == C.CHAT_ONE2ONE:
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
531 from_jid = wid.mess_data.from_jid
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
532 msg = _("{entity} is talking to you".format(entity=from_jid))
2736
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
533 self.host.notify(
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
534 C.NOTIFY_MESSAGE, from_jid, msg, widget=self, profile=self.profile
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
535 )
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
536 else:
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
537 self.host.notify(
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
538 C.NOTIFY_MESSAGE, self.target, widget=self, profile=self.profile
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
539 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
540
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
541 def addUser(self, nick):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
542 occupant = super(Chat, self).addUser(nick)
1987
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
543 self.occupants_widget.addUser(occupant)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
544
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
545 def removeUser(self, occupant_data):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
546 occupant = super(Chat, self).removeUser(occupant_data)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
547 if occupant is not None:
1987
ab439ffe4113 primitivus (chat): moved occupants widget to a dedicated class + display occupants count in footer
Goffi <goffi@goffi.org>
parents: 1980
diff changeset
548 self.occupants_widget.removeUser(occupant)
1388
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
549
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
550 def occupants_clear(self):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
551 super(Chat, self).occupants_clear()
2988
b5f8cb26ef6f quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents: 2904
diff changeset
552 self.occupants_widget.clear()
b5f8cb26ef6f quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents: 2904
diff changeset
553
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
554 def _occupants_clicked(self, occupant, clicked_wid):
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
555 assert self.type == C.CHAT_GROUP
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
556 contact_list = self.host.contact_lists[self.profile]
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
557
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
558 # we have a click on a nick, we need to create the widget if it doesn't exists
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
559 self.get_or_create_private_widget(occupant.jid)
511
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
560
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
561 # now we select the new window
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
562 for contact_list in self.host.widgets.get_widgets(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
563 ContactList, profiles=(self.profile,)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
564 ):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
565 contact_list.set_focus(occupant.jid, True)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
566
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
567 def _append_occupants_panel(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
568 self.chat_colums.contents.append((self.occupants_panel, ("weight", 2, False)))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
569
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
570 def _remove_occupants_panel(self):
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
571 for widget, options in self.chat_colums.contents:
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
572 if widget is self.occupants_panel:
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
573 self.chat_colums.contents.remove((widget, options))
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
574 break
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
575
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
576 def add_game_panel(self, widget):
1360
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
577 """Insert a game panel to this Chat dialog.
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
578
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
579 @param widget (Widget): the game panel
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
580 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
581 assert len(self.pile.contents) == 1
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
582 self.pile.contents.insert(0, (widget, ("weight", 1)))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
583 self.pile.contents.insert(1, (urwid.Filler(urwid.Divider("-"), ("fixed", 1))))
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
584 self.host.redraw()
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
585
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
586 def remove_game_panel(self, widget):
1360
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
587 """Remove the game panel from this Chat dialog.
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
588
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
589 @param widget (Widget): the game panel
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
590 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
591 assert len(self.pile.contents) == 3
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
592 del self.pile.contents[0]
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
593 self.host.redraw()
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
594
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
595 def set_subject(self, subject, wrap="space"):
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
596 """Set title for a group chat"""
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
597 quick_chat.QuickChat.set_subject(self, subject)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
598 self.subj_wid = urwid.Text(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
599 str(subject.replace("\n", "|") if wrap == "clip" else subject),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
600 align="left" if wrap == "clip" else "center",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
601 wrap=wrap,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
602 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
603 self.chat_widget.header = urwid.AttrMap(self.subj_wid, "title")
130
5a88ad24ccc0 Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents: 126
diff changeset
604 self.host.redraw()
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
605
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
606 ## Messages
1125
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1120
diff changeset
607
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
608 def print_messages(self, clear=True):
1979
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
609 """generate message widgets
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
610
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
611 @param clear(bool): clear message before printing if true
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
612 """
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
613 if clear:
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
614 del self.mess_walker[:]
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
615 for message in self.messages.values():
2992
4d5b9d4c7448 primitivus (chat): don't show minor notifications (all but mentions) when printing history
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
616 self.appendMessage(message, minor_notifs=False)
1979
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
617
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
618 def redraw(self):
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
619 """redraw all messages"""
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
620 for w in self.mess_walker:
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
621 try:
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
622 w.redraw()
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
623 except AttributeError:
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
624 pass
70e83ca721c8 primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
625
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
626 def update_history(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
627 self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, profile="@NONE@"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
628 ):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
629 del self.mess_walker[:]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
630 if filters and "search" in filters:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
631 self.mess_walker.append(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
632 urwid.Text(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
633 _("Results for searching the globbing pattern: {}").format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
634 filters["search"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
635 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
636 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
637 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
638 self.mess_walker.append(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
639 urwid.Text(_("Type ':history <lines>' to reset the chat history"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
640 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
641 super(Chat, self).update_history(size, filters, profile)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
642
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
643 def _on_history_printed(self):
1125
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1120
diff changeset
644 """Refresh or scroll down the focus after the history is printed"""
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
645 self.print_messages(clear=False)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
646 super(Chat, self)._on_history_printed()
1125
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1120
diff changeset
647
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
648 def on_private_created(self, widget):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
649 self.host.contact_lists[widget.profile].set_special(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
650 widget.target, C.CONTACT_SPECIAL_GROUP
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
651 )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
652
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
653 def on_selected(self):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
654 self.focus_marker_set = False
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
655
1786
104874018ab0 quick_frontend, primitivus (chat): move notification command to quick_frontend
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
656 def notify(self, contact="somebody", msg=""):
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
657 """Notify the user of a new message if Libervia TUI doesn't have the focus.
1748
3a6cd1c14974 frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents: 1637
diff changeset
658
3a6cd1c14974 frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents: 1637
diff changeset
659 @param contact (unicode): contact who wrote to the users
3a6cd1c14974 frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents: 1637
diff changeset
660 @param msg (unicode): the message that has been received
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
661 """
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
662 # FIXME: not called anymore after refactoring
739
7b72d5c30ebc primivitus: do not notify when an empty message is received
souliane <souliane@mailoo.org>
parents: 688
diff changeset
663 if msg == "":
7b72d5c30ebc primivitus: do not notify when an empty message is received
souliane <souliane@mailoo.org>
parents: 688
diff changeset
664 return
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
665 if self.mess_widgets.get_focus()[1] == len(self.mess_walker) - 2:
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
666 # we don't change focus if user is not at the bottom
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
667 # as that mean that he is probably watching discussion history
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
668 self.mess_widgets.focus_position = len(self.mess_walker) - 1
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
669 self.host.redraw()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
670 if not self.host.x_notify.has_focus():
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
671 if self.type == C.CHAT_ONE2ONE:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
672 self.host.x_notify.send_notification(
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
673 _("LiberviaTUI: %s is talking to you") % contact
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
674 )
1410
e2e75c3c7c7b quick_frontend, primitivus: fixes a couple of issues:
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
675 elif self.nick is not None and self.nick.lower() in msg.lower():
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
676 self.host.x_notify.send_notification(
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
677 _("LiberviaTUI: %(user)s mentioned you in room '%(room)s'")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
678 % {"user": contact, "room": self.target}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
679 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
680
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
681 # MENU EVENTS #
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
682 def on_tarot_request(self, menu):
1093
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
683 # TODO: move this to plugin_misc_tarot with dynamic menu
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
684 if len(self.occupants) != 4:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
685 self.host.show_pop_up(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
686 sat_widgets.Alert(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
687 _("Can't start game"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
688 _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
689 "You need to be exactly 4 peoples in the room to start a Tarot game"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
690 ),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
691 ok_cb=self.host.remove_pop_up,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
692 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
693 )
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
694 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
695 self.host.bridge.tarot_game_create(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
696 self.target, list(self.occupants), self.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
697 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
698
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
699 # MISC EVENTS #
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
700
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
701 def on_delete(self):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
702 # FIXME: to be checked after refactoring
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
703 super(Chat, self).on_delete()
1388
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
704 if self.type == C.CHAT_GROUP:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
705 self.host.removeListener("presence", self.presence_listener)
1388
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
706
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
707 def on_chat_state(self, from_jid, state, profile):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
708 super(Chat, self).on_chat_state(from_jid, state, profile)
2007
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
709 if self.type == C.CHAT_ONE2ONE:
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
710 self.title_dynamic = C.CHAT_STATE_ICON[state]
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
711 self.host.redraw() # FIXME: should not be necessary
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
712
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
713 def _on_subject_dialog_cb(self, button, dialog):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
714 self.change_subject(dialog.text)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
715 self.host.remove_pop_up(dialog)
2022
88c41a195728 primitivus (chat): added :topic (and :subject and :title aliases) to change subject with a dialog (/!\ urwid SàText need to be updated)
Goffi <goffi@goffi.org>
parents: 2020
diff changeset
716
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
717 def on_subject_dialog(self, new_subject=None):
2022
88c41a195728 primitivus (chat): added :topic (and :subject and :title aliases) to change subject with a dialog (/!\ urwid SàText need to be updated)
Goffi <goffi@goffi.org>
parents: 2020
diff changeset
718 dialog = sat_widgets.InputDialog(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
719 _("Change title"),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2992
diff changeset
720 _("Enter the new title"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
721 default_txt=new_subject if new_subject is not None else self.subject,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
722 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
723 dialog.set_callback("ok", self._on_subject_dialog_cb, dialog)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
724 dialog.set_callback("cancel", lambda __: self.host.remove_pop_up(dialog))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
725 self.host.show_pop_up(dialog)
2022
88c41a195728 primitivus (chat): added :topic (and :subject and :title aliases) to change subject with a dialog (/!\ urwid SàText need to be updated)
Goffi <goffi@goffi.org>
parents: 2020
diff changeset
726
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
727
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
728 quick_widgets.register(quick_chat.QuickChat, Chat)
1360
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
729 quick_widgets.register(quick_games.Tarot, game_tarot.TarotGame)