Mercurial > libervia-desktop-kivy
comparison cagou/core/cagou_widget.py @ 491:203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:44:32 +0200 |
parents | 3c9ba4a694ef |
children |
comparison
equal
deleted
inserted
replaced
490:962d17c4078c | 491:203755bbe0fe |
---|---|
43 cagou_widget = properties.ObjectProperty() | 43 cagou_widget = properties.ObjectProperty() |
44 plugin_info = properties.ObjectProperty() | 44 plugin_info = properties.ObjectProperty() |
45 | 45 |
46 def __init__(self, **kwargs): | 46 def __init__(self, **kwargs): |
47 super().__init__(**kwargs) | 47 super().__init__(**kwargs) |
48 self.bind(on_release=lambda btn: self.cagou_widget.switchWidget( | 48 self.bind(on_release=lambda btn: self.cagou_widget.switch_widget( |
49 self.plugin_info)) | 49 self.plugin_info)) |
50 | 50 |
51 | 51 |
52 class HeaderChoiceExtraMenu(HeaderChoice): | 52 class HeaderChoiceExtraMenu(HeaderChoice): |
53 pass | 53 pass |
60 class HeaderWidgetSelector(DropDown): | 60 class HeaderWidgetSelector(DropDown): |
61 | 61 |
62 def __init__(self, cagou_widget): | 62 def __init__(self, cagou_widget): |
63 super(HeaderWidgetSelector, self).__init__() | 63 super(HeaderWidgetSelector, self).__init__() |
64 plg_info_cls = cagou_widget.plugin_info_class or cagou_widget.__class__ | 64 plg_info_cls = cagou_widget.plugin_info_class or cagou_widget.__class__ |
65 for plugin_info in G.host.getPluggedWidgets(except_cls=plg_info_cls): | 65 for plugin_info in G.host.get_plugged_widgets(except_cls=plg_info_cls): |
66 choice = HeaderChoiceWidget( | 66 choice = HeaderChoiceWidget( |
67 cagou_widget=cagou_widget, | 67 cagou_widget=cagou_widget, |
68 plugin_info=plugin_info, | 68 plugin_info=plugin_info, |
69 ) | 69 ) |
70 self.add_widget(choice) | 70 self.add_widget(choice) |
100 # plugin info. Useful when a CagouWidget is used with global_screen_manager. | 100 # plugin info. Useful when a CagouWidget is used with global_screen_manager. |
101 plugin_info_class = None | 101 plugin_info_class = None |
102 | 102 |
103 def __init__(self, **kwargs): | 103 def __init__(self, **kwargs): |
104 plg_info_cls = self.plugin_info_class or self.__class__ | 104 plg_info_cls = self.plugin_info_class or self.__class__ |
105 for p in G.host.getPluggedWidgets(): | 105 for p in G.host.get_plugged_widgets(): |
106 if p['main'] == plg_info_cls: | 106 if p['main'] == plg_info_cls: |
107 self.plugin_info = p | 107 self.plugin_info = p |
108 break | 108 break |
109 super().__init__(**kwargs) | 109 super().__init__(**kwargs) |
110 self.selector = HeaderWidgetSelector(self) | 110 self.selector = HeaderWidgetSelector(self) |
113 background_normal=G.host.app.expand( | 113 background_normal=G.host.app.expand( |
114 '{media}/misc/borders/border_hollow_light.png'), | 114 '{media}/misc/borders/border_hollow_light.png'), |
115 multiline=False, | 115 multiline=False, |
116 ) | 116 ) |
117 self.header_input.bind( | 117 self.header_input.bind( |
118 on_text_validate=lambda *args: self.onHeaderInput(), | 118 on_text_validate=lambda *args: self.on_header_wid_input(), |
119 text=self.onHeaderInputComplete, | 119 text=self.on_header_wid_input_complete, |
120 ) | 120 ) |
121 self.header_box.add_widget(self.header_input) | 121 self.header_box.add_widget(self.header_input) |
122 | 122 |
123 def __lt__(self, other): | 123 def __lt__(self, other): |
124 # XXX: sorting is notably used when collection_carousel is set | 124 # XXX: sorting is notably used when collection_carousel is set |
137 and not (self.plugin_info_class is not None | 137 and not (self.plugin_info_class is not None |
138 and self.plugin_info_class.global_screen_manager))): | 138 and self.plugin_info_class.global_screen_manager))): |
139 raise exceptions.InternalError( | 139 raise exceptions.InternalError( |
140 "screen_manager property can't be used if global_screen_manager is not " | 140 "screen_manager property can't be used if global_screen_manager is not " |
141 "set") | 141 "set") |
142 screen = self.getAncestor(Screen) | 142 screen = self.get_ancestor(Screen) |
143 if screen is None: | 143 if screen is None: |
144 raise exceptions.NotFound("Can't find parent Screen") | 144 raise exceptions.NotFound("Can't find parent Screen") |
145 if screen.manager is None: | 145 if screen.manager is None: |
146 raise exceptions.NotFound("Can't find parent ScreenManager") | 146 raise exceptions.NotFound("Can't find parent ScreenManager") |
147 return screen.manager | 147 return screen.manager |
148 | 148 |
149 @property | 149 @property |
150 def whwrapper(self): | 150 def whwrapper(self): |
151 """Retrieve parent widget handler""" | 151 """Retrieve parent widget handler""" |
152 return G.host.getParentWHWrapper(self) | 152 return G.host.get_parent_wh_wrapper(self) |
153 | 153 |
154 def screenManagerInit(self, screen_manager): | 154 def screen_manager_init(self, screen_manager): |
155 """Override this method to do init when ScreenManager is instantiated | 155 """Override this method to do init when ScreenManager is instantiated |
156 | 156 |
157 This is only called once even if collection_carousel is used. | 157 This is only called once even if collection_carousel is used. |
158 """ | 158 """ |
159 if not self.global_screen_manager: | 159 if not self.global_screen_manager: |
160 raise exceptions.InternalError("screenManagerInit should not be called") | 160 raise exceptions.InternalError("screen_manager_init should not be called") |
161 | 161 |
162 def getAncestor(self, cls): | 162 def get_ancestor(self, cls): |
163 """Helper method to use host.getAncestorWidget with self""" | 163 """Helper method to use host.get_ancestor_widget with self""" |
164 return G.host.getAncestorWidget(self, cls) | 164 return G.host.get_ancestor_widget(self, cls) |
165 | 165 |
166 def switchWidget(self, plugin_info): | 166 def switch_widget(self, plugin_info): |
167 self.selector.dismiss() | 167 self.selector.dismiss() |
168 factory = plugin_info["factory"] | 168 factory = plugin_info["factory"] |
169 new_widget = factory(plugin_info, None, iter(G.host.profiles)) | 169 new_widget = factory(plugin_info, None, iter(G.host.profiles)) |
170 G.host.switchWidget(self, new_widget) | 170 G.host.switch_widget(self, new_widget) |
171 | 171 |
172 def key_input(self, window, key, scancode, codepoint, modifier): | 172 def key_input(self, window, key, scancode, codepoint, modifier): |
173 if key == 27: | 173 if key == 27: |
174 # we go back to root screen | 174 # we go back to root screen |
175 G.host.switchWidget(self) | 175 G.host.switch_widget(self) |
176 return True | 176 return True |
177 | 177 |
178 def onHeaderInput(self): | 178 def on_header_wid_input(self): |
179 log.info("header input text entered") | 179 log.info("header input text entered") |
180 | 180 |
181 def onHeaderInputComplete(self, wid, text): | 181 def on_header_wid_input_complete(self, wid, text): |
182 return | 182 return |
183 | 183 |
184 def on_touch_down(self, touch): | 184 def on_touch_down(self, touch): |
185 if self.collide_point(*touch.pos): | 185 if self.collide_point(*touch.pos): |
186 G.host.selected_widget = self | 186 G.host.selected_widget = self |
187 return super(CagouWidget, self).on_touch_down(touch) | 187 return super(CagouWidget, self).on_touch_down(touch) |
188 | 188 |
189 def headerInputAddExtra(self, widget): | 189 def header_input_add_extra(self, widget): |
190 """add a widget on the right of header input""" | 190 """add a widget on the right of header input""" |
191 self.header_box.add_widget(widget) | 191 self.header_box.add_widget(widget) |
192 | 192 |
193 def onVisible(self): | 193 def on_visible(self): |
194 pass | 194 pass |
195 # log.debug(u"{self} is visible".format(self=self)) | 195 # log.debug(u"{self} is visible".format(self=self)) |
196 | 196 |
197 def onNotVisible(self): | 197 def on_not_visible(self): |
198 pass | 198 pass |
199 # log.debug(u"{self} is not visible anymore".format(self=self)) | 199 # log.debug(u"{self} is not visible anymore".format(self=self)) |