Mercurial > libervia-backend
annotate libervia/tui/profile_manager.py @ 4326:5fd6a4dc2122
cli (output/std): use `rich` to output JSON.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 20 Nov 2024 11:38:44 +0100 |
parents | b620a8e882e1 |
children |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
112 | 3 |
4076
b620a8e882e1
refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
4 # Libervia TUI |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
112 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
10 # (at your option) any later version. |
112 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
15 # GNU Affero General Public License for more details. |
112 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
112 | 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 _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
21 from libervia.backend.core import log as logging |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
22 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
23 log = logging.getLogger(__name__) |
4074
26b7ed2817da
refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
24 from libervia.frontends.quick_frontend.quick_profile_manager import QuickProfileManager |
4076
b620a8e882e1
refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
25 from libervia.tui.constants import Const as C |
b620a8e882e1
refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
26 from libervia.tui.keys import action_key_map as a_key |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
27 from urwid_satext import sat_widgets |
112 | 28 import urwid |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
29 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
30 |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
31 class ProfileManager(QuickProfileManager, urwid.WidgetWrap): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
32 def __init__(self, host, autoconnect=None): |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
33 QuickProfileManager.__init__(self, host, autoconnect) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
34 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
35 # login & password box must be created before list because of on_profile_change |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
36 self.login_wid = sat_widgets.AdvancedEdit(_("Login:"), align="center") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
37 self.pass_wid = sat_widgets.Password(_("Password:"), align="center") |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
38 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
39 style = ["no_first_select"] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
40 profiles = host.bridge.profiles_list_get() |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
41 profiles.sort() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
42 self.list_profile = sat_widgets.List( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
43 profiles, style=style, align="center", on_change=self.on_profile_change |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
44 ) |
113 | 45 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
46 # new & delete buttons |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
47 buttons = [ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
48 urwid.Button(_("New"), self.on_new_profile), |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
49 urwid.Button(_("Delete"), self.on_delete_profile), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
50 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
51 buttons_flow = urwid.GridFlow( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
52 buttons, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
53 max([len(button.get_label()) for button in buttons]) + 4, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
54 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
56 "center", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
57 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
58 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
59 # second part: login information: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
60 divider = urwid.Divider("-") |
113 | 61 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
62 # connect button |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
63 connect_button = sat_widgets.CustomButton( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
64 _("Connect"), self.on_connect_profiles, align="center" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
65 ) |
113 | 66 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
67 # we now build the widget |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 list_walker = urwid.SimpleFocusListWalker( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
69 [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 buttons_flow, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 self.list_profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
72 divider, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 self.login_wid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
74 self.pass_wid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
75 connect_button, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
76 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
77 ) |
1178
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
78 frame_body = urwid.ListBox(list_walker) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
79 frame = urwid.Frame( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
80 frame_body, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
81 urwid.AttrMap(urwid.Text(_("Profile Manager"), align="center"), "title"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
82 ) |
113 | 83 self.main_widget = urwid.LineBox(frame) |
84 urwid.WidgetWrap.__init__(self, self.main_widget) | |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
85 |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
86 self.go(autoconnect) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
87 |
1161
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
88 def keypress(self, size, key): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
89 if key == a_key["APP_QUIT"]: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
90 self.host.on_exit() |
1161
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
91 raise urwid.ExitMainLoop() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
92 elif key in (a_key["FOCUS_UP"], a_key["FOCUS_DOWN"]): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
93 focus_diff = 1 if key == a_key["FOCUS_DOWN"] else -1 |
1178
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
94 list_box = self.main_widget.base_widget.body |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
95 current_focus = list_box.body.get_focus()[1] |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
96 if current_focus is None: |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
97 return |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
98 while True: |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
99 current_focus += focus_diff |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
100 if current_focus < 0 or current_focus >= len(list_box.body): |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
101 break |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
102 if list_box.body[current_focus].selectable(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
103 list_box.set_focus( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
104 current_focus, "above" if focus_diff == 1 else "below" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 ) |
1178
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
106 list_box._invalidate() |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
107 return |
1161
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
108 return super(ProfileManager, self).keypress(size, key) |
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
109 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
110 def cancel_dialog(self, button): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
111 self.host.remove_pop_up() |
113 | 112 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
113 def new_profile(self, button, edit): |
217 | 114 """Create the profile""" |
113 | 115 name = edit.get_edit_text() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
116 self.host.bridge.profile_create( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
117 name, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
118 callback=lambda: self.new_profile_created(name), |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
119 errback=self.profile_creation_failure, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
120 ) |
421
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
121 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
122 def new_profile_created(self, profile): |
1698
7923dc51143e
primitivus (profile manager): session is started for newly create profiles
Goffi <goffi@goffi.org>
parents:
1609
diff
changeset
|
123 # new profile will be selected, and a selected profile assume the session is started |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
124 self.host.bridge.profile_start_session( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
125 "", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
126 profile, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
127 callback=lambda __: self.new_profile_session_started(profile), |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
128 errback=self.profile_creation_failure, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
129 ) |
1698
7923dc51143e
primitivus (profile manager): session is started for newly create profiles
Goffi <goffi@goffi.org>
parents:
1609
diff
changeset
|
130 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
131 def new_profile_session_started(self, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
132 self.host.remove_pop_up() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
133 self.refill_profiles() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
134 self.list_profile.select_value(profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
135 self.current.profile = profile |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
136 self.get_connection_params(profile) |
421
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
137 self.host.redraw() |
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
138 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
139 def profile_creation_failure(self, reason): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
140 self.host.remove_pop_up() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
141 message = self._get_error_message(reason) |
1609
66f0e877625b
primitivus: fixed alert case + alert in profileManager
Goffi <goffi@goffi.org>
parents:
1489
diff
changeset
|
142 self.host.alert(_("Can't create profile"), message) |
113 | 143 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
144 def delete_profile(self, button): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
145 self._delete_profile() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
146 self.host.remove_pop_up() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
147 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
148 def on_new_profile(self, e): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 pop_up_widget = sat_widgets.InputDialog( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
150 _("New profile"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
151 _("Please enter a new profile name"), |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
152 cancel_cb=self.cancel_dialog, |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
153 ok_cb=self.new_profile, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
154 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
155 self.host.show_pop_up(pop_up_widget) |
113 | 156 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
157 def on_delete_profile(self, e): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
158 if self.current.profile: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
159 pop_up_widget = sat_widgets.ConfirmDialog( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
160 _("Are you sure you want to delete the profile {} ?").format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
161 self.current.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
162 ), |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
163 no_cb=self.cancel_dialog, |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
164 yes_cb=self.delete_profile, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
165 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
166 self.host.show_pop_up(pop_up_widget) |
113 | 167 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
168 def on_connect_profiles(self, button): |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
169 """Connect the profiles and start the main widget |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
170 |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
171 @param button: the connect button |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
172 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
173 self._on_connect_profiles() |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
174 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
175 def reset_fields(self): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
176 """Set profile to None, and reset fields""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
177 super(ProfileManager, self).reset_fields() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
178 self.list_profile.unselect_all(invisible=True) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
179 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
180 def set_profiles(self, profiles): |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
181 """Update the list of profiles""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
182 self.list_profile.change_values(profiles) |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
183 self.host.redraw() |
1034
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
184 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
185 def get_profiles(self): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
186 return self.list_profile.get_selected_values() |
1019 | 187 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
188 def get_jid(self): |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
189 return self.login_wid.get_edit_text() |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
190 |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
191 def getPassword(self): |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
192 return self.pass_wid.get_edit_text() |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
193 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
194 def set_jid(self, jid_): |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
195 self.login_wid.set_edit_text(jid_) |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
196 self.current.login = jid_ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
197 self.host.redraw() # FIXME: redraw should be avoided |
1034
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
198 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
199 def set_password(self, password): |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
200 self.pass_wid.set_edit_text(password) |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
201 self.current.password = password |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
202 self.host.redraw() |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
203 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
204 def on_profile_change(self, list_wid, widget=None, selected=None): |
1034
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
205 """This is called when a profile is selected in the profile list. |
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
206 |
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
207 @param list_wid: the List widget who sent the event |
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
208 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
209 self.update_connection_params() |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
210 focused = list_wid.focus |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
211 selected = focused.get_state() if focused is not None else False |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
212 if not selected: # profile was just unselected |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
213 return |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
214 focused.set_state( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
215 False, invisible=True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
216 ) # we don't want the widget to be selected until we are sure we can access it |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
217 |
1489
039d96e131be
frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents:
1488
diff
changeset
|
218 def authenticate_cb(data, cb_id, profile): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
219 if C.bool(data.pop("validated", C.BOOL_FALSE)): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
220 self.current.profile = profile |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
221 focused.set_state(True, invisible=True) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
222 self.get_connection_params(profile) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
223 self.host.redraw() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
224 self.host.action_manager(data, callback=authenticate_cb, profile=profile) |
1489
039d96e131be
frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents:
1488
diff
changeset
|
225 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
226 self.host.action_launch( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
227 C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=focused.text |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
228 ) |