annotate cagou/core/widgets_handler.py @ 362:e1f56257cabc

core (widgets handler): use widget set in set_widget as selected_widget if selected_widget is None
author Goffi <goffi@goffi.org>
date Mon, 27 Jan 2020 21:17:08 +0100
parents 8b6621cc142c
children 9c6fe392d623
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
1 #!/usr/bin/env python3
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
282
1b835bcfa663 date update
Goffi <goffi@goffi.org>
parents: 271
diff changeset
4 # Copyright (C) 2016-2019 Jérôme Poisson (goffi@goffi.org)
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.core import log as logging
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
21 from sat.core import exceptions
34
02acbb297a61 handler, widget: deleteWidget is now properly called when a QuickWidget is deleted
Goffi <goffi@goffi.org>
parents: 16
diff changeset
22 from sat_frontends.quick_frontend import quick_widgets
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
23 from kivy.graphics import Color, Ellipse
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
24 from kivy.uix.layout import Layout
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from kivy.uix.boxlayout import BoxLayout
155
a0e486074d91 widget handler: block carousel swiping when there is only one slide
Goffi <goffi@goffi.org>
parents: 154
diff changeset
26 from kivy.uix.stencilview import StencilView
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
27 from kivy.uix.carousel import Carousel
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
28 from kivy.uix.screenmanager import ScreenManager, Screen
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
29 from kivy.uix.scrollview import ScrollView
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
30 from kivy.metrics import dp
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from kivy import properties
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
32 from cagou import G
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
33 from .constants import Const as C
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
34 from . import cagou_widget
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
35
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
36 log = logging.getLogger(__name__)
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
163
ef09dce878c7 widgets handler: removed constants which are not used anymore
Goffi <goffi@goffi.org>
parents: 160
diff changeset
38
269
a5dfc789eeaf widgets_handler: increased remove limit and min height/width:
Goffi <goffi@goffi.org>
parents: 263
diff changeset
39 REMOVE_WID_LIMIT = dp(50)
a5dfc789eeaf widgets_handler: increased remove limit and min height/width:
Goffi <goffi@goffi.org>
parents: 263
diff changeset
40 MIN_WIDTH = MIN_HEIGHT = dp(70)
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
43 class WHWrapper(BoxLayout):
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
44 main_container = properties.ObjectProperty(None)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
45 screen_manager = properties.ObjectProperty(None, allownone=True)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
46 carousel = properties.ObjectProperty(None, allownone=True)
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
47 split_size = properties.NumericProperty(dp(1))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
48 split_margin = properties.NumericProperty(dp(2))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
49 split_color = properties.ListProperty([0.8, 0.8, 0.8, 1])
177
9835cafbd909 widgets handler: use dark secondary color for split
Goffi <goffi@goffi.org>
parents: 171
diff changeset
50 split_color_move = C.COLOR_SEC_DARK
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
51 split_color_del = properties.ListProperty([0.8, 0.0, 0.0, 1])
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
52 # sp stands for "split point"
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
53 sp_size = properties.NumericProperty(dp(1))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
54 sp_space = properties.NumericProperty(dp(4))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
55 sp_zone = properties.NumericProperty(dp(30))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
56 _split = properties.OptionProperty('None', options=['None', 'left', 'top'])
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
57 _split_del = properties.BooleanProperty(False)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
58
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
59 def __init__(self, **kwargs):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
60 idx = kwargs.pop('_wid_idx')
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
61 self._wid_idx = idx
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
62 super(WHWrapper, self).__init__(**kwargs)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
63 self._left_wids = set()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
64 self._top_wids = set()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
65 self._right_wids = set()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
66 self._bottom_wids = set()
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
67 self._clear_attributes()
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
68
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
69 def _clear_attributes(self):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
70 self._former_slide = None
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
71
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
72 def __repr__(self):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
73 return "WHWrapper_{idx}".format(idx=self._wid_idx)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
74
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
75 def _main_wid(self, wid_list):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
76 """return main widget of a side list
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
77
263
fe540a6dc14d widgets handler: call host._removeVisibleWidget when a widget is deleted (using split)
Goffi <goffi@goffi.org>
parents: 260
diff changeset
78 main widget is either the widget currently splitted
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
79 or any widget if none is split
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
80 @return (WHWrapper, None): main widget or None
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
81 if there is not widget
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
82 """
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
83 if not wid_list:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
84 return None
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
85 for wid in wid_list:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
86 if wid._split != 'None':
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
87 return wid
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
88 return next(iter(wid_list))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
89
355
8b6621cc142c core (widgets handler): clear widgets when WHWrapper is detached:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
90 def on_parent(self, __, new_parent):
8b6621cc142c core (widgets handler): clear widgets when WHWrapper is detached:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
91 if new_parent is None:
8b6621cc142c core (widgets handler): clear widgets when WHWrapper is detached:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
92 # we detach all children so CagouWidget.whwrapper won't link to this one
8b6621cc142c core (widgets handler): clear widgets when WHWrapper is detached:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
93 # anymore
8b6621cc142c core (widgets handler): clear widgets when WHWrapper is detached:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
94 self.clear_widgets()
8b6621cc142c core (widgets handler): clear widgets when WHWrapper is detached:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
95
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
96 @property
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
97 def _left_wid(self):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
98 return self._main_wid(self._left_wids)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
99
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
100 @property
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
101 def _top_wid(self):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
102 return self._main_wid(self._top_wids)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
103
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
104 @property
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
105 def _right_wid(self):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
106 return self._main_wid(self._right_wids)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
107
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
108 @property
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
109 def _bottom_wid(self):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
110 return self._main_wid(self._bottom_wids)
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
112 @property
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
113 def current_slide(self):
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
114 if (self.carousel is not None
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
115 and (self.screen_manager is None or self.screen_manager.current == '')):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
116 return self.carousel.current_slide
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
117 elif self.screen_manager is not None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
118 # we should have exactly one children in current_screen, else there is a bug
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
119 return self.screen_manager.current_screen.children[0]
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
120 else:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
121 try:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
122 return self.main_container.children[0]
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
123 except IndexError:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
124 log.error("No child found, this should not happen")
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
125 return None
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
126
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
127 @property
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
128 def carousel_active(self):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
129 """Return True if Carousel is used and active"""
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
130 if self.carousel is None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
131 return False
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
132 if self.screen_manager is not None and self.screen_manager.current != '':
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
133 return False
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
134 return True
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
135
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
136 @property
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
137 def former_screen_wid(self):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
138 """Return widget currently active for former screen"""
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
139 if self.screen_manager is None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
140 raise exceptions.InternalError(
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
141 "former_screen_wid can only be used if ScreenManager is used")
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
142 if self._former_screen_name is None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
143 return None
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
144 return self.getScreenWidget(self._former_screen_name)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
145
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
146 def getScreenWidget(self, screen_name):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
147 """Return screen main widget, handling carousel if necessary"""
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
148 if self.carousel is not None and screen_name == '':
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
149 return self.carousel.current_slide
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
150 try:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
151 return self.screen_manager.get_screen(screen_name).children[0]
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
152 except IndexError:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
153 return None
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
155 def _draw_ellipse(self):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
156 """draw split ellipse"""
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
157 color = self.split_color_del if self._split_del else self.split_color_move
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
158 try:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
159 self.canvas.after.remove(self.ellipse)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
160 except AttributeError:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
161 pass
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
162 if self._split == "top":
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
163 with self.canvas.after:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
164 Color(*color)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
165 self.ellipse = Ellipse(angle_start=90, angle_end=270,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
166 pos=(self.x + self.width/2 - self.sp_zone/2,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
167 self.y + self.height - self.sp_zone/2),
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
168 size=(self.sp_zone, self.sp_zone))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
169 elif self._split == "left":
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
170 with self.canvas.after:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
171 Color(*color)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
172 self.ellipse = Ellipse(angle_end=180,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
173 pos=(self.x + -self.sp_zone/2,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
174 self.y + self.height/2 - self.sp_zone/2),
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
175 size = (self.sp_zone, self.sp_zone))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
176 else:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
177 raise exceptions.InternalError('unexpected split value')
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
178
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
179 def on_touch_down(self, touch):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
180 """activate split if touch is on a split zone"""
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
181 if not self.collide_point(*touch.pos):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
182 return
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
183 log.debug("WIDGET IDX: {} (left: {}, top: {}, right: {}, bottom: {}), pos: {}, size: {}".format(
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
184 self._wid_idx,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
185 'None' if not self._left_wids else [w._wid_idx for w in self._left_wids],
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
186 'None' if not self._top_wids else [w._wid_idx for w in self._top_wids],
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
187 'None' if not self._right_wids else [w._wid_idx for w in self._right_wids],
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
188 'None' if not self._bottom_wids else [w._wid_idx for w in self._bottom_wids],
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
189 self.pos,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
190 self.size,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
191 ))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
192 touch_rx, touch_ry = self.to_widget(*touch.pos, relative=True)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
193 if (touch_ry <= self.height and
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
194 touch_ry >= self.height - self.split_size - self.split_margin or
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
195 touch_ry <= self.height and
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
196 touch_ry >= self.height - self.sp_zone and
300
efd3fbc85aaf core (widgets_handler): use explicit floor division to avoid warnings.
Goffi <goffi@goffi.org>
parents: 282
diff changeset
197 touch_rx >= self.width//2 - self.sp_zone//2 and
efd3fbc85aaf core (widgets_handler): use explicit floor division to avoid warnings.
Goffi <goffi@goffi.org>
parents: 282
diff changeset
198 touch_rx <= self.width//2 + self.sp_zone//2):
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
199 # split area is touched, we activate top split mode
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
200 self._split = "top"
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
201 self._draw_ellipse()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
202 elif (touch_rx >= 0 and
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
203 touch_rx <= self.split_size + self.split_margin or
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
204 touch_rx >= 0 and
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
205 touch_rx <= self.sp_zone and
300
efd3fbc85aaf core (widgets_handler): use explicit floor division to avoid warnings.
Goffi <goffi@goffi.org>
parents: 282
diff changeset
206 touch_ry >= self.height//2 - self.sp_zone//2 and
efd3fbc85aaf core (widgets_handler): use explicit floor division to avoid warnings.
Goffi <goffi@goffi.org>
parents: 282
diff changeset
207 touch_ry <= self.height//2 + self.sp_zone//2):
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
208 # split area is touched, we activate left split mode
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
209 self._split = "left"
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
210 touch.ud['ori_width'] = self.width
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
211 self._draw_ellipse()
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 else:
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
213 if self.carousel_active and len(self.carousel.slides) <= 1:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
214 # we don't want swipe of carousel if there is only one slide
155
a0e486074d91 widget handler: block carousel swiping when there is only one slide
Goffi <goffi@goffi.org>
parents: 154
diff changeset
215 return StencilView.on_touch_down(self.carousel, touch)
a0e486074d91 widget handler: block carousel swiping when there is only one slide
Goffi <goffi@goffi.org>
parents: 154
diff changeset
216 else:
a0e486074d91 widget handler: block carousel swiping when there is only one slide
Goffi <goffi@goffi.org>
parents: 154
diff changeset
217 return super(WHWrapper, self).on_touch_down(touch)
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
218
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 def on_touch_move(self, touch):
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
220 """handle size change and widget creation on split"""
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
221 if self._split == 'None':
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
222 return super(WHWrapper, self).on_touch_move(touch)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
223
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
224 elif self._split == 'top':
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
225 new_height = touch.y - self.y
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
226
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
227 if new_height < MIN_HEIGHT:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
228 return
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
229
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
230 # we must not pass the top widget/border
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
231 if self._top_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
232 top = next(iter(self._top_wids))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
233 y_limit = top.y + top.height
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
234
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
235 if top.height <= REMOVE_WID_LIMIT:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
236 # we are in remove zone, we add visual hint for that
160
916af9c1cb9b widget handler: don't set split delete mode if there is not top/left widget
Goffi <goffi@goffi.org>
parents: 155
diff changeset
237 if not self._split_del and self._top_wids:
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
238 self._split_del = True
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
239 self._draw_ellipse()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
240 else:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
241 if self._split_del:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
242 self._split_del = False
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
243 self._draw_ellipse()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
244 else:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
245 y_limit = self.y + self.height
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
246
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
247 if touch.y >= y_limit:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
248 return
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
249
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
250 # all right, we can change size
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
251 self.height = new_height
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
252 self.ellipse.pos = (self.ellipse.pos[0], touch.y - self.sp_zone/2)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
253
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
254 if not self._top_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
255 # we are the last widget on the top
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
256 # so we create a new widget
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
257 new_wid = self.parent.add_widget()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
258 self._top_wids.add(new_wid)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
259 new_wid._bottom_wids.add(self)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
260 for w in self._right_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
261 new_wid._right_wids.add(w)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
262 w._left_wids.add(new_wid)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
263 for w in self._left_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
264 new_wid._left_wids.add(w)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
265 w._right_wids.add(new_wid)
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
266
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
267 elif self._split == 'left':
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
268 ori_width = touch.ud['ori_width']
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
269 new_x = touch.x
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
270 new_width = ori_width - (touch.x - touch.ox)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
271
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
272 if new_width < MIN_WIDTH:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
273 return
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
274
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
275 # we must not pass the left widget/border
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
276 if self._left_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
277 left = next(iter(self._left_wids))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
278 x_limit = left.x
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
279
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
280 if left.width <= REMOVE_WID_LIMIT:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
281 # we are in remove zone, we add visual hint for that
160
916af9c1cb9b widget handler: don't set split delete mode if there is not top/left widget
Goffi <goffi@goffi.org>
parents: 155
diff changeset
282 if not self._split_del and self._left_wids:
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
283 self._split_del = True
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
284 self._draw_ellipse()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
285 else:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
286 if self._split_del:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
287 self._split_del = False
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
288 self._draw_ellipse()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
289 else:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
290 x_limit = self.x
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
291
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
292 if new_x <= x_limit:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
293 return
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
294
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
295 # all right, we can change position/size
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
296 self.x = new_x
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
297 self.width = new_width
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
298 self.ellipse.pos = (touch.x - self.sp_zone/2, self.ellipse.pos[1])
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
299
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
300 if not self._left_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
301 # we are the last widget on the left
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
302 # so we create a new widget
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
303 new_wid = self.parent.add_widget()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
304 self._left_wids.add(new_wid)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
305 new_wid._right_wids.add(self)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
306 for w in self._top_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
307 new_wid._top_wids.add(w)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
308 w._bottom_wids.add(new_wid)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
309 for w in self._bottom_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
310 new_wid._bottom_wids.add(w)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
311 w._top_wids.add(new_wid)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
312
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
313 else:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
314 raise Exception.InternalError('invalid _split value')
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
315
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
316 def on_touch_up(self, touch):
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
317 if self._split == 'None':
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
318 return super(WHWrapper, self).on_touch_up(touch)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
319 if self._split == 'top':
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
320 # we remove all top widgets in delete zone,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
321 # and update there side widgets list
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
322 for top in self._top_wids.copy():
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
323 if top.height <= REMOVE_WID_LIMIT:
263
fe540a6dc14d widgets handler: call host._removeVisibleWidget when a widget is deleted (using split)
Goffi <goffi@goffi.org>
parents: 260
diff changeset
324 G.host._removeVisibleWidget(top.current_slide)
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
325 for w in top._top_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
326 w._bottom_wids.remove(top)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
327 w._bottom_wids.update(top._bottom_wids)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
328 for w in top._bottom_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
329 w._top_wids.remove(top)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
330 w._top_wids.update(top._top_wids)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
331 for w in top._left_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
332 w._right_wids.remove(top)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
333 for w in top._right_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
334 w._left_wids.remove(top)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
335 self.parent.remove_widget(top)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
336 elif self._split == 'left':
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
337 # we remove all left widgets in delete zone,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
338 # and update there side widgets list
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
339 for left in self._left_wids.copy():
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
340 if left.width <= REMOVE_WID_LIMIT:
263
fe540a6dc14d widgets handler: call host._removeVisibleWidget when a widget is deleted (using split)
Goffi <goffi@goffi.org>
parents: 260
diff changeset
341 G.host._removeVisibleWidget(left.current_slide)
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
342 for w in left._left_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
343 w._right_wids.remove(left)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
344 w._right_wids.update(left._right_wids)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
345 for w in left._right_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
346 w._left_wids.remove(left)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
347 w._left_wids.update(left._left_wids)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
348 for w in left._top_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
349 w._bottom_wids.remove(left)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
350 for w in left._bottom_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
351 w._top_wids.remove(left)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
352 self.parent.remove_widget(left)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
353 self._split = 'None'
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
354 self.canvas.after.remove(self.ellipse)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
355 del self.ellipse
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
356
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
357 def clear_widgets(self):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
358 current_slide = self.current_slide
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
359 if current_slide is not None:
355
8b6621cc142c core (widgets handler): clear widgets when WHWrapper is detached:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
360 G.host._removeVisibleWidget(current_slide, ignore_missing=True)
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
361
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
362 super().clear_widgets()
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
363
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
364 self.screen_manager = None
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
365 self.carousel = None
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
366 self._clear_attributes()
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
367
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
368 def set_widget(self, wid, index=0):
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
369 assert len(self.children) == 0
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
370
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
371 if wid.collection_carousel or wid.global_screen_manager:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
372 self.main_container = self
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
373 else:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
374 self.main_container = ScrollView()
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
375 self.add_widget(self.main_container)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
376
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
377 if self.carousel is not None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
378 return self.carousel.add_widget(wid, index)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
379
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
380 if wid.global_screen_manager:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
381 if self.screen_manager is None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
382 self.screen_manager = ScreenManager()
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
383 self.main_container.add_widget(self.screen_manager)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
384 parent = Screen()
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
385 self.screen_manager.add_widget(parent)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
386 self._former_screen_name = ''
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
387 self.screen_manager.bind(current=self.onScreenChange)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
388 wid.screenManagerInit(self.screen_manager)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
389 else:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
390 parent = self.main_container
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
391
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
392 if wid.collection_carousel:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
393 # a Carousel is requested, and this is the first widget that we add
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
394 # so we need to create the carousel
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
395 self.carousel = Carousel(
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
396 direction = "right",
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
397 ignore_perpendicular_swipes = True,
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
398 loop = True,
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
399 )
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
400 self._slides_update_lock = 0
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
401 self.carousel.bind(current_slide=self.onSlideChange)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
402 parent.add_widget(self.carousel)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
403 self.carousel.add_widget(wid, index)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
404 else:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
405 # no Carousel requested, we add the widget as a direct child
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
406 parent.add_widget(wid)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
407 G.host._addVisibleWidget(wid)
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
408
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
409 def changeWidget(self, new_widget):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
410 """Change currently displayed widget
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
411
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
412 slides widgets will be updated
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
413 """
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
414 if (self.carousel is not None
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
415 and self.carousel.current_slide.__class__ == new_widget.__class__):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
416 # we have the same class, we reuse carousel and screen manager setting
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
417
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
418 if self.carousel.current_slide != new_widget:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
419 # slides update need to be blocked to avoid the update in onSlideChange
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
420 # which would mess the removal of current widgets
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
421 self._slides_update_lock += 1
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
422 new_wid = None
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
423 for w in self.carousel.slides[:]:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
424 if w.widget_hash == new_widget.widget_hash:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
425 new_wid = w
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
426 continue
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
427 self.carousel.remove_widget(w)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
428 if isinstance(w, quick_widgets.QuickWidget):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
429 G.host.widgets.deleteWidget(w)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
430 if new_wid is None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
431 new_wid = G.host.getOrClone(new_widget)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
432 self.carousel.add_widget(new_wid)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
433 self._updateHiddenSlides()
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
434 self._slides_update_lock -= 1
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
435
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
436 if self.screen_manager is not None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
437 self.screen_manager.clear_widgets([
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
438 s for s in self.screen_manager.screens if s.name != ''])
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
439 new_wid.screenManagerInit(self.screen_manager)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
440 else:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
441 # else, we restart fresh
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
442 self.clear_widgets()
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
443 self.set_widget(G.host.getOrClone(new_widget))
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
444
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
445 def onScreenChange(self, screen_manager, new_screen):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
446 try:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
447 new_screen_wid = self.current_slide
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
448 except IndexError:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
449 new_screen_wid = None
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
450 log.warning("Switching to a screen without children")
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
451 if new_screen == '' and self.carousel is not None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
452 # carousel may have been changed in the background, so we update slides
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
453 self._updateHiddenSlides()
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
454 former_screen_wid = self.former_screen_wid
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
455 if isinstance(former_screen_wid, cagou_widget.CagouWidget):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
456 G.host._removeVisibleWidget(former_screen_wid)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
457 if isinstance(new_screen_wid, cagou_widget.CagouWidget):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
458 G.host._addVisibleWidget(new_screen_wid)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
459 self._former_screen_name = new_screen
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
460 G.host.selected_widget = new_screen_wid
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
461
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
462 def onSlideChange(self, handler, new_slide):
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
463 if self._former_slide is new_slide:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
464 # FIXME: workaround for Kivy a95d67f (and above?), Carousel.current_slide
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
465 # binding now calls onSlideChange twice with the same widget (here
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
466 # "new_slide"). To be checked with Kivy team.
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
467 return
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
468 log.debug(f"Slide change: new_slide = {new_slide}")
248
b6e33b35538b core, widgets handler: visible_widgets now keep all CagouWidgets, not only QuickWidgets. visible_quick_widgets can be used if only QuickWidgets are desired.
Goffi <goffi@goffi.org>
parents: 177
diff changeset
469 if self._former_slide is not None:
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
470 G.host._removeVisibleWidget(self._former_slide, ignore_missing=True)
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
471 self._former_slide = new_slide
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
472 if self.carousel_active:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
473 G.host.selected_widget = new_slide
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
474 if new_slide is not None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
475 G.host._addVisibleWidget(new_slide)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
476 self._updateHiddenSlides()
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
477
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
478 def hiddenList(self, visible_list, ignore=None):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
479 """return widgets of same class as carousel current one, if they are hidden
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
480
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
481 @param visible_list(list[QuickWidget]): widgets visible
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
482 @param ignore(QuickWidget, None): do no return this widget
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
483 @return (iter[QuickWidget]): widgets hidden
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
484 """
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
485 # we want to avoid recreated widgets
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
486 added = [w.widget_hash for w in visible_list]
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
487 current_slide = self.carousel.current_slide
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
488 for w in G.host.widgets.getWidgets(current_slide.__class__,
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
489 profiles=current_slide.profiles):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
490 wid_hash = w.widget_hash
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
491 if w in visible_list or wid_hash in added:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
492 continue
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
493 if wid_hash == ignore.widget_hash:
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
494 continue
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
495 yield w
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
496
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
497 def widgets_sort(self, widget):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
498 """method used as key to sort the widgets
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
499
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
500 order of the widgets when changing slide is affected
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
501 @param widget(QuickWidget): widget to sort
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
502 @return: a value which will be used for sorting
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
503 """
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
504 try:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
505 return str(widget.target).lower()
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
506 except AttributeError:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
507 return str(list(widget.targets)[0]).lower()
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
508
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
509 def _updateHiddenSlides(self):
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
510 """adjust carousel slides according to visible widgets"""
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
511 if self._slides_update_lock or not self.carousel_active:
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
512 return
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
513 current_slide = self.carousel.current_slide
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
514 if not isinstance(current_slide, quick_widgets.QuickWidget):
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
515 return
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
516 # lock must be used here to avoid recursions
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
517 self._slides_update_lock += 1
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
518 visible_list = G.host.getVisibleList(current_slide.__class__)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
519 # we ignore current_slide as it may not be visible yet (e.g. if an other
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
520 # screen is shown
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
521 hidden = list(self.hiddenList(visible_list, ignore=current_slide))
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
522 slides_sorted = sorted(set(hidden + [current_slide]), key=self.widgets_sort)
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
523 to_remove = set(self.carousel.slides).difference({current_slide})
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
524 for w in to_remove:
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
525 self.carousel.remove_widget(w)
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
526 if hidden:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
527 # no need to add more than two widgets (next and previous),
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
528 # as the list will be updated on each new visible widget
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
529 current_idx = slides_sorted.index(current_slide)
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
530 try:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
531 next_slide = slides_sorted[current_idx+1]
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
532 except IndexError:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
533 next_slide = slides_sorted[0]
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
534 self.carousel.add_widget(G.host.getOrClone(next_slide))
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
535 if len(hidden)>1:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
536 previous_slide = slides_sorted[current_idx-1]
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
537 self.carousel.add_widget(G.host.getOrClone(previous_slide))
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
538
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
539 self._slides_update_lock -= 1
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
540
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
541
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
542 class WidgetsHandlerLayout(Layout):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
543 count = 0
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
544
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
545 def __init__(self, **kwargs):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
546 super(WidgetsHandlerLayout, self).__init__(**kwargs)
171
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
547 self._layout_size = None # size used for the last layout
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
548 fbind = self.fbind
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
549 update = self._trigger_layout
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
550 fbind('children', update)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
551 fbind('parent', update)
171
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
552 fbind('size', self.adjust_prop)
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
553 fbind('pos', update)
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
554
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
555 @property
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
556 def default_widget(self):
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
557 return G.host.default_wid['factory'](G.host.default_wid, None, None)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
558
171
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
559 def adjust_prop(self, handler, new_size):
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
560 """Adjust children proportion
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
561
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
562 useful when this widget is resized (e.g. when going to fullscreen)
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
563 """
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
564 if len(self.children) > 1:
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
565 old_width, old_height = self._layout_size
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
566 if not old_width or not old_height:
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
567 # we don't want division by zero
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
568 return self._trigger_layout(handler, new_size)
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
569 width_factor = float(self.width) / old_width
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
570 height_factor = float(self.height) / old_height
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
571 for child in self.children:
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
572 child.width *= width_factor
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
573 child.height *= height_factor
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
574 child.x *= width_factor
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
575 child.y *= height_factor
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
576 self._trigger_layout(handler, new_size)
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
577
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
578 def do_layout(self, *args):
171
27b4ceb977c7 widgets handler: keep proportion on resize
Goffi <goffi@goffi.org>
parents: 170
diff changeset
579 self._layout_size = self.size[:]
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
580 for child in self.children:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
581 # XXX: left must be calculated before right and bottom before top
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
582 # because they are the pos, and are used to caculate size (right and top)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
583 # left
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
584 left = child._left_wid
170
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
585 left_end_x = self.x-1 if left is None else left.right
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
586 if child.x != left_end_x + 1 and child._split == "None":
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
587 child.x = left_end_x + 1
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
588 # right
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
589 right = child._right_wid
170
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
590 right_x = self.right + 1 if right is None else right.x
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
591 if child.right != right_x - 1:
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
592 child.width = right_x - child.x - 1
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
593 # bottom
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
594 bottom = child._bottom_wid
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
595 if bottom is None:
170
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
596 if child.y != self.y:
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
597 child.y = self.y
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
598 else:
170
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
599 if child.y != bottom.top + 1:
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
600 child.y = bottom.top + 1
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
601 # top
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
602 top = child._top_wid
170
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
603 top_y = self.top+1 if top is None else top.y
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
604 if child.top != top_y - 1:
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
605 if child._split == "None":
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
606 child.height = top_y - child.y - 1
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
607
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
608 def remove_widget(self, wid):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
609 super(WidgetsHandlerLayout, self).remove_widget(wid)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
610 log.debug("widget deleted ({})".format(wid._wid_idx))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
611
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
612 def add_widget(self, wid=None, index=0):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
613 WidgetsHandlerLayout.count += 1
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
614 if wid is None:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
615 wid = self.default_widget
362
e1f56257cabc core (widgets handler): use widget set in set_widget as selected_widget if selected_widget is None
Goffi <goffi@goffi.org>
parents: 355
diff changeset
616 if G.host.selected_widget is None:
e1f56257cabc core (widgets handler): use widget set in set_widget as selected_widget if selected_widget is None
Goffi <goffi@goffi.org>
parents: 355
diff changeset
617 G.host.selected_widget = wid
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
618 wrapper = WHWrapper(_wid_idx=WidgetsHandlerLayout.count)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
619 log.debug("WHWrapper created ({})".format(wrapper._wid_idx))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
620 wrapper.set_widget(wid)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
621 super(WidgetsHandlerLayout, self).add_widget(wrapper, index)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
622 return wrapper
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
623
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
624
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
625 class WidgetsHandler(WidgetsHandlerLayout):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
626
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
627 def __init__(self, **kw):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
628 super(WidgetsHandler, self).__init__(**kw)
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
629 self.add_widget()