annotate cagou/core/widgets_handler.py @ 170:f4522b7c3318

widgets handler: use widget's top and right
author Goffi <goffi@goffi.org>
date Sun, 29 Apr 2018 12:23:52 +0200
parents ef09dce878c7
children 27b4ceb977c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
126
cd99f70ea592 global file reorganisation:
Goffi <goffi@goffi.org>
parents: 62
diff changeset
5 # Copyright (C) 2016-2018 Jérôme Poisson (goffi@goffi.org)
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # 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
9 # the Free Software Foundation, either version 3 of the License, or
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # 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
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
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
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core import log as logging
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 log = logging.getLogger(__name__)
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
23 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
24 from sat_frontends.quick_frontend import quick_widgets
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
25 from kivy.graphics import Color, Ellipse
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
26 from kivy.uix.layout import Layout
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 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
28 from kivy.uix.stencilview import StencilView
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
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
163
ef09dce878c7 widgets handler: removed constants which are not used anymore
Goffi <goffi@goffi.org>
parents: 160
diff changeset
33
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
34 REMOVE_WID_LIMIT = dp(10)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
35 MIN_WIDTH = MIN_HEIGHT = dp(50)
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
38 class WHWrapper(BoxLayout):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
39 carousel = properties.ObjectProperty(None)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
40 split_size = properties.NumericProperty(dp(1))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
41 split_margin = properties.NumericProperty(dp(2))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
42 split_color = properties.ListProperty([0.8, 0.8, 0.8, 1])
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
43 split_color_move = properties.ListProperty([0.0, 0.8, 0.8, 1])
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
44 split_color_del = properties.ListProperty([0.8, 0.0, 0.0, 1])
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
45 # sp stands for "split point"
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
46 sp_size = properties.NumericProperty(dp(1))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
47 sp_space = properties.NumericProperty(dp(4))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
48 sp_zone = properties.NumericProperty(dp(30))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
49 _split = properties.OptionProperty('None', options=['None', 'left', 'top'])
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
50 _split_del = properties.BooleanProperty(False)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
51
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
52 def __init__(self, **kwargs):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
53 idx = kwargs.pop('_wid_idx')
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
54 self._wid_idx = idx
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
55 super(WHWrapper, self).__init__(**kwargs)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
56 self._former_slide = None
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
57 self.carousel.bind(current_slide=self.onSlideChange)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
58 self._slides_update_lock = False
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
59 self._left_wids = set()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
60 self._top_wids = set()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
61 self._right_wids = set()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
62 self._bottom_wids = set()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
63
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
64 def __repr__(self):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
65 return "WHWrapper_{idx}".format(idx=self._wid_idx)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
66
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
67 def _main_wid(self, wid_list):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
68 """return main widget of a side list
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
69
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
70 main widget is either the widget currently splitter
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
71 or any widget if none is split
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
72 @return (WHWrapper, None): main widget or None
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
73 if there is not widget
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 if not wid_list:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
76 return None
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
77 for wid in wid_list:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
78 if wid._split != 'None':
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
79 return wid
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
80 return next(iter(wid_list))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
81
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
82 @property
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
83 def _left_wid(self):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
84 return self._main_wid(self._left_wids)
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 @property
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
87 def _top_wid(self):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
88 return self._main_wid(self._top_wids)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
89
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
90 @property
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
91 def _right_wid(self):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
92 return self._main_wid(self._right_wids)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
93
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
94 @property
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
95 def _bottom_wid(self):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
96 return self._main_wid(self._bottom_wids)
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
98 @property
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
99 def current_slide(self):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
100 return self.carousel.current_slide
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
101
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
102 def _draw_ellipse(self):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
103 """draw split ellipse"""
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
104 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
105 try:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
106 self.canvas.after.remove(self.ellipse)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
107 except AttributeError:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
108 pass
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
109 if self._split == "top":
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
110 with self.canvas.after:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
111 Color(*color)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
112 self.ellipse = Ellipse(angle_start=90, angle_end=270,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
113 pos=(self.x + self.width/2 - self.sp_zone/2,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
114 self.y + self.height - self.sp_zone/2),
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
115 size=(self.sp_zone, self.sp_zone))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
116 elif self._split == "left":
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
117 with self.canvas.after:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
118 Color(*color)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
119 self.ellipse = Ellipse(angle_end=180,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
120 pos=(self.x + -self.sp_zone/2,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
121 self.y + self.height/2 - self.sp_zone/2),
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
122 size = (self.sp_zone, self.sp_zone))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
123 else:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
124 raise exceptions.InternalError('unexpected split value')
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
126 def on_touch_down(self, touch):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
127 """activate split if touch is on a split zone"""
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
128 if not self.collide_point(*touch.pos):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
129 return
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
130 log.debug("WIDGET IDX: {} (left: {}, top: {}, right: {}, bottom: {}), pos: {}, size: {}".format(
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
131 self._wid_idx,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
132 '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
133 '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
134 '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
135 '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
136 self.pos,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
137 self.size,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
138 ))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
139 touch_rx, touch_ry = self.to_widget(*touch.pos, relative=True)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
140 if (touch_ry <= self.height and
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
141 touch_ry >= self.height - self.split_size - self.split_margin or
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
142 touch_ry <= self.height and
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
143 touch_ry >= self.height - self.sp_zone and
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
144 touch_rx >= self.width/2 - self.sp_zone/2 and
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
145 touch_rx <= self.width/2 + self.sp_zone/2):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
146 # split area is touched, we activate top split mode
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
147 self._split = "top"
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
148 self._draw_ellipse()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
149 elif (touch_rx >= 0 and
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
150 touch_rx <= self.split_size + self.split_margin or
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
151 touch_rx >= 0 and
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
152 touch_rx <= self.sp_zone and
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
153 touch_ry >= self.height/2 - self.sp_zone/2 and
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
154 touch_ry <= self.height/2 + self.sp_zone/2):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
155 # split area is touched, we activate left split mode
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
156 self._split = "left"
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
157 touch.ud['ori_width'] = self.width
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
158 self._draw_ellipse()
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 else:
155
a0e486074d91 widget handler: block carousel swiping when there is only one slide
Goffi <goffi@goffi.org>
parents: 154
diff changeset
160 if len(self.carousel.slides) == 1:
a0e486074d91 widget handler: block carousel swiping when there is only one slide
Goffi <goffi@goffi.org>
parents: 154
diff changeset
161 # we don't want swipe if there is only one slide
a0e486074d91 widget handler: block carousel swiping when there is only one slide
Goffi <goffi@goffi.org>
parents: 154
diff changeset
162 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
163 else:
a0e486074d91 widget handler: block carousel swiping when there is only one slide
Goffi <goffi@goffi.org>
parents: 154
diff changeset
164 return super(WHWrapper, self).on_touch_down(touch)
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
165
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 def on_touch_move(self, touch):
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
167 """handle size change and widget creation on split"""
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
168 if self._split == 'None':
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
169 return super(WHWrapper, self).on_touch_move(touch)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
170
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
171 elif self._split == 'top':
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
172 new_height = touch.y - self.y
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
173
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
174 if new_height < MIN_HEIGHT:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
175 return
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
176
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
177 # we must not pass the top widget/border
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
178 if self._top_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
179 top = next(iter(self._top_wids))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
180 y_limit = top.y + top.height
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
181
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
182 if top.height <= REMOVE_WID_LIMIT:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
183 # 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
184 if not self._split_del and self._top_wids:
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
185 self._split_del = True
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
186 self._draw_ellipse()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
187 else:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
188 if self._split_del:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
189 self._split_del = False
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
190 self._draw_ellipse()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
191 else:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
192 y_limit = self.y + self.height
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
193
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
194 if touch.y >= y_limit:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
195 return
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
196
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
197 # all right, we can change size
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
198 self.height = new_height
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
199 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
200
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
201 if not self._top_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
202 # we are the last widget on the top
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
203 # so we create a new widget
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
204 new_wid = self.parent.add_widget()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
205 self._top_wids.add(new_wid)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
206 new_wid._bottom_wids.add(self)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
207 for w in self._right_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
208 new_wid._right_wids.add(w)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
209 w._left_wids.add(new_wid)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
210 for w in self._left_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
211 new_wid._left_wids.add(w)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
212 w._right_wids.add(new_wid)
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
213
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
214 elif self._split == 'left':
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
215 ori_width = touch.ud['ori_width']
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
216 new_x = touch.x
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
217 new_width = ori_width - (touch.x - touch.ox)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
218
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
219 if new_width < MIN_WIDTH:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
220 return
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
221
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
222 # we must not pass the left widget/border
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
223 if self._left_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
224 left = next(iter(self._left_wids))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
225 x_limit = left.x
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 left.width <= REMOVE_WID_LIMIT:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
228 # 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
229 if not self._split_del and self._left_wids:
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
230 self._split_del = True
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
231 self._draw_ellipse()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
232 else:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
233 if self._split_del:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
234 self._split_del = False
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
235 self._draw_ellipse()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
236 else:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
237 x_limit = self.x
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
238
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
239 if new_x <= x_limit:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
240 return
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
241
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
242 # all right, we can change position/size
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
243 self.x = new_x
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
244 self.width = new_width
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
245 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
246
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
247 if not self._left_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
248 # we are the last widget on the left
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
249 # so we create a new widget
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
250 new_wid = self.parent.add_widget()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
251 self._left_wids.add(new_wid)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
252 new_wid._right_wids.add(self)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
253 for w in self._top_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
254 new_wid._top_wids.add(w)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
255 w._bottom_wids.add(new_wid)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
256 for w in self._bottom_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
257 new_wid._bottom_wids.add(w)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
258 w._top_wids.add(new_wid)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
259
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
260 else:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
261 raise Exception.InternalError('invalid _split value')
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
262
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 def on_touch_up(self, touch):
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
264 if self._split == 'None':
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
265 return super(WHWrapper, self).on_touch_up(touch)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
266 if self._split == 'top':
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
267 # we remove all top widgets in delete zone,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
268 # and update there side widgets list
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
269 for top in self._top_wids.copy():
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
270 if top.height <= REMOVE_WID_LIMIT:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
271 for w in top._top_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
272 w._bottom_wids.remove(top)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
273 w._bottom_wids.update(top._bottom_wids)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
274 for w in top._bottom_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
275 w._top_wids.remove(top)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
276 w._top_wids.update(top._top_wids)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
277 for w in top._left_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
278 w._right_wids.remove(top)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
279 for w in top._right_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
280 w._left_wids.remove(top)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
281 self.parent.remove_widget(top)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
282 elif self._split == 'left':
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
283 # we remove all left widgets in delete zone,
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
284 # and update there side widgets list
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
285 for left in self._left_wids.copy():
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
286 if left.width <= REMOVE_WID_LIMIT:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
287 for w in left._left_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
288 w._right_wids.remove(left)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
289 w._right_wids.update(left._right_wids)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
290 for w in left._right_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
291 w._left_wids.remove(left)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
292 w._left_wids.update(left._left_wids)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
293 for w in left._top_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
294 w._bottom_wids.remove(left)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
295 for w in left._bottom_wids:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
296 w._top_wids.remove(left)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
297 self.parent.remove_widget(left)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
298 self._split = 'None'
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
299 self.canvas.after.remove(self.ellipse)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
300 del self.ellipse
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
301
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
302 def set_widget(self, wid, index=0):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
303 self.carousel.add_widget(wid, index)
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
304
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
305 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
306 """Change currently displayed widget
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
307
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
308 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
309 """
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
310 # slides update need to be blocked to avoid the update in onSlideChange
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
311 # which would mess the removal of current widgets
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
312 self._slides_update_lock = True
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
313 current = self.carousel.current_slide
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
314 for w in self.carousel.slides:
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
315 if w == current or w == new_widget:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
316 continue
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
317 if isinstance(w, quick_widgets.QuickWidget):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
318 G.host.widgets.deleteWidget(w)
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
319 self.carousel.clear_widgets()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
320 self.carousel.add_widget(new_widget)
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
321 self._slides_update_lock = False
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
322 self.updateHiddenSlides()
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
323
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
324 def onSlideChange(self, handler, new_slide):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
325 if isinstance(self._former_slide, quick_widgets.QuickWidget):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
326 G.host.removeVisibleWidget(self._former_slide)
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
327 self._former_slide = new_slide
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
328 if isinstance(new_slide, quick_widgets.QuickWidget):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
329 G.host.addVisibleWidget(new_slide)
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
330 self.updateHiddenSlides()
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
331
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
332 def hiddenList(self, visible_list):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
333 """return widgets of same class as holded one which are hidden
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
334
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
335 @param visible_list(list[QuickWidget]): widgets visible
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
336 @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
337 """
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
338 added = [(w.targets, w.profiles) for w in visible_list] # we want to avoid recreated widgets
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
339 for w in G.host.widgets.getWidgets(self.current_slide.__class__, profiles=self.current_slide.profiles):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
340 if w in visible_list or (w.targets, w.profiles) in added:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
341 continue
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
342 yield w
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
343
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
344 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
345 """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
346
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
347 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
348 @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
349 @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
350 """
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
351 try:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
352 return unicode(widget.target).lower()
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
353 except AttributeError:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
354 return unicode(list(widget.targets)[0]).lower()
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
355
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
356 def updateHiddenSlides(self):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
357 """adjust carousel slides according to visible widgets"""
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
358 if self._slides_update_lock:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
359 return
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
360 if not isinstance(self.carousel.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
361 return
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
362 # lock must be used here to avoid recursions
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
363 self._slides_update_lock = True
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
364 visible_list = G.host.getVisibleList(self.current_slide.__class__)
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
365 hidden = list(self.hiddenList(visible_list))
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
366 slides_sorted = sorted(hidden + [self.carousel.current_slide], key=self.widgets_sort)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
367 to_remove = set(self.carousel.slides).difference({self.carousel.current_slide})
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
368 for w in to_remove:
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
369 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
370 if hidden:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
371 # 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
372 # as the list will be updated on each new visible widget
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
373 current_idx = slides_sorted.index(self.current_slide)
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
374 try:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
375 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
376 except IndexError:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
377 next_slide = slides_sorted[0]
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
378 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
379 if len(hidden)>1:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
380 previous_slide = slides_sorted[current_idx-1]
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
381 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
382
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
383 self._slides_update_lock = False
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
384
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
385
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
386 class WidgetsHandlerLayout(Layout):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
387 count = 0
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
388
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
389 def __init__(self, **kwargs):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
390 super(WidgetsHandlerLayout, self).__init__(**kwargs)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
391 fbind = self.fbind
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
392 update = self._trigger_layout
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
393 fbind('children', update)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
394 fbind('parent', update)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
395 fbind('size', update)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
396 fbind('pos', update)
13
12a189fbb9ba widget handler first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
397
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
398 @property
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
399 def default_widget(self):
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
400 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
401
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
402 def do_layout(self, *args):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
403 for child in self.children:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
404 # XXX: left must be calculated before right and bottom before top
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
405 # 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
406 # left
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
407 left = child._left_wid
170
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
408 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
409 if child.x != left_end_x + 1 and child._split == "None":
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
410 child.x = left_end_x + 1
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
411 # right
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
412 right = child._right_wid
170
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
413 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
414 if child.right != right_x - 1:
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
415 child.width = right_x - child.x - 1
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
416 # bottom
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
417 bottom = child._bottom_wid
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
418 if bottom is None:
170
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
419 if child.y != self.y:
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
420 child.y = self.y
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
421 else:
170
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
422 if child.y != bottom.top + 1:
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
423 child.y = bottom.top + 1
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
424 # top
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
425 top = child._top_wid
170
f4522b7c3318 widgets handler: use widget's top and right
Goffi <goffi@goffi.org>
parents: 163
diff changeset
426 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
427 if child.top != top_y - 1:
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
428 if child._split == "None":
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
429 child.height = top_y - child.y - 1
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
430
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
431 def remove_widget(self, wid):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
432 super(WidgetsHandlerLayout, self).remove_widget(wid)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
433 log.debug("widget deleted ({})".format(wid._wid_idx))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
434
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
435 def add_widget(self, wid=None, index=0):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
436 WidgetsHandlerLayout.count += 1
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
437 if wid is None:
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
438 wid = self.default_widget
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
439 wrapper = WHWrapper(_wid_idx=WidgetsHandlerLayout.count)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
440 log.debug("WHWrapper created ({})".format(wrapper._wid_idx))
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
441 wrapper.set_widget(wid)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
442 super(WidgetsHandlerLayout, self).add_widget(wrapper, index)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
443 return wrapper
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
444
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
445
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
446 class WidgetsHandler(WidgetsHandlerLayout):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
447
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
448 def __init__(self, **kw):
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
449 super(WidgetsHandler, self).__init__(**kw)
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
450 self.wrapper = self.add_widget()
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
451
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
452 @property
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
453 def cagou_widget(self):
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
454 """get holded CagouWidget"""
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
455 return self.wrapper.current_slide