annotate libervia/tui/base.py @ 4272:89a0999884ac default tip @

cli (list/set): add "--comments" argument.
author Goffi <goffi@goffi.org>
date Thu, 20 Jun 2024 14:46:55 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3016
diff changeset
1 #!/usr/bin/env python3
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
3 # Libervia TUI
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1707
diff changeset
4 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
6 # 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: 608
diff changeset
7 # 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: 608
diff changeset
8 # 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: 608
diff changeset
9 # (at your option) any later version.
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
11 # 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: 608
diff changeset
12 # 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: 608
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
14 # GNU Affero General Public License for more details.
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 608
diff changeset
16 # 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: 608
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
20 from libervia.backend.core.i18n import _, D_
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
21 from libervia.tui.constants import Const as C
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
22 from libervia.backend.core import log_config
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
23
4078
15055a00162c refactoring: rename `sat_configure` to `libervia_configure`
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
24 log_config.libervia_configure(C.LOG_BACKEND_STANDARD, C)
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
25 from libervia.backend.core import log as logging
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
26
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
27 log = logging.getLogger(__name__)
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
28 from libervia.backend.tools import config as sat_config
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 import urwid
1947
be4b143cf123 primitivus: fixed paste detection/handling:
Goffi <goffi@goffi.org>
parents: 1946
diff changeset
30 from urwid.util import is_wide_char
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
31 from urwid_satext import sat_widgets
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
32 from libervia.frontends.quick_frontend.quick_app import QuickApp
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
33 from libervia.frontends.quick_frontend import quick_utils
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
34 from libervia.frontends.quick_frontend import quick_chat
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
35 from libervia.tui.profile_manager import ProfileManager
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
36 from libervia.tui.contact_list import ContactList
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
37 from libervia.tui.chat import Chat
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
38 from libervia.tui import xmlui
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
39 from libervia.tui.progress import Progress
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
40 from libervia.tui.notify import Notify
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
41 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
42 from libervia.tui import config
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
43 from libervia.frontends.tools.misc import InputHistory
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
44 from libervia.backend.tools.common import dynamic_import
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
45 from libervia.frontends.tools import jid
1162
b32800b9793e primitivus: SIGINT is now ignored, APP_QUIT key/menu or :quit command must be used to quit Primitivus
Goffi <goffi@goffi.org>
parents: 1160
diff changeset
46 import signal
1949
c5fd304d0976 primitivus: added bracketed_paste option in sat.conf (if set, the bracketed paste mode will be activated on Primitivus start)
Goffi <goffi@goffi.org>
parents: 1948
diff changeset
47 import sys
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
48
2098
e0066920a661 primitivus, jp: dynamic bridge + fixed D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
49 ## bridge handling
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
50 # we get bridge name from conf and initialise the right class accordingly
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
51 main_config = sat_config.parse_main_conf()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
52 bridge_name = sat_config.config_get(main_config, "", "bridge", "dbus")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
53 if "dbus" not in bridge_name:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
54 print("only D-Bus bridge is currently supported")
2098
e0066920a661 primitivus, jp: dynamic bridge + fixed D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
55 sys.exit(3)
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
58 class EditBar(sat_widgets.ModalEdit):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
59 """
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
60 The modal edit bar where you would enter messages and commands.
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
61 """
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
62
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
63 def __init__(self, host):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
64 modes = {
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
65 None: (C.MODE_NORMAL, ""),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
66 a_key["MODE_INSERTION"]: (C.MODE_INSERTION, "> "),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
67 a_key["MODE_COMMAND"]: (C.MODE_COMMAND, ":"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
68 } # XXX: captions *MUST* be unicode
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
69 super(EditBar, self).__init__(modes)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
70 self.host = host
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
71 self.set_completion_method(self._text_completion)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
72 urwid.connect_signal(self, "click", self.on_text_entered)
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
73
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
74 def _text_completion(self, text, completion_data, mode):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
75 if mode == C.MODE_INSERTION:
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
76 if self.host.selected_widget is not None:
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
77 try:
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
78 completion = self.host.selected_widget.completion
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
79 except AttributeError:
9421e721d5e2 primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
80 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
81 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
82 return completion(text, completion_data)
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
83 else:
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
84 return text
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
85
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
86 def on_text_entered(self, editBar):
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
87 """Called when text is entered in the main edit bar"""
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
88 if self.mode == C.MODE_INSERTION:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
89 if isinstance(self.host.selected_widget, quick_chat.QuickChat):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
90 chat_widget = self.host.selected_widget
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
91 self.host.message_send(
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1938
diff changeset
92 chat_widget.target,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
93 {"": editBar.get_edit_text()}, # TODO: handle language
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
94 mess_type=(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
95 C.MESS_TYPE_GROUPCHAT
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
96 if chat_widget.type == C.CHAT_GROUP
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
97 else C.MESS_TYPE_CHAT
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
98 ), # TODO: put this in QuickChat
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
99 errback=lambda failure: self.host.show_dialog(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
100 _("Error while sending message ({})").format(failure),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
101 type="error",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
102 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
103 profile_key=chat_widget.profile,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
104 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
105 editBar.set_edit_text("")
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
106 elif self.mode == C.MODE_COMMAND:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
107 self.command_handler()
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
108
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
109 def command_handler(self):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
110 # TODO: separate class with auto documentation (with introspection)
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
111 # and completion method
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
112 tokens = self.get_edit_text().split(" ")
1119
5968fd8d2248 primitivus: change behavior of commands ":presence" and ":status" :
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
113 command, args = tokens[0], tokens[1:]
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
114 if command == "quit":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
115 self.host.on_exit()
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
116 raise urwid.ExitMainLoop()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
117 elif command == "messages":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
118 wid = sat_widgets.GenericList(logging.memory_get())
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
119 self.host.select_widget(wid)
1434
b06047e1c1fb primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents: 1417
diff changeset
120 # FIXME: reactivate the command
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
121 # elif command == 'presence':
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
122 # values = [value for value in commonConst.PRESENCE.keys()]
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
123 # values = [value if value else 'online' for value in values] # the empty value actually means 'online'
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
124 # if args and args[0] in values:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
125 # presence = '' if args[0] == 'online' else args[0]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
126 # self.host.status_bar.on_change(user_data=sat_widgets.ClickableText(commonConst.PRESENCE[presence]))
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
127 # else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
128 # self.host.status_bar.on_presence_click()
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
129 # elif command == 'status':
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
130 # if args:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
131 # self.host.status_bar.on_change(user_data=sat_widgets.AdvancedEdit(args[0]))
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
132 # else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
133 # self.host.status_bar.on_status_click()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
134 elif command == "history":
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
135 widget = self.host.selected_widget
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
136 if isinstance(widget, quick_chat.QuickChat):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
137 try:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
138 limit = int(args[0])
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
139 except (IndexError, ValueError):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
140 limit = 50
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
141 widget.update_history(size=limit, profile=widget.profile)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
142 elif command == "search":
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
143 widget = self.host.selected_widget
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
144 if isinstance(widget, quick_chat.QuickChat):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
145 pattern = " ".join(args)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
146 if not pattern:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
147 self.host.notif_bar.add_message(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
148 D_("Please specify the globbing pattern to search for")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
149 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
150 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
151 widget.update_history(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
152 size=C.HISTORY_LIMIT_NONE,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
153 filters={"search": pattern},
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
154 profile=widget.profile,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
155 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
156 elif command == "filter":
1966
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
157 # FIXME: filter is now only for current widget,
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
158 # need to be able to set it globally or per widget
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
159 widget = self.host.selected_widget
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
160 # FIXME: Q&D way, need to be more generic
d727aab9a80e primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
161 if isinstance(widget, quick_chat.QuickChat):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
162 widget.set_filter(args)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
163 elif command in ("topic", "suject", "title"):
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: 2016
diff changeset
164 try:
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: 2016
diff changeset
165 new_title = args[0].strip()
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: 2016
diff changeset
166 except IndexError:
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: 2016
diff changeset
167 new_title = None
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: 2016
diff changeset
168 widget = self.host.selected_widget
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: 2016
diff changeset
169 if isinstance(widget, quick_chat.QuickChat) and widget.type == C.CHAT_GROUP:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
170 widget.on_subject_dialog(new_title)
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
171 else:
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
172 return
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
173 self.set_edit_text("")
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
174
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
175 def _history_cb(self, text):
1160
2ff15a6c5791 primitivus: moved history method definition out of keypress
Goffi <goffi@goffi.org>
parents: 1159
diff changeset
176 self.set_edit_text(text)
2ff15a6c5791 primitivus: moved history method definition out of keypress
Goffi <goffi@goffi.org>
parents: 1159
diff changeset
177 self.set_edit_pos(len(text))
2ff15a6c5791 primitivus: moved history method definition out of keypress
Goffi <goffi@goffi.org>
parents: 1159
diff changeset
178
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
179 def keypress(self, size, key):
671
4e691a231763 frontend, primitivus: added input history (mode-wise)
souliane <souliane@mailoo.org>
parents: 661
diff changeset
180 """Callback when a key is pressed. Send "composing" states
4e691a231763 frontend, primitivus: added input history (mode-wise)
souliane <souliane@mailoo.org>
parents: 661
diff changeset
181 and move the index of the temporary history stack."""
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
182 if key == a_key["MODAL_ESCAPE"]:
738
e867f146d49f primitivus: save the input history when "esc" is pressed
souliane <souliane@mailoo.org>
parents: 737
diff changeset
183 # first save the text to the current mode, then change to NORMAL
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
184 self.host._update_input_history(self.get_edit_text(), mode=self.mode)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
185 self.host._update_input_history(mode=C.MODE_NORMAL)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
186 if self._mode == C.MODE_NORMAL and key in self._modes:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
187 self.host._update_input_history(mode=self._modes[key][0])
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
188 if key == a_key["HISTORY_PREV"]:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
189 self.host._update_input_history(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
190 self.get_edit_text(), -1, self._history_cb, self.mode
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
191 )
913
d08cbdd566e2 primitivus: EditBar doesn't propagate key pressed anymore if it manage a 'up' or 'down' event (history event)
Goffi <goffi@goffi.org>
parents: 911
diff changeset
192 return
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
193 elif key == a_key["HISTORY_NEXT"]:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
194 self.host._update_input_history(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
195 self.get_edit_text(), +1, self._history_cb, self.mode
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
196 )
913
d08cbdd566e2 primitivus: EditBar doesn't propagate key pressed anymore if it manage a 'up' or 'down' event (history event)
Goffi <goffi@goffi.org>
parents: 911
diff changeset
197 return
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
198 elif key == a_key["EDIT_ENTER"]:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
199 self.host._update_input_history(self.get_edit_text(), mode=self.mode)
671
4e691a231763 frontend, primitivus: added input history (mode-wise)
souliane <souliane@mailoo.org>
parents: 661
diff changeset
200 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
201 if (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
202 self._mode == C.MODE_INSERTION
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
203 and isinstance(self.host.selected_widget, quick_chat.QuickChat)
2012
53587e738aca primitivus: dont call chatStateComposing where history keys are pressed
Goffi <goffi@goffi.org>
parents: 2008
diff changeset
204 and key not in sat_widgets.FOCUS_KEYS
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
205 and key not in (a_key["HISTORY_PREV"], a_key["HISTORY_NEXT"])
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
206 and self.host.sync
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
207 ):
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
208 self.host.bridge.chat_state_composing(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
209 self.host.selected_widget.target, self.host.selected_widget.profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
210 )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
211
671
4e691a231763 frontend, primitivus: added input history (mode-wise)
souliane <souliane@mailoo.org>
parents: 661
diff changeset
212 return super(EditBar, self).keypress(size, key)
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
213
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
214
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
215 class LiberviaTUITopWidget(sat_widgets.FocusPile):
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
216 """Top most widget used in LiberviaTUI"""
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
217
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
218 _focus_inversed = True
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
219 positions = ("menu", "body", "notif_bar", "edit_bar")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
220 can_hide = ("menu", "notif_bar")
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
221
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
222 def __init__(self, body, menu, notif_bar, edit_bar):
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
223 self._body = body
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
224 self._menu = menu
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
225 self._notif_bar = notif_bar
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
226 self._edit_bar = edit_bar
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
227 self._hidden = {"notif_bar"}
1186
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
228 self._focus_extra = False
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
229 super(LiberviaTUITopWidget, self).__init__(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
230 [("pack", self._menu), self._body, ("pack", self._edit_bar)]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
231 )
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
232 for position in self.positions:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
233 setattr(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
234 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
235 position,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
236 property(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
237 lambda: self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
238 self.widget_get(position=position),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
239 lambda pos, new_wid: self.widget_set(new_wid, position=pos),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
240 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
241 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
242 self.focus_position = len(self.contents) - 1
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
243
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
244 def get_visible_positions(self, keep=None):
1186
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
245 """Return positions that are not hidden in the right order
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
246
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
247 @param keep: if not None, this position will be keep in the right order, even if it's hidden
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
248 (can be useful to find its index)
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
249 @return (list): list of visible positions
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
250 """
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
251 return [
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
252 pos
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
253 for pos in self.positions
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
254 if (keep and pos == keep) or pos not in self._hidden
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
255 ]
1186
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
256
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
257 def keypress(self, size, key):
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
258 """Manage FOCUS keys that focus directly a main part (one of self.positions)
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
259
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
260 To avoid key conflicts, a combinaison must be made with FOCUS_EXTRA then an other key
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
261 """
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
262 if key == a_key["FOCUS_EXTRA"]:
1186
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
263 self._focus_extra = True
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
264 return
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
265 if self._focus_extra:
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
266 self._focus_extra = False
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
267 if key in ("m", "1"):
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
268 focus = "menu"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
269 elif key in ("b", "2"):
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
270 focus = "body"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
271 elif key in ("n", "3"):
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
272 focus = "notif_bar"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
273 elif key in ("e", "4"):
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
274 focus = "edit_bar"
1186
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
275 else:
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
276 return super(LiberviaTUITopWidget, self).keypress(size, key)
1186
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
277
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
278 if focus in self._hidden:
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
279 return
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
280
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
281 self.focus_position = self.get_visible_positions().index(focus)
1186
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
282 return
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
283
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
284 return super(LiberviaTUITopWidget, self).keypress(size, key)
1186
9cc858acae91 primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
Goffi <goffi@goffi.org>
parents: 1185
diff changeset
285
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
286 def widget_get(self, position):
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
287 if not position in self.positions:
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
288 raise ValueError("Unknown position {}".format(position))
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
289 return getattr(self, "_{}".format(position))
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
290
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
291 def widget_set(self, widget, position):
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
292 if not position in self.positions:
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
293 raise ValueError("Unknown position {}".format(position))
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
294 return setattr(self, "_{}".format(position), widget)
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
295
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
296 def hide_switch(self, position):
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
297 if not position in self.can_hide:
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
298 raise ValueError("Can't switch position {}".format(position))
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
299 hide = not position in self._hidden
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
300 widget = self.widget_get(position)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
301 idx = self.get_visible_positions(position).index(position)
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
302 if hide:
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
303 del self.contents[idx]
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
304 self._hidden.add(position)
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
305 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
306 self.contents.insert(idx, (widget, ("pack", None)))
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
307 self._hidden.remove(position)
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
308
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
309 def show(self, position):
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
310 if position in self._hidden:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
311 self.hide_switch(position)
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
312
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
313 def hide(self, position):
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
314 if not position in self._hidden:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
315 self.hide_switch(position)
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
316
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
317
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
318 class LiberviaTUIApp(QuickApp, InputHistory):
2067
7834743705f0 quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
319 MB_HANDLER = False
2123
c42aab22c2c0 plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents: 2098
diff changeset
320 AVATARS_HANDLER = False
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
321
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
322 def __init__(self):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
323 bridge_module = dynamic_import.bridge(bridge_name, "libervia.frontends.bridge")
2098
e0066920a661 primitivus, jp: dynamic bridge + fixed D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
324 if bridge_module is None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
325 log.error("Can't import {} bridge".format(bridge_name))
2098
e0066920a661 primitivus, jp: dynamic bridge + fixed D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
326 sys.exit(3)
e0066920a661 primitivus, jp: dynamic bridge + fixed D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
327 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
328 log.debug("Loading {} bridge".format(bridge_name))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
329 QuickApp.__init__(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
330 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
331 bridge_factory=bridge_module.bridge,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
332 xmlui=xmlui,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
333 check_options=quick_utils.check_options,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
334 connect_bridge=False,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
335 )
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
336 ## main loop setup ##
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
337 event_loop = (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
338 urwid.GLibEventLoop if "dbus" in bridge_name else urwid.TwistedEventLoop
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
339 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
340 self.loop = urwid.MainLoop(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
341 urwid.SolidFill(),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
342 C.PALETTE,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
343 event_loop=event_loop(),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
344 input_filter=self.input_filter,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
345 unhandled_input=self.key_handler,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
346 )
2098
e0066920a661 primitivus, jp: dynamic bridge + fixed D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
347
3481
7892585b7e17 core (setup), jp, primitivus: update console scripts + classifiers:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
348 @classmethod
7892585b7e17 core (setup), jp, primitivus: update console scripts + classifiers:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
349 def run(cls):
7892585b7e17 core (setup), jp, primitivus: update console scripts + classifiers:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
350 cls().start()
7892585b7e17 core (setup), jp, primitivus: update console scripts + classifiers:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
351
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
352 def on_bridge_connected(self):
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
353
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
354 ##misc setup##
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
355 self._visible_widgets = set()
1181
ca8ce5a47969 Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
Goffi <goffi@goffi.org>
parents: 1165
diff changeset
356 self.notif_bar = sat_widgets.NotificationBar()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
357 urwid.connect_signal(self.notif_bar, "change", self.on_notification)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
358
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
359 self.progress_wid = self.widgets.get_or_create_widget(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
360 Progress, None, on_new_widget=None
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
361 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
362 urwid.connect_signal(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
363 self.notif_bar.progress,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
364 "click",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
365 lambda x: self.select_widget(self.progress_wid),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
366 )
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
367 self.__saved_overlay = None
380
ede26abf6ca1 primitivus: freedesktop notifications (if available) when somebody is talking to us and we have not focus, or our nick is pinged and we have not focus.
Goffi <goffi@goffi.org>
parents: 276
diff changeset
368
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 503
diff changeset
369 self.x_notify = Notify()
524
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
370
1162
b32800b9793e primitivus: SIGINT is now ignored, APP_QUIT key/menu or :quit command must be used to quit Primitivus
Goffi <goffi@goffi.org>
parents: 1160
diff changeset
371 # we already manage exit with a_key['APP_QUIT'], so we don't want C-c
b32800b9793e primitivus: SIGINT is now ignored, APP_QUIT key/menu or :quit command must be used to quit Primitivus
Goffi <goffi@goffi.org>
parents: 1160
diff changeset
372 signal.signal(signal.SIGINT, signal.SIG_IGN)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
373 sat_conf = sat_config.parse_main_conf()
3494
b5bed164dce0 frontends (primitivus): `SECTION_NAME` is now `CONFIG_SECTION`
Goffi <goffi@goffi.org>
parents: 3481
diff changeset
374 self._bracketed_paste = C.bool(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
375 sat_config.config_get(sat_conf, C.CONFIG_SECTION, "bracketed_paste", "false")
3494
b5bed164dce0 frontends (primitivus): `SECTION_NAME` is now `CONFIG_SECTION`
Goffi <goffi@goffi.org>
parents: 3481
diff changeset
376 )
1949
c5fd304d0976 primitivus: added bracketed_paste option in sat.conf (if set, the bracketed paste mode will be activated on Primitivus start)
Goffi <goffi@goffi.org>
parents: 1948
diff changeset
377 if self._bracketed_paste:
c5fd304d0976 primitivus: added bracketed_paste option in sat.conf (if set, the bracketed paste mode will be activated on Primitivus start)
Goffi <goffi@goffi.org>
parents: 1948
diff changeset
378 log.debug("setting bracketed paste mode as requested")
c5fd304d0976 primitivus: added bracketed_paste option in sat.conf (if set, the bracketed paste mode will be activated on Primitivus start)
Goffi <goffi@goffi.org>
parents: 1948
diff changeset
379 sys.stdout.write("\033[?2004h")
c5fd304d0976 primitivus: added bracketed_paste option in sat.conf (if set, the bracketed paste mode will be activated on Primitivus start)
Goffi <goffi@goffi.org>
parents: 1948
diff changeset
380 self._bracketed_mode_set = True
1162
b32800b9793e primitivus: SIGINT is now ignored, APP_QUIT key/menu or :quit command must be used to quit Primitivus
Goffi <goffi@goffi.org>
parents: 1160
diff changeset
381
2098
e0066920a661 primitivus, jp: dynamic bridge + fixed D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
382 self.loop.widget = self.main_widget = ProfileManager(self)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
383 self.post_init()
2098
e0066920a661 primitivus, jp: dynamic bridge + fixed D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
384
524
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
385 @property
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
386 def visible_widgets(self):
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
387 return self._visible_widgets
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
388
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
389 @property
524
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
390 def mode(self):
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
391 return self.editBar.mode
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
392
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
393 @mode.setter
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
394 def mode(self, value):
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
395 self.editBar.mode = value
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
396
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
397 def mode_hint(self, value):
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
398 """Change mode if make sens (i.e.: if there is nothing in the editBar)"""
524
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
399 if not self.editBar.get_edit_text():
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
400 self.mode = value
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
401
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
402 def debug(self):
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
403 """convenient method to reset screen and launch (i)p(u)db"""
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
404 log.info("Entered debug mode")
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
405 try:
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
406 import pudb
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
407
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
408 pudb.set_trace()
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
409 except ImportError:
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
410 import os
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
411
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
412 os.system("reset")
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
413 try:
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
414 import ipdb
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
415
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
416 ipdb.set_trace()
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
417 except ImportError:
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
418 import pdb
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
419
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
420 pdb.set_trace()
129
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
421
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
422 def redraw(self):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
423 """redraw the screen"""
422
5a18c5f08d9b Primitivus: Profile Manager: fixed redraw on profile change + use of AdvandedEdit for login field
Goffi <goffi@goffi.org>
parents: 415
diff changeset
424 try:
5a18c5f08d9b Primitivus: Profile Manager: fixed redraw on profile change + use of AdvandedEdit for login field
Goffi <goffi@goffi.org>
parents: 415
diff changeset
425 self.loop.draw_screen()
5a18c5f08d9b Primitivus: Profile Manager: fixed redraw on profile change + use of AdvandedEdit for login field
Goffi <goffi@goffi.org>
parents: 415
diff changeset
426 except AttributeError:
5a18c5f08d9b Primitivus: Profile Manager: fixed redraw on profile change + use of AdvandedEdit for login field
Goffi <goffi@goffi.org>
parents: 415
diff changeset
427 pass
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
428
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
429 def start(self):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
430 self.connect_bridge()
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
431 self.loop.run()
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
432
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
433 def post_init(self):
1159
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
434 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
435 config.apply_config(self)
1159
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
436 except Exception as e:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
437 log.error("configuration error: {}".format(e))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
438 popup = self.alert(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
439 _("Configuration Error"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
440 _(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
441 "Something went wrong while reading the configuration, please check :messages"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
442 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
443 )
1159
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
444 if self.options.profile:
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
445 self._early_popup = popup
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
446 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
447 self.show_pop_up(popup)
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
448 super(LiberviaTUIApp, self).post_init(self.main_widget)
1159
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
449
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
450 def keys_to_text(self, keys):
1947
be4b143cf123 primitivus: fixed paste detection/handling:
Goffi <goffi@goffi.org>
parents: 1946
diff changeset
451 """Generator return normal text from urwid keys"""
be4b143cf123 primitivus: fixed paste detection/handling:
Goffi <goffi@goffi.org>
parents: 1946
diff changeset
452 for k in keys:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
453 if k == "tab":
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
454 yield "\t"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
455 elif k == "enter":
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
456 yield "\n"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
457 elif is_wide_char(k, 0) or (len(k) == 1 and ord(k) >= 32):
1947
be4b143cf123 primitivus: fixed paste detection/handling:
Goffi <goffi@goffi.org>
parents: 1946
diff changeset
458 yield k
be4b143cf123 primitivus: fixed paste detection/handling:
Goffi <goffi@goffi.org>
parents: 1946
diff changeset
459
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
460 def input_filter(self, input_, raw):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
461 if self.__saved_overlay and input_ != a_key["OVERLAY_HIDE"]:
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
462 return
1946
827bb478d8af primitivus: paste is now detected, and put in edit bar, so use can check and validate it
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
463
1949
c5fd304d0976 primitivus: added bracketed_paste option in sat.conf (if set, the bracketed paste mode will be activated on Primitivus start)
Goffi <goffi@goffi.org>
parents: 1948
diff changeset
464 ## paste detection/handling
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
465 if (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
466 len(input_) > 1 # XXX: it may be needed to increase this value if buffer
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
467 and not isinstance(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
468 input_[0], tuple
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
469 ) # or other things result in several chars at once
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
470 and not "window resize" in input_
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
471 ): # (e.g. using LiberviaTUI through ssh). Need some testing
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
472 # and experience to adjust value.
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
473 if input_[0] == "begin paste" and not self._bracketed_paste:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
474 log.info("Bracketed paste mode detected")
1948
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
475 self._bracketed_paste = True
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
476
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
477 if self._bracketed_paste:
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
478 # after this block, extra will contain non pasted keys
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
479 # and input_ will contain pasted keys
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
480 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
481 begin_idx = input_.index("begin paste")
1948
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
482 except ValueError:
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
483 # this is not a paste, maybe we have something buffering
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
484 # or bracketed mode is set in conf but not enabled in term
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
485 extra = input_
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
486 input_ = []
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
487 else:
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
488 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
489 end_idx = input_.index("end paste")
1948
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
490 except ValueError:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
491 log.warning("missing end paste sequence, discarding paste")
1948
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
492 extra = input_[:begin_idx]
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
493 del input_[begin_idx:]
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
494 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
495 extra = input_[:begin_idx] + input_[end_idx + 1 :]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
496 input_ = input_[begin_idx + 1 : end_idx]
1948
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
497 else:
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
498 extra = None
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
499
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
500 log.debug("Paste detected (len {})".format(len(input_)))
1946
827bb478d8af primitivus: paste is now detected, and put in edit bar, so use can check and validate it
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
501 try:
827bb478d8af primitivus: paste is now detected, and put in edit bar, so use can check and validate it
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
502 edit_bar = self.editBar
827bb478d8af primitivus: paste is now detected, and put in edit bar, so use can check and validate it
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
503 except AttributeError:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
504 log.warning("Paste treated as normal text: there is no edit bar yet")
1981
2f97e58b6fa1 primitivus: paste is now treated as normal text instead of discarded if edit_bar doesn't exist
Goffi <goffi@goffi.org>
parents: 1974
diff changeset
505 if extra is None:
2f97e58b6fa1 primitivus: paste is now treated as normal text instead of discarded if edit_bar doesn't exist
Goffi <goffi@goffi.org>
parents: 1974
diff changeset
506 extra = []
2f97e58b6fa1 primitivus: paste is now treated as normal text instead of discarded if edit_bar doesn't exist
Goffi <goffi@goffi.org>
parents: 1974
diff changeset
507 extra.extend(input_)
1946
827bb478d8af primitivus: paste is now detected, and put in edit bar, so use can check and validate it
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
508 else:
1974
b34fdb44b7d4 primitivus: ignore paste if edit bar is not selected
Goffi <goffi@goffi.org>
parents: 1952
diff changeset
509 if self.main_widget.focus == edit_bar:
b34fdb44b7d4 primitivus: ignore paste if edit bar is not selected
Goffi <goffi@goffi.org>
parents: 1952
diff changeset
510 # XXX: if a paste is detected, we append it directly to the edit bar text
b34fdb44b7d4 primitivus: ignore paste if edit bar is not selected
Goffi <goffi@goffi.org>
parents: 1952
diff changeset
511 # so the user can check it and press [enter] if it's OK
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
512 buf_paste = "".join(self.keys_to_text(input_))
1974
b34fdb44b7d4 primitivus: ignore paste if edit bar is not selected
Goffi <goffi@goffi.org>
parents: 1952
diff changeset
513 pos = edit_bar.edit_pos
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
514 edit_bar.set_edit_text(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
515 "{}{}{}".format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
516 edit_bar.edit_text[:pos], buf_paste, edit_bar.edit_text[pos:]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
517 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
518 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
519 edit_bar.edit_pos += len(buf_paste)
1974
b34fdb44b7d4 primitivus: ignore paste if edit bar is not selected
Goffi <goffi@goffi.org>
parents: 1952
diff changeset
520 else:
b34fdb44b7d4 primitivus: ignore paste if edit bar is not selected
Goffi <goffi@goffi.org>
parents: 1952
diff changeset
521 # we are not on the edit_bar,
b34fdb44b7d4 primitivus: ignore paste if edit bar is not selected
Goffi <goffi@goffi.org>
parents: 1952
diff changeset
522 # so we treat pasted text as normal text
b34fdb44b7d4 primitivus: ignore paste if edit bar is not selected
Goffi <goffi@goffi.org>
parents: 1952
diff changeset
523 if extra is None:
b34fdb44b7d4 primitivus: ignore paste if edit bar is not selected
Goffi <goffi@goffi.org>
parents: 1952
diff changeset
524 extra = []
b34fdb44b7d4 primitivus: ignore paste if edit bar is not selected
Goffi <goffi@goffi.org>
parents: 1952
diff changeset
525 extra.extend(input_)
1948
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
526 if not extra:
1946
827bb478d8af primitivus: paste is now detected, and put in edit bar, so use can check and validate it
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
527 return
1948
373550000092 primitivus: bracketed paste mode is now detected
Goffi <goffi@goffi.org>
parents: 1947
diff changeset
528 input_ = extra
1949
c5fd304d0976 primitivus: added bracketed_paste option in sat.conf (if set, the bracketed paste mode will be activated on Primitivus start)
Goffi <goffi@goffi.org>
parents: 1948
diff changeset
529 ## end of paste detection/handling
1946
827bb478d8af primitivus: paste is now detected, and put in edit bar, so use can check and validate it
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
530
1164
af395a6f2551 primitivus: fixed forgotten keys
Goffi <goffi@goffi.org>
parents: 1163
diff changeset
531 for i in input_:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
532 if isinstance(i, tuple):
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
533 if i[0] == "mouse press":
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
534 if i[1] == 4: # Mouse wheel up
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
535 input_[input_.index(i)] = a_key["HISTORY_PREV"]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
536 if i[1] == 5: # Mouse wheel down
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
537 input_[input_.index(i)] = a_key["HISTORY_NEXT"]
1164
af395a6f2551 primitivus: fixed forgotten keys
Goffi <goffi@goffi.org>
parents: 1163
diff changeset
538 return input_
127
55d3ef84f01f Primitivus: mouse wheel changed to 'up' and 'down' key press
Goffi <goffi@goffi.org>
parents: 125
diff changeset
539
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
540 def key_handler(self, input_):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
541 if input_ == a_key["MENU_HIDE"]:
181
a566f654929e README update:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
542 """User want to (un)hide the menu roller"""
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
543 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
544 self.main_widget.hide_switch("menu")
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
545 except AttributeError:
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
546 pass
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
547 elif input_ == a_key["NOTIFICATION_NEXT"]:
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
548 """User wants to see next notification"""
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
549 self.notif_bar.show_next()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
550 elif input_ == a_key["OVERLAY_HIDE"]:
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
551 """User wants to (un)hide overlay window"""
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
552 if isinstance(self.loop.widget, urwid.Overlay):
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
553 self.__saved_overlay = self.loop.widget
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
554 self.loop.widget = self.main_widget
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
555 else:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
556 if self.__saved_overlay:
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
557 self.loop.widget = self.__saved_overlay
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
558 self.__saved_overlay = None
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
559
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
560 elif (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
561 input_ == a_key["DEBUG"] and ".dev0" in self.bridge.version_get()
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
562 ): # Debug only for dev versions
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
563 self.debug()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
564 elif input_ == a_key["CONTACTS_HIDE"]: # user wants to (un)hide the contact lists
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
565 try:
608
ea9aa51234eb Primitivus: fixed contacts list (un)hidding
Goffi <goffi@goffi.org>
parents: 607
diff changeset
566 for wid, options in self.center_part.contents:
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
567 if self.contact_lists_pile is wid:
608
ea9aa51234eb Primitivus: fixed contacts list (un)hidding
Goffi <goffi@goffi.org>
parents: 607
diff changeset
568 self.center_part.contents.remove((wid, options))
ea9aa51234eb Primitivus: fixed contacts list (un)hidding
Goffi <goffi@goffi.org>
parents: 607
diff changeset
569 break
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
570 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
571 self.center_part.contents.insert(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
572 0, (self.contact_lists_pile, ("weight", 2, False))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
573 )
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
574 except AttributeError:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
575 # The main widget is not built (probably in Profile Manager)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
576 pass
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
577 elif input_ == "window resize":
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
578 width, height = self.loop.screen_size
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
579 if height <= 5 and width <= 35:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
580 if not "save_main_widget" in dir(self):
129
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
581 self.save_main_widget = self.loop.widget
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
582 self.loop.widget = urwid.Filler(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
583 urwid.Text(_("Pleeeeasse, I can't even breathe !"))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
584 )
129
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
585 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
586 if "save_main_widget" in dir(self):
129
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
587 self.loop.widget = self.save_main_widget
542682d67282 sortilege's easter egg reimplemented
Goffi <goffi@goffi.org>
parents: 128
diff changeset
588 del self.save_main_widget
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
589 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
590 return self.menu_roller.check_shortcuts(input_)
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 127
diff changeset
591 except AttributeError:
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
592 return input_
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
593
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
594 def add_menus(self, menu, type_filter, menu_data=None):
1093
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
595 """Add cached menus to instance
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
596 @param menu: sat_widgets.Menu instance
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
597 @param type_filter: menu type like is sat.core.sat_main.import_menu
1093
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
598 @param menu_data: data to send with these menus
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
599
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
600 """
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
601
1093
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
602 def add_menu_cb(callback_id):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
603 self.action_launch(callback_id, menu_data, profile=self.current_profile)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
604
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
605 for id_, type_, path, path_i18n, extra in self.bridge.menus_get(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
606 "", C.NO_SECURITY_LIMIT
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
607 ): # TODO: manage extra
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
608 if type_ != type_filter:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
609 continue
1093
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
610 if len(path) != 2:
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
611 raise NotImplementedError("Menu with a path != 2 are not implemented yet")
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
612 menu.add_menu(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
613 path_i18n[0], path_i18n[1], lambda dummy, id_=id_: add_menu_cb(id_)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
614 )
1093
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
615
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
616 def _build_menu_roller(self):
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 219
diff changeset
617 menu = sat_widgets.Menu(self.loop)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 131
diff changeset
618 general = _("General")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
619 menu.add_menu(general, _("Connect"), self.on_connect_request)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
620 menu.add_menu(general, _("Disconnect"), self.on_disconnect_request)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
621 menu.add_menu(general, _("Parameters"), self.on_param)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
622 menu.add_menu(general, _("About"), self.on_about_request)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
623 menu.add_menu(general, _("Exit"), self.on_exit_request, a_key["APP_QUIT"])
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
624 menu.add_menu(_("Contacts")) # add empty menu to save the place in the menu order
1707
94c450972346 primitivus and plugins: renamed a few menus:
souliane <souliane@mailoo.org>
parents: 1676
diff changeset
625 groups = _("Groups")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
626 menu.add_menu(groups)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
627 menu.add_menu(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
628 groups, _("Join room"), self.on_join_room_request, a_key["ROOM_JOIN"]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
629 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
630 # additionals menus
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
631 # FIXME: do this in a more generic way (in quickapp)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
632 self.add_menus(menu, C.MENU_GLOBAL)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
633
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
634 menu_roller = sat_widgets.MenuRoller([(_("Main menu"), menu, C.MENU_ID_MAIN)])
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
635 return menu_roller
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
636
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
637 def _build_main_widget(self):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
638 self.contact_lists_pile = urwid.Pile([])
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
639 # self.center_part = urwid.Columns([('weight',2,self.contact_lists[profile]),('weight',8,Chat('',self))])
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
640 self.center_part = urwid.Columns(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
641 [
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
642 ("weight", 2, self.contact_lists_pile),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
643 ("weight", 8, urwid.Filler(urwid.Text(""))),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
644 ]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
645 )
524
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
646
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 634
diff changeset
647 self.editBar = EditBar(self)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
648 self.menu_roller = self._build_menu_roller()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
649 self.main_widget = LiberviaTUITopWidget(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
650 self.center_part, self.menu_roller, self.notif_bar, self.editBar
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
651 )
118
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
652 return self.main_widget
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
653
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
654 def plugging_profiles(self):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
655 self.loop.widget = self._build_main_widget()
415
3348331e0f09 primitivus: fixed screen redraw after plugin profile
Goffi <goffi@goffi.org>
parents: 411
diff changeset
656 self.redraw()
1159
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
657 try:
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
658 # if a popup arrived before main widget is build, we need to show it now
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
659 self.show_pop_up(self._early_popup)
1159
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
660 except AttributeError:
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
661 pass
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
662 else:
85fd02356dba primitivus: key can be changed in config:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
663 del self._early_popup
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
664
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
665 def profile_plugged(self, profile):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
666 QuickApp.profile_plugged(self, profile)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
667 contact_list = self.widgets.get_or_create_widget(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
668 ContactList,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
669 None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
670 on_new_widget=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
671 on_click=self.contact_selected,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
672 on_change=lambda w: self.redraw(),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
673 profile=profile,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
674 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
675 self.contact_lists_pile.contents.append((contact_list, ("weight", 1)))
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
676 return contact_list
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
677
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
678 def is_hidden(self):
1787
d678b723460b quick_frontend, primitivus: mechanism to signal a new message reception when the window is hidden (even if the message is actually displayed):
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
679 """Tells if the frontend window is hidden.
d678b723460b quick_frontend, primitivus: mechanism to signal a new message reception when the window is hidden (even if the message is actually displayed):
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
680
d678b723460b quick_frontend, primitivus: mechanism to signal a new message reception when the window is hidden (even if the message is actually displayed):
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
681 @return bool
d678b723460b quick_frontend, primitivus: mechanism to signal a new message reception when the window is hidden (even if the message is actually displayed):
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
682 """
d678b723460b quick_frontend, primitivus: mechanism to signal a new message reception when the window is hidden (even if the message is actually displayed):
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
683 return False # FIXME: implement when necessary
d678b723460b quick_frontend, primitivus: mechanism to signal a new message reception when the window is hidden (even if the message is actually displayed):
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
684
1609
66f0e877625b primitivus: fixed alert case + alert in profileManager
Goffi <goffi@goffi.org>
parents: 1582
diff changeset
685 def alert(self, title, message):
1580
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
686 """Shortcut method to create an alert message
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
687
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
688 Alert will have an "OK" button, which remove it if pressed
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
689 @param title(unicode): title of the dialog
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
690 @param message(unicode): body of the dialog
1609
66f0e877625b primitivus: fixed alert case + alert in profileManager
Goffi <goffi@goffi.org>
parents: 1582
diff changeset
691 @return (urwid_satext.Alert): the created Alert instance
1580
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
692 """
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
693 popup = sat_widgets.Alert(title, message)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
694 popup.set_callback("ok", lambda dummy: self.remove_pop_up(popup))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
695 self.show_pop_up(popup, width=75, height=20)
1580
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
696 return popup
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
697
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
698 def remove_pop_up(self, widget=None):
1580
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
699 """Remove current pop-up, and if there is other in queue, show it
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
700
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
701 @param widget(None, urwid.Widget): if not None remove this popup from front or queue
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
702 """
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
703 # TODO: refactor popup management in a cleaner way
3016
0b1c17c24bba core: fixed handling of button callback in popups:
Goffi <goffi@goffi.org>
parents: 3005
diff changeset
704 # buttons' callback use themselve as first argument, and we never use
0b1c17c24bba core: fixed handling of button callback in popups:
Goffi <goffi@goffi.org>
parents: 3005
diff changeset
705 # a Button directly in a popup, so we consider urwid.Button as None
0b1c17c24bba core: fixed handling of button callback in popups:
Goffi <goffi@goffi.org>
parents: 3005
diff changeset
706 if widget is not None and not isinstance(widget, urwid.Button):
1580
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
707 if isinstance(self.loop.widget, urwid.Overlay):
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
708 current_popup = self.loop.widget.top_w
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
709 if not current_popup == widget:
1676
a0810e0f386e primitivus: a warning is loggued when trying to remove an unknown popup, instead of an error raised
Goffi <goffi@goffi.org>
parents: 1659
diff changeset
710 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
711 self.notif_bar.remove_pop_up(widget)
1676
a0810e0f386e primitivus: a warning is loggued when trying to remove an unknown popup, instead of an error raised
Goffi <goffi@goffi.org>
parents: 1659
diff changeset
712 except ValueError:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
713 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
714 "Trying to remove an unknown widget {}".format(widget)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
715 )
1580
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
716 return
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
717 self.loop.widget = self.main_widget
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
718 next_popup = self.notif_bar.get_next_popup()
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
719 if next_popup:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
720 # we still have popup to show, we display it
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
721 self.show_pop_up(next_popup)
1580
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
722 else:
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1468
diff changeset
723 self.redraw()
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 116
diff changeset
724
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
725 def show_pop_up(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
726 self, pop_up_widget, width=None, height=None, align="center", valign="middle"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
727 ):
3005
595b8857538b primitivus: better popup sizing:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
728 """Show a pop-up window if possible, else put it in queue
595b8857538b primitivus: better popup sizing:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
729
595b8857538b primitivus: better popup sizing:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
730 @param pop_up_widget: pop up to show
595b8857538b primitivus: better popup sizing:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
731 @param width(int, None): width of the popup
595b8857538b primitivus: better popup sizing:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
732 None to use default
595b8857538b primitivus: better popup sizing:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
733 @param height(int, None): height of the popup
595b8857538b primitivus: better popup sizing:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
734 None to use default
595b8857538b primitivus: better popup sizing:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
735 @param align: same as for [urwid.Overlay]
595b8857538b primitivus: better popup sizing:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
736 """
595b8857538b primitivus: better popup sizing:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
737 if width == None:
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
738 width = 75 if isinstance(pop_up_widget, xmlui.LiberviaTUINoteDialog) else 135
3005
595b8857538b primitivus: better popup sizing:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
739 if height == None:
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
740 height = 20 if isinstance(pop_up_widget, xmlui.LiberviaTUINoteDialog) else 40
687
af0d08a84cc6 primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents: 679
diff changeset
741 if not isinstance(self.loop.widget, urwid.Overlay):
3005
595b8857538b primitivus: better popup sizing:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
742 display_widget = urwid.Overlay(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
743 pop_up_widget, self.main_widget, align, width, valign, height
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
744 )
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
745 self.loop.widget = display_widget
219
782319a64ac6 primitivus, wix: added forgotten profile
Goffi <goffi@goffi.org>
parents: 216
diff changeset
746 self.redraw()
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
747 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
748 self.notif_bar.add_pop_up(pop_up_widget)
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
749
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
750 def bar_notify(self, message):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
751 """ "Notify message to user via notification bar"""
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
752 self.notif_bar.add_message(message)
776
f89173f44850 frontends: fixed sendMessage calls, sendMessage is now async so callback and errback need to be specified + redraw in PrimivitusApp.notify
Goffi <goffi@goffi.org>
parents: 773
diff changeset
753 self.redraw()
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
754
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
755 def notify(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
756 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
757 type_,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
758 entity=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
759 message=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
760 subject=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
761 callback=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
762 cb_args=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
763 widget=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
764 profile=C.PROF_KEY_NONE,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
765 ):
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1971
diff changeset
766 if widget is None or widget is not None and widget != self.selected_widget:
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1971
diff changeset
767 # we ignore notification if the widget is selected but we can
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1971
diff changeset
768 # still do a desktop notification is the X window has not the focus
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
769 super(LiberviaTUIApp, self).notify(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
770 type_, entity, message, subject, callback, cb_args, widget, profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
771 )
2008
8a749ec21c50 primitivus: fixed notifications counter for simple messages in MUC rooms
Goffi <goffi@goffi.org>
parents: 1991
diff changeset
772 # we don't want notifications without message on desktop
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
773 if message is not None and not self.x_notify.has_focus():
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1971
diff changeset
774 if message is None:
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1971
diff changeset
775 message = _("{app}: a new event has just happened{entity}").format(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
776 app=C.APP_NAME, entity=" ({})".format(entity) if entity else ""
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
777 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
778 self.x_notify.send_notification(message)
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1971
diff changeset
779
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
780 def new_widget(self, widget, user_action=False):
3004
d86cddc1cd05 primitivus: select the widget even if an other one is selected when the selection comes from an user action:
Goffi <goffi@goffi.org>
parents: 3001
diff changeset
781 """Method called when a new widget is created
d86cddc1cd05 primitivus: select the widget even if an other one is selected when the selection comes from an user action:
Goffi <goffi@goffi.org>
parents: 3001
diff changeset
782
d86cddc1cd05 primitivus: select the widget even if an other one is selected when the selection comes from an user action:
Goffi <goffi@goffi.org>
parents: 3001
diff changeset
783 if suitable, the widget will be displayed
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
784 @param widget(widget.LiberviaTUIWidget): created widget
3004
d86cddc1cd05 primitivus: select the widget even if an other one is selected when the selection comes from an user action:
Goffi <goffi@goffi.org>
parents: 3001
diff changeset
785 @param user_action(bool): if True, the widget has been created following an
d86cddc1cd05 primitivus: select the widget even if an other one is selected when the selection comes from an user action:
Goffi <goffi@goffi.org>
parents: 3001
diff changeset
786 explicit user action. In this case, the widget may get focus immediately
d86cddc1cd05 primitivus: select the widget even if an other one is selected when the selection comes from an user action:
Goffi <goffi@goffi.org>
parents: 3001
diff changeset
787 """
1991
dbe025b03eba primitivus: fixed XMLUI window creation
Goffi <goffi@goffi.org>
parents: 1982
diff changeset
788 # FIXME: when several widgets are possible (e.g. with :split)
dbe025b03eba primitivus: fixed XMLUI window creation
Goffi <goffi@goffi.org>
parents: 1982
diff changeset
789 # do not replace current widget when self.selected_widget != None
3004
d86cddc1cd05 primitivus: select the widget even if an other one is selected when the selection comes from an user action:
Goffi <goffi@goffi.org>
parents: 3001
diff changeset
790 if user_action or self.selected_widget is None:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
791 self.select_widget(widget)
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
792
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
793 def select_widget(self, widget):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
794 """Display a widget if possible,
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
795
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
796 else add it in the notification bar queue
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
797 @param widget: BoxWidget
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
798 """
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
799 assert len(self.center_part.widget_list) <= 2
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
800 wid_idx = len(self.center_part.widget_list) - 1
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
801 self.center_part.widget_list[wid_idx] = widget
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
802 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
803 self.menu_roller.remove_menu(C.MENU_ID_WIDGET)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
804 except KeyError:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
805 log.debug("No menu to delete")
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
806 self.selected_widget = widget
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
807 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
808 on_selected = self.selected_widget.on_selected
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
809 except AttributeError:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
810 pass
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
811 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
812 on_selected()
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
813 self._visible_widgets = set(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
814 [widget]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
815 ) # XXX: we can only have one widget visible at the time for now
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
816 self.contact_lists.select(None)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
817
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
818 for (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
819 wid
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
820 ) in (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
821 self.visible_widgets
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
822 ): # FIXME: check if widgets.get_widgets is not more appropriate
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
823 if isinstance(wid, Chat):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
824 contact_list = self.contact_lists[wid.profile]
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
825 contact_list.select(wid.target)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
826
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
827 self.redraw()
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
828
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
829 def remove_window(self):
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
830 """Remove window showed on the right column"""
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
831 # TODO: better Window management than this hack
1336
2ecc07a8f91b primitivus, quick_frontends: moved newMessage signal handler to quick_frontend
Goffi <goffi@goffi.org>
parents: 1290
diff changeset
832 assert len(self.center_part.widget_list) <= 2
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
833 wid_idx = len(self.center_part.widget_list) - 1
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
834 self.center_part.widget_list[wid_idx] = urwid.Filler(urwid.Text(""))
911
b12706d164d7 primitivus: removed deprecated use of set_focus
Goffi <goffi@goffi.org>
parents: 907
diff changeset
835 self.center_part.focus_position = 0
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
836 self.redraw()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
837
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
838 def add_progress(self, pid, message, profile):
1636
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1632
diff changeset
839 """Follow a SàT progression
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1632
diff changeset
840
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1632
diff changeset
841 @param pid: progression id
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1632
diff changeset
842 @param message: message to show to identify the progression
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1632
diff changeset
843 """
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1632
diff changeset
844 self.progress_wid.add(pid, message, profile)
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
845
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
846 def set_progress(self, percentage):
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
847 """Set the progression shown in notification bar"""
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
848 self.notif_bar.set_progress(percentage)
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
849
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
850 def contact_selected(self, contact_list, entity):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
851 self.clear_notifs(entity, profile=contact_list.profile)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
852 if entity.resource:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
853 # we have clicked on a private MUC conversation
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
854 chat_widget = self.widgets.get_or_create_widget(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
855 Chat,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
856 entity,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
857 on_new_widget=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
858 force_hash=Chat.get_private_hash(contact_list.profile, entity),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
859 profile=contact_list.profile,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
860 )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
861 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
862 chat_widget = self.widgets.get_or_create_widget(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
863 Chat, entity, on_new_widget=None, profile=contact_list.profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
864 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
865 self.select_widget(chat_widget)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
866 self.menu_roller.add_menu(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
867 _("Chat menu"), chat_widget.get_menu(), C.MENU_ID_WIDGET
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
868 )
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
869
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
870 def _dialog_ok_cb(self, widget, data):
1582
a41cc0849008 primitivus: partly reverted commit 641cfd2faefe :
Goffi <goffi@goffi.org>
parents: 1580
diff changeset
871 popup, answer_cb, answer_data = data
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
872 self.remove_pop_up(popup)
1612
48f324352c52 primitivus: fixed showDialog and XMLUI message dialog
Goffi <goffi@goffi.org>
parents: 1609
diff changeset
873 if answer_cb is not None:
48f324352c52 primitivus: fixed showDialog and XMLUI message dialog
Goffi <goffi@goffi.org>
parents: 1609
diff changeset
874 answer_cb(True, answer_data)
182
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 181
diff changeset
875
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
876 def _dialog_cancel_cb(self, widget, data):
1582
a41cc0849008 primitivus: partly reverted commit 641cfd2faefe :
Goffi <goffi@goffi.org>
parents: 1580
diff changeset
877 popup, answer_cb, answer_data = data
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
878 self.remove_pop_up(popup)
1612
48f324352c52 primitivus: fixed showDialog and XMLUI message dialog
Goffi <goffi@goffi.org>
parents: 1609
diff changeset
879 if answer_cb is not None:
48f324352c52 primitivus: fixed showDialog and XMLUI message dialog
Goffi <goffi@goffi.org>
parents: 1609
diff changeset
880 answer_cb(False, answer_data)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
881
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
882 def show_dialog(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
883 self, message, title="", type="info", answer_cb=None, answer_data=None
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
884 ):
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
885 if type == "info":
1632
4f9fa67758eb primitivus: fixed showDialog
Goffi <goffi@goffi.org>
parents: 1612
diff changeset
886 popup = sat_widgets.Alert(title, message, ok_cb=answer_cb)
1582
a41cc0849008 primitivus: partly reverted commit 641cfd2faefe :
Goffi <goffi@goffi.org>
parents: 1580
diff changeset
887 if answer_cb is None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
888 popup.set_callback("ok", lambda dummy: self.remove_pop_up(popup))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
889 elif type == "error":
1632
4f9fa67758eb primitivus: fixed showDialog
Goffi <goffi@goffi.org>
parents: 1612
diff changeset
890 popup = sat_widgets.Alert(title, message, ok_cb=answer_cb)
1582
a41cc0849008 primitivus: partly reverted commit 641cfd2faefe :
Goffi <goffi@goffi.org>
parents: 1580
diff changeset
891 if answer_cb is None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
892 popup.set_callback("ok", lambda dummy: self.remove_pop_up(popup))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
893 elif type == "yes/no":
1612
48f324352c52 primitivus: fixed showDialog and XMLUI message dialog
Goffi <goffi@goffi.org>
parents: 1609
diff changeset
894 popup = sat_widgets.ConfirmDialog(message)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
895 popup.set_callback("yes", self._dialog_ok_cb, (popup, answer_cb, answer_data))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
896 popup.set_callback(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
897 "no", self._dialog_cancel_cb, (popup, answer_cb, answer_data)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
898 )
1582
a41cc0849008 primitivus: partly reverted commit 641cfd2faefe :
Goffi <goffi@goffi.org>
parents: 1580
diff changeset
899 else:
1632
4f9fa67758eb primitivus: fixed showDialog
Goffi <goffi@goffi.org>
parents: 1612
diff changeset
900 popup = sat_widgets.Alert(title, message, ok_cb=answer_cb)
1582
a41cc0849008 primitivus: partly reverted commit 641cfd2faefe :
Goffi <goffi@goffi.org>
parents: 1580
diff changeset
901 if answer_cb is None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
902 popup.set_callback("ok", lambda dummy: self.remove_pop_up(popup))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
903 log.error("unmanaged dialog type: {}".format(type))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
904 self.show_pop_up(popup)
1582
a41cc0849008 primitivus: partly reverted commit 641cfd2faefe :
Goffi <goffi@goffi.org>
parents: 1580
diff changeset
905
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
906 def dialog_failure(self, failure):
1468
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1434
diff changeset
907 """Show a failure that has been returned by an asynchronous bridge method.
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1434
diff changeset
908
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1434
diff changeset
909 @param failure (defer.Failure): Failure instance
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1434
diff changeset
910 """
1609
66f0e877625b primitivus: fixed alert case + alert in profileManager
Goffi <goffi@goffi.org>
parents: 1582
diff changeset
911 self.alert(failure.classname, failure.message)
1468
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1434
diff changeset
912
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
913 def on_notification(self, notif_bar):
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
914 """Called when a new notification has been received"""
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
915 if not isinstance(self.main_widget, LiberviaTUITopWidget):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
916 # if we are not in the main configuration, we ignore the notifications bar
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
917 return
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
918 if self.notif_bar.can_hide():
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
919 # No notification left, we can hide the bar
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
920 self.main_widget.hide("notif_bar")
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
921 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
922 self.main_widget.show("notif_bar")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
923 self.redraw() # FIXME: invalidate cache in a more efficient way
159
2fa58703f1b7 Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents: 157
diff changeset
924
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
925 def _action_manager_unknown_error(self):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
926 self.alert(_("Error"), _("Unmanaged action"))
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
927
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
928 def room_joined_handler(self, room_jid_s, room_nicks, user_nick, subject, profile):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
929 super(LiberviaTUIApp, self).room_joined_handler(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
930 room_jid_s, room_nicks, user_nick, subject, profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
931 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
932 # if self.selected_widget is None:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
933 # for contact_list in self.widgets.get_widgets(ContactList):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
934 # if profile in contact_list.profiles:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
935 # contact_list.set_focus(jid.JID(room_jid_s), True)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
936
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
937 def progress_started_handler(self, pid, metadata, profile):
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
938 super(LiberviaTUIApp, self).progress_started_handler(pid, metadata, profile)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
939 self.add_progress(pid, metadata.get("name", _("unkown")), profile)
1636
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1632
diff changeset
940
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
941 def progress_finished_handler(self, pid, metadata, profile):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
942 log.info("Progress {} finished".format(pid))
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
943 super(LiberviaTUIApp, self).progress_finished_handler(pid, metadata, profile)
1636
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1632
diff changeset
944
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
945 def progress_error_handler(self, pid, err_msg, profile):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
946 log.warning("Progress {pid} error: {err_msg}".format(pid=pid, err_msg=err_msg))
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
947 super(LiberviaTUIApp, self).progress_error_handler(pid, err_msg, profile)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
948
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 145
diff changeset
949 ##DIALOGS CALLBACKS##
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
950 def on_join_room(self, button, edit):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
951 self.remove_pop_up()
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
952 room_jid = jid.JID(edit.get_edit_text())
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
953 self.bridge.muc_join(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
954 room_jid,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
955 self.profiles[self.current_profile].whoami.node,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
956 {},
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
957 self.current_profile,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
958 callback=lambda dummy: None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
959 errback=self.dialog_failure,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
960 )
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
961
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
962 # MENU EVENTS#
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
963 def on_connect_request(self, menu):
2142
be96beb7ca14 core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
Goffi <goffi@goffi.org>
parents: 2134
diff changeset
964 QuickApp.connect(self, self.current_profile)
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
965
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
966 def on_disconnect_request(self, menu):
1348
a39d2db03c80 frontends: add listeners 'profilePlugged', 'disconnect' and 'gotMenus' (the last one to be removed when the menus are refactored to quick_app)
souliane <souliane@mailoo.org>
parents: 1337
diff changeset
967 self.disconnect(self.current_profile)
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
968
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
969 def on_param(self, menu):
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 422
diff changeset
970 def success(params):
1353
361b0fe72961 frontends (primitivus): assign the current profile to the parameters dialog
souliane <souliane@mailoo.org>
parents: 1350
diff changeset
971 ui = xmlui.create(self, xml_data=params, profile=self.current_profile)
1185
6184779544c7 Primitivus (xmlui): fixed window closing on save params + removed now unused onConfigureRoom in Chat
Goffi <goffi@goffi.org>
parents: 1181
diff changeset
972 ui.show()
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 776
diff changeset
973
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 422
diff changeset
974 def failure(error):
1609
66f0e877625b primitivus: fixed alert case + alert in profileManager
Goffi <goffi@goffi.org>
parents: 1582
diff changeset
975 self.alert(_("Error"), _("Can't get parameters (%s)") % error)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
976
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
977 self.bridge.param_ui_get(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
978 app=C.APP_NAME,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
979 profile_key=self.current_profile,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
980 callback=success,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
981 errback=failure,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
982 )
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 159
diff changeset
983
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
984 def on_exit_request(self, menu):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
985 QuickApp.on_exit(self)
1949
c5fd304d0976 primitivus: added bracketed_paste option in sat.conf (if set, the bracketed paste mode will be activated on Primitivus start)
Goffi <goffi@goffi.org>
parents: 1948
diff changeset
986 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
987 if (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
988 self._bracketed_mode_set
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
989 ): # we don't unset if bracketed paste mode was detected automatically (i.e. not in conf)
1949
c5fd304d0976 primitivus: added bracketed_paste option in sat.conf (if set, the bracketed paste mode will be activated on Primitivus start)
Goffi <goffi@goffi.org>
parents: 1948
diff changeset
990 log.debug("unsetting bracketed paste mode")
c5fd304d0976 primitivus: added bracketed_paste option in sat.conf (if set, the bracketed paste mode will be activated on Primitivus start)
Goffi <goffi@goffi.org>
parents: 1948
diff changeset
991 sys.stdout.write("\033[?2004l")
c5fd304d0976 primitivus: added bracketed_paste option in sat.conf (if set, the bracketed paste mode will be activated on Primitivus start)
Goffi <goffi@goffi.org>
parents: 1948
diff changeset
992 except AttributeError:
c5fd304d0976 primitivus: added bracketed_paste option in sat.conf (if set, the bracketed paste mode will be activated on Primitivus start)
Goffi <goffi@goffi.org>
parents: 1948
diff changeset
993 pass
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
994 raise urwid.ExitMainLoop()
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
995
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
996 def on_join_room_request(self, menu):
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
997 """User wants to join a MUC room"""
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
998 pop_up_widget = sat_widgets.InputDialog(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
999 _("Entering a MUC room"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
1000 _("Please enter MUC's JID"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
1001 default_txt=self.bridge.muc_get_default_service(),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
1002 ok_cb=self.on_join_room,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
1003 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
1004 pop_up_widget.set_callback(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
1005 "cancel", lambda dummy: self.remove_pop_up(pop_up_widget)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
1006 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
1007 self.show_pop_up(pop_up_widget)
131
6cad483a6d84 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 129
diff changeset
1008
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
1009 def on_about_request(self, menu):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
1010 self.alert(_("About"), C.APP_NAME + " v" + self.bridge.version_get())
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1011
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
1012 # MISC CALLBACKS#
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents: 168
diff changeset
1013
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
1014 def set_presence_status(self, show="", status=None, profile=C.PROF_KEY_NONE):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
1015 contact_list_wid = self.widgets.get_widget(ContactList, profiles=profile)
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1016 if contact_list_wid is not None:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3494
diff changeset
1017 contact_list_wid.status_bar.set_presence_status(show, status)
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1018 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
1019 log.warning("No ContactList widget found for profile {}".format(profile))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
1020
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
1021
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4079
diff changeset
1022 if __name__ == "__main__":
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
1023 LiberviaTUIApp().start()