Mercurial > libervia-backend
annotate libervia/frontends/quick_frontend/quick_widgets.py @ 4322:00837fa13e5a default tip @
tools (common/template), cli (call/gui): use font-awesome instead of fontello:
following change in Libervia Media, code has been updated to use font-awesome now instead
of fontello.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 26 Oct 2024 22:42:17 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
0 | 3 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
4 # helper class for making a SAT frontend |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
0 | 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. |
0 | 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. |
0 | 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/>. |
0 | 19 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
20 from libervia.backend.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
21 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
22 log = getLogger(__name__) |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
23 from libervia.backend.core import exceptions |
4074
26b7ed2817da
refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
24 from libervia.frontends.quick_frontend.constants import Const as C |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
25 |
2039
6353deb1bd73
quick frontend (quick_widget): getWidgets can now filter on hash (using target), handling recreated widgets too
Goffi <goffi@goffi.org>
parents:
2027
diff
changeset
|
26 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
27 classes_map = {} |
0 | 28 |
29 | |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
30 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
31 # FIXME: to be removed when an acceptable solution is here |
3028 | 32 str("") # XXX: unicode doesn't exist in pyjamas |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
33 except ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
34 TypeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
35 AttributeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
36 ): # Error raised is not the same depending on pyjsbuild options |
3028 | 37 str = str |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
38 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
39 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
40 def register(base_cls, child_cls=None): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
41 """Register a child class to use by default when a base class is needed |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
42 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
43 @param base_cls: "Quick..." base class (like QuickChat or QuickContact), must inherit from QuickWidget |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
44 @param child_cls: inherited class to use when Quick... class is requested, must inherit from base_cls. |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
45 Can be None if it's the base_cls itself which register |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
46 """ |
1304
1a61b18703c4
quick frontend (quick widgets): class' __name__ method is used for classes_map hash because the use of class directly was causing bugs with pyjamas (difficult to find, several MicroblogPanel instances were added only once in Libervia's TabPanel, hash method seemed buggy)
Goffi <goffi@goffi.org>
parents:
1303
diff
changeset
|
47 # FIXME: we use base_cls.__name__ instead of base_cls directly because pyjamas because |
1a61b18703c4
quick frontend (quick widgets): class' __name__ method is used for classes_map hash because the use of class directly was causing bugs with pyjamas (difficult to find, several MicroblogPanel instances were added only once in Libervia's TabPanel, hash method seemed buggy)
Goffi <goffi@goffi.org>
parents:
1303
diff
changeset
|
48 # in the second case |
1a61b18703c4
quick frontend (quick widgets): class' __name__ method is used for classes_map hash because the use of class directly was causing bugs with pyjamas (difficult to find, several MicroblogPanel instances were added only once in Libervia's TabPanel, hash method seemed buggy)
Goffi <goffi@goffi.org>
parents:
1303
diff
changeset
|
49 classes_map[base_cls.__name__] = child_cls |
1a61b18703c4
quick frontend (quick widgets): class' __name__ method is used for classes_map hash because the use of class directly was causing bugs with pyjamas (difficult to find, several MicroblogPanel instances were added only once in Libervia's TabPanel, hash method seemed buggy)
Goffi <goffi@goffi.org>
parents:
1303
diff
changeset
|
50 |
1a61b18703c4
quick frontend (quick widgets): class' __name__ method is used for classes_map hash because the use of class directly was causing bugs with pyjamas (difficult to find, several MicroblogPanel instances were added only once in Libervia's TabPanel, hash method seemed buggy)
Goffi <goffi@goffi.org>
parents:
1303
diff
changeset
|
51 |
1301
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
52 class WidgetAlreadyExistsError(Exception): |
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
53 pass |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
54 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
55 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
56 class QuickWidgetsManager(object): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
57 """This class is used to manage all the widgets of a frontend |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
58 A widget can be a window, a graphical thing, or someting else depending of the frontend |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
59 """ |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
60 |
0 | 61 def __init__(self, host): |
62 self.host = host | |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
63 self._widgets = {} |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
64 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
65 def __iter__(self): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
66 """Iterate throught all widgets""" |
3028 | 67 for widget_map in self._widgets.values(): |
68 for widget_instances in widget_map.values(): | |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
69 for widget in widget_instances: |
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
70 yield widget |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
71 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
72 def get_real_class(self, class_): |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
73 """Return class registered for given class_ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
74 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
75 @param class_: subclass of QuickWidget |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
76 @return: class actually used to create widget |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
77 """ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
78 try: |
1304
1a61b18703c4
quick frontend (quick widgets): class' __name__ method is used for classes_map hash because the use of class directly was causing bugs with pyjamas (difficult to find, several MicroblogPanel instances were added only once in Libervia's TabPanel, hash method seemed buggy)
Goffi <goffi@goffi.org>
parents:
1303
diff
changeset
|
79 # FIXME: we use base_cls.__name__ instead of base_cls directly because pyjamas bugs |
1a61b18703c4
quick frontend (quick widgets): class' __name__ method is used for classes_map hash because the use of class directly was causing bugs with pyjamas (difficult to find, several MicroblogPanel instances were added only once in Libervia's TabPanel, hash method seemed buggy)
Goffi <goffi@goffi.org>
parents:
1303
diff
changeset
|
80 # in the second case |
1a61b18703c4
quick frontend (quick widgets): class' __name__ method is used for classes_map hash because the use of class directly was causing bugs with pyjamas (difficult to find, several MicroblogPanel instances were added only once in Libervia's TabPanel, hash method seemed buggy)
Goffi <goffi@goffi.org>
parents:
1303
diff
changeset
|
81 cls = classes_map[class_.__name__] |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
82 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
83 cls = class_ |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
84 if cls is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
85 raise exceptions.InternalError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
86 "There is not class registered for {}".format(class_) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
87 ) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
88 return cls |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
89 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
90 def get_widget_instances(self, widget): |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
91 """Get all instance of a widget |
2039
6353deb1bd73
quick frontend (quick_widget): getWidgets can now filter on hash (using target), handling recreated widgets too
Goffi <goffi@goffi.org>
parents:
2027
diff
changeset
|
92 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
93 This is a helper method which call get_widgets |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
94 @param widget(QuickWidget): retrieve instances of this widget |
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
95 @return: iterator on widgets |
2039
6353deb1bd73
quick frontend (quick_widget): getWidgets can now filter on hash (using target), handling recreated widgets too
Goffi <goffi@goffi.org>
parents:
2027
diff
changeset
|
96 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
97 return self.get_widgets(widget.__class__, widget.target, widget.profiles) |
2039
6353deb1bd73
quick frontend (quick_widget): getWidgets can now filter on hash (using target), handling recreated widgets too
Goffi <goffi@goffi.org>
parents:
2027
diff
changeset
|
98 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
99 def get_widgets(self, class_, target=None, profiles=None, with_duplicates=True): |
2007
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1995
diff
changeset
|
100 """Get all subclassed widgets instances |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
101 |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
102 @param class_: subclass of QuickWidget, same parameter as used in |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
103 [get_or_create_widget] |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
104 @param target: if not None, construct a hash with this target and filter |
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
105 corresponding widgets |
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
106 recreated widgets are handled |
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
107 @param profiles(iterable, None): if not None, filter on instances linked to these |
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
108 profiles |
3165
7699a08ba8fb
quick frontend(widget): added `with_duplicates` argument to getWidgets:
Goffi <goffi@goffi.org>
parents:
3159
diff
changeset
|
109 @param with_duplicates(bool): if False, only first widget with a given hash is |
7699a08ba8fb
quick frontend(widget): added `with_duplicates` argument to getWidgets:
Goffi <goffi@goffi.org>
parents:
3159
diff
changeset
|
110 returned |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
111 @return: iterator on widgets |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
112 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
113 class_ = self.get_real_class(class_) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
114 try: |
1304
1a61b18703c4
quick frontend (quick widgets): class' __name__ method is used for classes_map hash because the use of class directly was causing bugs with pyjamas (difficult to find, several MicroblogPanel instances were added only once in Libervia's TabPanel, hash method seemed buggy)
Goffi <goffi@goffi.org>
parents:
1303
diff
changeset
|
115 widgets_map = self._widgets[class_.__name__] |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
116 except KeyError: |
2007
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1995
diff
changeset
|
117 return |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
118 else: |
2039
6353deb1bd73
quick frontend (quick_widget): getWidgets can now filter on hash (using target), handling recreated widgets too
Goffi <goffi@goffi.org>
parents:
2027
diff
changeset
|
119 if target is not None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
120 filter_hash = str(class_.get_widget_hash(target, profiles)) |
2039
6353deb1bd73
quick frontend (quick_widget): getWidgets can now filter on hash (using target), handling recreated widgets too
Goffi <goffi@goffi.org>
parents:
2027
diff
changeset
|
121 else: |
6353deb1bd73
quick frontend (quick_widget): getWidgets can now filter on hash (using target), handling recreated widgets too
Goffi <goffi@goffi.org>
parents:
2027
diff
changeset
|
122 filter_hash = None |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
123 if filter_hash is not None: |
2888
e3803ae89fbc
quick_frontend (widgets): fixed crash on getWidgets when target doesn't correspond to any widget
Goffi <goffi@goffi.org>
parents:
2855
diff
changeset
|
124 for widget in widgets_map.get(filter_hash, []): |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
125 yield widget |
3165
7699a08ba8fb
quick frontend(widget): added `with_duplicates` argument to getWidgets:
Goffi <goffi@goffi.org>
parents:
3159
diff
changeset
|
126 if not with_duplicates: |
7699a08ba8fb
quick frontend(widget): added `with_duplicates` argument to getWidgets:
Goffi <goffi@goffi.org>
parents:
3159
diff
changeset
|
127 return |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
128 else: |
3028 | 129 for widget_instances in widgets_map.values(): |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
130 for widget in widget_instances: |
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
131 yield widget |
3165
7699a08ba8fb
quick frontend(widget): added `with_duplicates` argument to getWidgets:
Goffi <goffi@goffi.org>
parents:
3159
diff
changeset
|
132 if not with_duplicates: |
7699a08ba8fb
quick frontend(widget): added `with_duplicates` argument to getWidgets:
Goffi <goffi@goffi.org>
parents:
3159
diff
changeset
|
133 # widgets are set by hashes, so if don't want duplicates |
7699a08ba8fb
quick frontend(widget): added `with_duplicates` argument to getWidgets:
Goffi <goffi@goffi.org>
parents:
3159
diff
changeset
|
134 # we only return the first widget of the list |
7699a08ba8fb
quick frontend(widget): added `with_duplicates` argument to getWidgets:
Goffi <goffi@goffi.org>
parents:
3159
diff
changeset
|
135 break |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
136 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
137 def get_widget(self, class_, target=None, profiles=None): |
1349
273b044fde6d
quick_frontend: add a method getWidget to return a widget without creating it if it doesn't exist
souliane <souliane@mailoo.org>
parents:
1322
diff
changeset
|
138 """Get a widget without creating it if it doesn't exist. |
273b044fde6d
quick_frontend: add a method getWidget to return a widget without creating it if it doesn't exist
souliane <souliane@mailoo.org>
parents:
1322
diff
changeset
|
139 |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
140 if several instances of widgets with this hash exist, the first one is returned |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
141 @param class_: subclass of QuickWidget, same parameter as used in [get_or_create_widget] |
1349
273b044fde6d
quick_frontend: add a method getWidget to return a widget without creating it if it doesn't exist
souliane <souliane@mailoo.org>
parents:
1322
diff
changeset
|
142 @param target: target depending of the widget, usually a JID instance |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
143 @param profiles (unicode, iterable[unicode], None): profile(s) to use (may or may not be |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
144 used, depending of the widget class) |
1349
273b044fde6d
quick_frontend: add a method getWidget to return a widget without creating it if it doesn't exist
souliane <souliane@mailoo.org>
parents:
1322
diff
changeset
|
145 @return: a class_ instance or None if the widget doesn't exist |
273b044fde6d
quick_frontend: add a method getWidget to return a widget without creating it if it doesn't exist
souliane <souliane@mailoo.org>
parents:
1322
diff
changeset
|
146 """ |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
147 assert (target is not None) or (profiles is not None) |
3028 | 148 if profiles is not None and isinstance(profiles, str): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
149 profiles = [profiles] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
150 class_ = self.get_real_class(class_) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
151 hash_ = class_.get_widget_hash(target, profiles) |
1349
273b044fde6d
quick_frontend: add a method getWidget to return a widget without creating it if it doesn't exist
souliane <souliane@mailoo.org>
parents:
1322
diff
changeset
|
152 try: |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
153 return self._widgets[class_.__name__][hash_][0] |
1349
273b044fde6d
quick_frontend: add a method getWidget to return a widget without creating it if it doesn't exist
souliane <souliane@mailoo.org>
parents:
1322
diff
changeset
|
154 except KeyError: |
273b044fde6d
quick_frontend: add a method getWidget to return a widget without creating it if it doesn't exist
souliane <souliane@mailoo.org>
parents:
1322
diff
changeset
|
155 return None |
273b044fde6d
quick_frontend: add a method getWidget to return a widget without creating it if it doesn't exist
souliane <souliane@mailoo.org>
parents:
1322
diff
changeset
|
156 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
157 def get_or_create_widget(self, class_, target, *args, **kwargs): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
158 """Get an existing widget or create a new one when necessary |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
159 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
160 If the widget is new, self.host.new_widget will be called with it. |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
161 @param class_(class): class of the widget to create |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
162 @param target: target depending of the widget, usually a JID instance |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
163 @param args(list): optional args to create a new instance of class_ |
1312
9e904f8a094e
quick_frontend: getOrCreateWidget callbacks can return another widget
souliane <souliane@mailoo.org>
parents:
1310
diff
changeset
|
164 @param kwargs(dict): optional kwargs to create a new instance of class_ |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
165 if 'profile' key is present, it will be popped and put in 'profiles' |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
166 if there is neither 'profile' nor 'profiles', None will be used for 'profiles' |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
167 if 'on_new_widget' is present it can have the following values: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
168 C.WIDGET_NEW [default]: self.host.new_widget will be called on widget creation |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
169 [callable]: this method will be called instead of self.host.new_widget |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
170 None: do nothing |
1301
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
171 if 'on_existing_widget' is present it can have the following values: |
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
172 C.WIDGET_KEEP [default]: return the existing widget |
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
173 C.WIDGET_RAISE: raise WidgetAlreadyExistsError |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
174 C.WIDGET_RECREATE: create a new widget |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
175 if the existing widget has a "recreate_args" method, it will be called with args list and kwargs dict |
2062
e22ab34c68f6
quick fronten (widgets): if a widget is recreated, "recreateArgs" method can be implemented to specify arguments to clone it correctly
Goffi <goffi@goffi.org>
parents:
2047
diff
changeset
|
176 so the values can be completed to create correctly the new instance |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
177 [callable]: this method will be called with existing widget as argument, the widget to use must be returned |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
178 if 'force_hash' is present, the hash given in value will be used instead of the one returned by class_.get_widget_hash |
1307
9512590dc3d7
quick_ frontend (quick widgets): added explanation in docstring for non special keywords in getOrCreateWidget
Goffi <goffi@goffi.org>
parents:
1304
diff
changeset
|
179 other keys will be used to instanciate class_ if the case happen (e.g. if type_ is present and class_ is a QuickChat subclass, |
9512590dc3d7
quick_ frontend (quick widgets): added explanation in docstring for non special keywords in getOrCreateWidget
Goffi <goffi@goffi.org>
parents:
1304
diff
changeset
|
180 it will be used to create a new QuickChat instance). |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
181 @return: a class_ instance, either new or already existing |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
182 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
183 cls = self.get_real_class(class_) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
184 |
1301
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
185 ## arguments management ## |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
186 _args = [self.host, target] + list( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
187 args |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
188 ) or [] # FIXME: check if it's really necessary to use optional args |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
189 _kwargs = kwargs or {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
190 if "profiles" in _kwargs and "profile" in _kwargs: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
191 raise ValueError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
192 "You can't have 'profile' and 'profiles' keys at the same time" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
193 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
194 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
195 _kwargs["profiles"] = [_kwargs.pop("profile")] |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
196 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
197 if not "profiles" in _kwargs: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
198 _kwargs["profiles"] = None |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
199 |
2792
441b536e28ed
quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
200 # on_new_widget tells what to do for the new widget creation |
1301
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
201 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
202 on_new_widget = _kwargs.pop("on_new_widget") |
1301
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
203 except KeyError: |
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
204 on_new_widget = C.WIDGET_NEW |
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
205 |
2792
441b536e28ed
quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
206 # on_existing_widget tells what to do when the widget already exists |
1301
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
207 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
208 on_existing_widget = _kwargs.pop("on_existing_widget") |
1301
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
209 except KeyError: |
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
210 on_existing_widget = C.WIDGET_KEEP |
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
211 |
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
212 ## we get the hash ## |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
213 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
214 hash_ = _kwargs.pop("force_hash") |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
215 except KeyError: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
216 hash_ = cls.get_widget_hash(target, _kwargs["profiles"]) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
217 |
1304
1a61b18703c4
quick frontend (quick widgets): class' __name__ method is used for classes_map hash because the use of class directly was causing bugs with pyjamas (difficult to find, several MicroblogPanel instances were added only once in Libervia's TabPanel, hash method seemed buggy)
Goffi <goffi@goffi.org>
parents:
1303
diff
changeset
|
218 ## widget creation or retrieval ## |
1a61b18703c4
quick frontend (quick widgets): class' __name__ method is used for classes_map hash because the use of class directly was causing bugs with pyjamas (difficult to find, several MicroblogPanel instances were added only once in Libervia's TabPanel, hash method seemed buggy)
Goffi <goffi@goffi.org>
parents:
1303
diff
changeset
|
219 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
220 widgets_map = self._widgets.setdefault( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
221 cls.__name__, {} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
222 ) # we sorts widgets by classes |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
223 if not cls.SINGLE: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
224 widget = None # if the class is not SINGLE, we always create a new widget |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
225 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
226 try: |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
227 widget = widgets_map[hash_][0] |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
228 except KeyError: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
229 widget = None |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
230 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
231 widget.add_target(target) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
232 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
233 if widget is None: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
234 # we need to create a new widget |
3168
1cb232c9e845
quick frontends (widgets): added widgetNew and widgetDelete listeners:
Goffi <goffi@goffi.org>
parents:
3165
diff
changeset
|
235 log.debug(f"Creating new widget for target {target} {cls}") |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
236 widget = cls(*_args, **_kwargs) |
3114
060ac43627fc
quick frontend (widgets): fixed widget creation in getOrCreateWidget:
Goffi <goffi@goffi.org>
parents:
3112
diff
changeset
|
237 widgets_map.setdefault(hash_, []).append(widget) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
238 self.host.call_listeners("widgetNew", widget) |
0 | 239 |
1301
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
240 if on_new_widget == C.WIDGET_NEW: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
241 self.host.new_widget(widget) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
242 elif callable(on_new_widget): |
1322
1f13a837e4b2
quick_frontend (quick_widgets): revert commit 1319
souliane <souliane@mailoo.org>
parents:
1321
diff
changeset
|
243 on_new_widget(widget) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
244 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
245 assert on_new_widget is None |
1301
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
246 else: |
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
247 # the widget already exists |
1308
f079e6ed1e69
quick frontend(quick widgets): added the ability to use a callable with getOrCreateWidget's on_existing_widget
Goffi <goffi@goffi.org>
parents:
1307
diff
changeset
|
248 if on_existing_widget == C.WIDGET_KEEP: |
f079e6ed1e69
quick frontend(quick widgets): added the ability to use a callable with getOrCreateWidget's on_existing_widget
Goffi <goffi@goffi.org>
parents:
1307
diff
changeset
|
249 pass |
1309
d0d5ba3b4d64
quick frontend(quick widgets): fixed bad condition test in previous commit
Goffi <goffi@goffi.org>
parents:
1308
diff
changeset
|
250 elif on_existing_widget == C.WIDGET_RAISE: |
1301
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
251 raise WidgetAlreadyExistsError(hash_) |
afc57b34c0a3
Quick Frontend (quick_widgets): added on_existing_widget in getOrCreateWidget (see docstring for more infos) + use of constants
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
252 elif on_existing_widget == C.WIDGET_RECREATE: |
2062
e22ab34c68f6
quick fronten (widgets): if a widget is recreated, "recreateArgs" method can be implemented to specify arguments to clone it correctly
Goffi <goffi@goffi.org>
parents:
2047
diff
changeset
|
253 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
254 recreate_args = widget.recreate_args |
2062
e22ab34c68f6
quick fronten (widgets): if a widget is recreated, "recreateArgs" method can be implemented to specify arguments to clone it correctly
Goffi <goffi@goffi.org>
parents:
2047
diff
changeset
|
255 except AttributeError: |
e22ab34c68f6
quick fronten (widgets): if a widget is recreated, "recreateArgs" method can be implemented to specify arguments to clone it correctly
Goffi <goffi@goffi.org>
parents:
2047
diff
changeset
|
256 pass |
e22ab34c68f6
quick fronten (widgets): if a widget is recreated, "recreateArgs" method can be implemented to specify arguments to clone it correctly
Goffi <goffi@goffi.org>
parents:
2047
diff
changeset
|
257 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
258 recreate_args(_args, _kwargs) |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
259 widget = cls(*_args, **_kwargs) |
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
260 widgets_map[hash_].append(widget) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
261 log.debug( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
262 "widget <{wid}> already exists, a new one has been recreated".format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
263 wid=widget |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
264 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
265 ) |
1308
f079e6ed1e69
quick frontend(quick widgets): added the ability to use a callable with getOrCreateWidget's on_existing_widget
Goffi <goffi@goffi.org>
parents:
1307
diff
changeset
|
266 elif callable(on_existing_widget): |
2852
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
267 widget = on_existing_widget(widget) |
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
268 if widget is None: |
e2595c81eb6d
quick frontend(widgets): improved handling of multiple instances of widgets:
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
269 raise exceptions.InternalError( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
270 "on_existing_widget method must return the widget to use" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
271 ) |
3115
3018d153a615
quick frontend (widgets): some more errors handling in getOrCreateWidget
Goffi <goffi@goffi.org>
parents:
3114
diff
changeset
|
272 if widget not in widgets_map[hash_]: |
3018d153a615
quick frontend (widgets): some more errors handling in getOrCreateWidget
Goffi <goffi@goffi.org>
parents:
3114
diff
changeset
|
273 log.debug( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
274 "the widget returned by on_existing_widget is new, adding it" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
275 ) |
3115
3018d153a615
quick frontend (widgets): some more errors handling in getOrCreateWidget
Goffi <goffi@goffi.org>
parents:
3114
diff
changeset
|
276 widgets_map[hash_].append(widget) |
1308
f079e6ed1e69
quick frontend(quick widgets): added the ability to use a callable with getOrCreateWidget's on_existing_widget
Goffi <goffi@goffi.org>
parents:
1307
diff
changeset
|
277 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
278 raise exceptions.InternalError( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
279 "Unexpected on_existing_widget value ({})".format(on_existing_widget) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
280 ) |
1308
f079e6ed1e69
quick frontend(quick widgets): added the ability to use a callable with getOrCreateWidget's on_existing_widget
Goffi <goffi@goffi.org>
parents:
1307
diff
changeset
|
281 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
282 return widget |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
283 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
284 def delete_widget(self, widget_to_delete, *args, **kwargs): |
2853
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
285 """Delete a widget instance |
1303
d3ef3894254d
quick frontend (quick_widgets): add deleteWidget method
Goffi <goffi@goffi.org>
parents:
1301
diff
changeset
|
286 |
2043
f3940f6a3222
quick frontend (widgets): a deletion with onDelete can now be cancelled if onDelete return False
Goffi <goffi@goffi.org>
parents:
2039
diff
changeset
|
287 this method must be called by frontends when a widget is deleted |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
288 widget's on_delete method will be called before deletion, and deletion will be |
2853
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
289 stopped if it returns False. |
2047
7f5e344938c1
quick_frontend(quick_widgets): deleteWidget can use additional arguments which will be passed to onDelete
Goffi <goffi@goffi.org>
parents:
2043
diff
changeset
|
290 @param widget_to_delete(QuickWidget): widget which need to deleted |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
291 @param *args: extra arguments to pass to on_delete |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
292 @param *kwargs: extra keywords arguments to pass to on_delete |
3158
6032245c927e
quick frontend (app): added "explicit_close" to deleteWidget, and use it on mucRoomLeftHandler:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
293 the extra arguments are not used by QuickFrontend, it's is up to |
6032245c927e
quick frontend (app): added "explicit_close" to deleteWidget, and use it on mucRoomLeftHandler:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
294 the frontend to use them or not. |
6032245c927e
quick frontend (app): added "explicit_close" to deleteWidget, and use it on mucRoomLeftHandler:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
295 following extra arguments are well known: |
6032245c927e
quick frontend (app): added "explicit_close" to deleteWidget, and use it on mucRoomLeftHandler:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
296 - "all_instances" can be used as kwarg, if it evaluate to True, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
297 all instances of the widget will be deleted (if on_delete is |
3158
6032245c927e
quick frontend (app): added "explicit_close" to deleteWidget, and use it on mucRoomLeftHandler:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
298 not returning False for any of the instance). This arguments |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
299 is not sent to on_delete methods. |
3158
6032245c927e
quick frontend (app): added "explicit_close" to deleteWidget, and use it on mucRoomLeftHandler:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
300 - "explicit_close" is used when the deletion is requested by |
6032245c927e
quick frontend (app): added "explicit_close" to deleteWidget, and use it on mucRoomLeftHandler:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
301 the user or a leave signal, "all_instances" is usually set at |
6032245c927e
quick frontend (app): added "explicit_close" to deleteWidget, and use it on mucRoomLeftHandler:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
302 the same time. |
1303
d3ef3894254d
quick frontend (quick_widgets): add deleteWidget method
Goffi <goffi@goffi.org>
parents:
1301
diff
changeset
|
303 """ |
2853
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
304 # TODO: all_instances must be independante kwargs, this is not possible with Python 2 |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
305 # but will be with Python 3 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
306 all_instances = kwargs.get("all_instances", False) |
2853
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
307 |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
308 if all_instances: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
309 for w in self.get_widget_instances(widget_to_delete): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
310 if w.on_delete(**kwargs) == False: |
3116
328a6cea3802
quick frontend (widgets): don't use *args for onDelete + more debug logs
Goffi <goffi@goffi.org>
parents:
3115
diff
changeset
|
311 log.debug( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
312 f"Deletion of {widget_to_delete} cancelled by widget itself" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
313 ) |
2853
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
314 return |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
315 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
316 if widget_to_delete.on_delete(**kwargs) == False: |
3116
328a6cea3802
quick frontend (widgets): don't use *args for onDelete + more debug logs
Goffi <goffi@goffi.org>
parents:
3115
diff
changeset
|
317 log.debug(f"Deletion of {widget_to_delete} cancelled by widget itself") |
2853
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
318 return |
2043
f3940f6a3222
quick frontend (widgets): a deletion with onDelete can now be cancelled if onDelete return False
Goffi <goffi@goffi.org>
parents:
2039
diff
changeset
|
319 |
f3940f6a3222
quick frontend (widgets): a deletion with onDelete can now be cancelled if onDelete return False
Goffi <goffi@goffi.org>
parents:
2039
diff
changeset
|
320 if self.host.selected_widget == widget_to_delete: |
f3940f6a3222
quick frontend (widgets): a deletion with onDelete can now be cancelled if onDelete return False
Goffi <goffi@goffi.org>
parents:
2039
diff
changeset
|
321 self.host.selected_widget = None |
1303
d3ef3894254d
quick frontend (quick_widgets): add deleteWidget method
Goffi <goffi@goffi.org>
parents:
1301
diff
changeset
|
322 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
323 class_ = self.get_real_class(widget_to_delete.__class__) |
2853
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
324 try: |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
325 widgets_map = self._widgets[class_.__name__] |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
326 except KeyError: |
3028 | 327 log.error("no widgets_map found for class {cls}".format(cls=class_)) |
2853
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
328 return |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
329 widget_hash = str( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
330 class_.get_widget_hash(widget_to_delete.target, widget_to_delete.profiles) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
331 ) |
3115
3018d153a615
quick frontend (widgets): some more errors handling in getOrCreateWidget
Goffi <goffi@goffi.org>
parents:
3114
diff
changeset
|
332 try: |
3018d153a615
quick frontend (widgets): some more errors handling in getOrCreateWidget
Goffi <goffi@goffi.org>
parents:
3114
diff
changeset
|
333 widget_instances = widgets_map[widget_hash] |
3018d153a615
quick frontend (widgets): some more errors handling in getOrCreateWidget
Goffi <goffi@goffi.org>
parents:
3114
diff
changeset
|
334 except KeyError: |
3018d153a615
quick frontend (widgets): some more errors handling in getOrCreateWidget
Goffi <goffi@goffi.org>
parents:
3114
diff
changeset
|
335 log.error(f"no instance of {class_.__name__} found with hash {widget_hash!r}") |
3018d153a615
quick frontend (widgets): some more errors handling in getOrCreateWidget
Goffi <goffi@goffi.org>
parents:
3114
diff
changeset
|
336 return |
2853
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
337 if all_instances: |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
338 widget_instances.clear() |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
339 else: |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
340 try: |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
341 widget_instances.remove(widget_to_delete) |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
342 except ValueError: |
3028 | 343 log.error("widget_to_delete not found in widget instances") |
2853
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
344 return |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
345 |
3028 | 346 log.debug("widget {} deleted".format(widget_to_delete)) |
2853
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
347 |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
348 if not widget_instances: |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
349 # all instances with this hash have been deleted |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
350 # we remove the hash itself |
6901a425d882
quick frontend (widgets): improved deletion of widget:
Goffi <goffi@goffi.org>
parents:
2852
diff
changeset
|
351 del widgets_map[widget_hash] |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
352 log.debug( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
353 "All instances of {cls} with hash {widget_hash!r} have been deleted".format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
354 cls=class_, widget_hash=widget_hash |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
355 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
356 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
357 self.host.call_listeners("widgetDeleted", widget_to_delete) |
1303
d3ef3894254d
quick frontend (quick_widgets): add deleteWidget method
Goffi <goffi@goffi.org>
parents:
1301
diff
changeset
|
358 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
359 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
360 class QuickWidget(object): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
361 """generic widget base""" |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
362 |
2855
ef65dbce313b
quick frontend(widgets): added QuickWidget.target property as a helper method to get a single target:
Goffi <goffi@goffi.org>
parents:
2853
diff
changeset
|
363 # FIXME: sometime a single target is used, sometimes several ones |
ef65dbce313b
quick frontend(widgets): added QuickWidget.target property as a helper method to get a single target:
Goffi <goffi@goffi.org>
parents:
2853
diff
changeset
|
364 # This should be sorted out in the same way as for profiles: a single |
ef65dbce313b
quick frontend(widgets): added QuickWidget.target property as a helper method to get a single target:
Goffi <goffi@goffi.org>
parents:
2853
diff
changeset
|
365 # target should be possible when appropriate attribute is set. |
ef65dbce313b
quick frontend(widgets): added QuickWidget.target property as a helper method to get a single target:
Goffi <goffi@goffi.org>
parents:
2853
diff
changeset
|
366 # methods using target(s) and hash should be fixed accordingly |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
367 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
368 SINGLE = True # if True, there can be only one widget per target(s) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
369 PROFILES_MULTIPLE = False # If True, this widget can handle several profiles at once |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
370 PROFILES_ALLOW_NONE = False # If True, this widget can be used without profile |
0 | 371 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
372 def __init__(self, host, target, profiles=None): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
373 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
374 @param host: %(doc_host)s |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
375 @param target: target specific for this widget class |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
376 @param profiles: can be either: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
377 - (unicode): used when widget class manage a unique profile |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
378 - (iterable): some widget class can manage several profiles, several at once can be specified here |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
379 - None: no profile is managed by this widget class (rare) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
380 @raise: ValueError when (iterable) or None is given to profiles for a widget class which manage one unique profile. |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
381 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
382 self.host = host |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
383 self.targets = set() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
384 self.add_target(target) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
385 self.profiles = set() |
2851
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
386 self._sync = True |
3028 | 387 if isinstance(profiles, str): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
388 self.add_profile(profiles) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
389 elif profiles is None: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
390 if not self.PROFILES_ALLOW_NONE: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
391 raise ValueError("profiles can't have a value of None") |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
392 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
393 for profile in profiles: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
394 self.add_profile(profile) |
2027
666b42c957b5
quick frontend (widget): minor profiles check on widget creation
Goffi <goffi@goffi.org>
parents:
2007
diff
changeset
|
395 if not self.profiles: |
666b42c957b5
quick frontend (widget): minor profiles check on widget creation
Goffi <goffi@goffi.org>
parents:
2007
diff
changeset
|
396 raise ValueError("no profile found, use None for no profile classes") |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
397 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
398 @property |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
399 def profile(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
400 assert ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
401 len(self.profiles) == 1 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
402 and not self.PROFILES_MULTIPLE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
403 and not self.PROFILES_ALLOW_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
404 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
405 return list(self.profiles)[0] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
406 |
2855
ef65dbce313b
quick frontend(widgets): added QuickWidget.target property as a helper method to get a single target:
Goffi <goffi@goffi.org>
parents:
2853
diff
changeset
|
407 @property |
ef65dbce313b
quick frontend(widgets): added QuickWidget.target property as a helper method to get a single target:
Goffi <goffi@goffi.org>
parents:
2853
diff
changeset
|
408 def target(self): |
ef65dbce313b
quick frontend(widgets): added QuickWidget.target property as a helper method to get a single target:
Goffi <goffi@goffi.org>
parents:
2853
diff
changeset
|
409 """Return main target |
ef65dbce313b
quick frontend(widgets): added QuickWidget.target property as a helper method to get a single target:
Goffi <goffi@goffi.org>
parents:
2853
diff
changeset
|
410 |
ef65dbce313b
quick frontend(widgets): added QuickWidget.target property as a helper method to get a single target:
Goffi <goffi@goffi.org>
parents:
2853
diff
changeset
|
411 A random target is returned when several targets are available |
ef65dbce313b
quick frontend(widgets): added QuickWidget.target property as a helper method to get a single target:
Goffi <goffi@goffi.org>
parents:
2853
diff
changeset
|
412 """ |
ef65dbce313b
quick frontend(widgets): added QuickWidget.target property as a helper method to get a single target:
Goffi <goffi@goffi.org>
parents:
2853
diff
changeset
|
413 return next(iter(self.targets)) |
ef65dbce313b
quick frontend(widgets): added QuickWidget.target property as a helper method to get a single target:
Goffi <goffi@goffi.org>
parents:
2853
diff
changeset
|
414 |
3112
91891a108d6f
quick frontend (widgets): added "widget_hash" helper property
Goffi <goffi@goffi.org>
parents:
3108
diff
changeset
|
415 @property |
91891a108d6f
quick frontend (widgets): added "widget_hash" helper property
Goffi <goffi@goffi.org>
parents:
3108
diff
changeset
|
416 def widget_hash(self): |
91891a108d6f
quick frontend (widgets): added "widget_hash" helper property
Goffi <goffi@goffi.org>
parents:
3108
diff
changeset
|
417 """Return quick widget hash""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
418 return self.get_widget_hash(self.target, self.profiles) |
3112
91891a108d6f
quick frontend (widgets): added "widget_hash" helper property
Goffi <goffi@goffi.org>
parents:
3108
diff
changeset
|
419 |
2851
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
420 # synchronisation state |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
421 |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
422 @property |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
423 def sync(self): |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
424 return self._sync |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
425 |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
426 @sync.setter |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
427 def sync(self, state): |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
428 """state of synchronisation with backend |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
429 |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
430 @param state(bool): True when backend is synchronised |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
431 False is set by core |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
432 True must be set by the widget when resynchronisation is finished |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
433 """ |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
434 self._sync = state |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
435 |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
436 def resync(self): |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
437 """Method called when backend can be resynchronized |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
438 |
3108 | 439 The widget has to set self.sync itself when the synchronisation is finished |
2851
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
440 """ |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
441 pass |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
442 |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
443 # target/profile |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
444 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
445 def add_target(self, target): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
446 """Add a target if it doesn't already exists |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
447 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
448 @param target: target to add |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
449 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
450 self.targets.add(target) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
451 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
452 def add_profile(self, profile): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
453 """Add a profile is if doesn't already exists |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
454 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
455 @param profile: profile to add |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
456 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
457 if self.profiles and not self.PROFILES_MULTIPLE: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
458 raise ValueError("multiple profiles are not allowed") |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
459 self.profiles.add(profile) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
460 |
2851
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
461 # widget identitication |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
462 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
463 @staticmethod |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
464 def get_widget_hash(target, profiles): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
465 """Return the hash associated with this target for this widget class |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
466 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
467 some widget classes can manage several target on the same instance |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
468 (e.g.: a chat widget with multiple resources on the same bare jid), |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
469 this method allow to return a hash associated to one or several targets |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
470 to retrieve the good instance. For example, a widget managing JID targets, |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
471 and all resource of the same bare jid would return the bare jid as hash. |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
472 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
473 @param target: target to check |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
474 @param profiles: profile(s) associated to target, see __init__ docstring |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
475 @return: a hash (can correspond to one or many targets or profiles, depending of widget class) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
476 """ |
3028 | 477 return str(target) # by defaut, there is one hash for one target |
1303
d3ef3894254d
quick frontend (quick_widgets): add deleteWidget method
Goffi <goffi@goffi.org>
parents:
1301
diff
changeset
|
478 |
2851
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
479 # widget life events |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2845
diff
changeset
|
480 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
481 def on_delete(self, *args, **kwargs): |
2043
f3940f6a3222
quick frontend (widgets): a deletion with onDelete can now be cancelled if onDelete return False
Goffi <goffi@goffi.org>
parents:
2039
diff
changeset
|
482 """Called when a widget is being deleted |
1410
e2e75c3c7c7b
quick_frontend, primitivus: fixes a couple of issues:
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
483 |
2043
f3940f6a3222
quick frontend (widgets): a deletion with onDelete can now be cancelled if onDelete return False
Goffi <goffi@goffi.org>
parents:
2039
diff
changeset
|
484 @return (boot, None): False to cancel deletion |
f3940f6a3222
quick frontend (widgets): a deletion with onDelete can now be cancelled if onDelete return False
Goffi <goffi@goffi.org>
parents:
2039
diff
changeset
|
485 all other value continue deletion |
f3940f6a3222
quick frontend (widgets): a deletion with onDelete can now be cancelled if onDelete return False
Goffi <goffi@goffi.org>
parents:
2039
diff
changeset
|
486 """ |
f3940f6a3222
quick frontend (widgets): a deletion with onDelete can now be cancelled if onDelete return False
Goffi <goffi@goffi.org>
parents:
2039
diff
changeset
|
487 return True |
3159
30e08d904208
quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents:
3158
diff
changeset
|
488 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
489 def on_selected(self): |
3159
30e08d904208
quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents:
3158
diff
changeset
|
490 """Called when host.selected_widget is this instance""" |
30e08d904208
quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents:
3158
diff
changeset
|
491 pass |