annotate cagou/core/widgets_handler.py @ 382:c7f1176cd2a9

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