Mercurial > libervia-desktop-kivy
diff cagou/core/widgets_handler.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 |
line wrap: on
line diff
--- a/cagou/core/widgets_handler.py Sat Apr 08 13:34:55 2023 +0200 +++ b/cagou/core/widgets_handler.py Sat Apr 08 13:44:32 2023 +0200 @@ -144,9 +144,9 @@ "former_screen_wid can only be used if ScreenManager is used") if self._former_screen_name is None: return None - return self.getScreenWidget(self._former_screen_name) + return self.get_screen_widget(self._former_screen_name) - def getScreenWidget(self, screen_name): + def get_screen_widget(self, screen_name): """Return screen main widget, handling carousel if necessary""" if self.carousel is not None and screen_name == '': return self.carousel.current_slide @@ -324,7 +324,7 @@ # and update there side widgets list for top in self._top_wids.copy(): if top.height <= REMOVE_WID_LIMIT: - G.host._removeVisibleWidget(top.current_slide) + G.host._remove_visible_widget(top.current_slide) for w in top._top_wids: w._bottom_wids.remove(top) w._bottom_wids.update(top._bottom_wids) @@ -341,7 +341,7 @@ # and update there side widgets list for left in self._left_wids.copy(): if left.width <= REMOVE_WID_LIMIT: - G.host._removeVisibleWidget(left.current_slide) + G.host._remove_visible_widget(left.current_slide) for w in left._left_wids: w._right_wids.remove(left) w._right_wids.update(left._right_wids) @@ -360,7 +360,7 @@ def clear_widgets(self): current_slide = self.current_slide if current_slide is not None: - G.host._removeVisibleWidget(current_slide, ignore_missing=True) + G.host._remove_visible_widget(current_slide, ignore_missing=True) super().clear_widgets() @@ -387,8 +387,8 @@ parent = Screen() self.screen_manager.add_widget(parent) self._former_screen_name = '' - self.screen_manager.bind(current=self.onScreenChange) - wid.screenManagerInit(self.screen_manager) + self.screen_manager.bind(current=self.on_screen_change) + wid.screen_manager_init(self.screen_manager) else: parent = self.main_container @@ -401,15 +401,15 @@ loop = True, ) self._slides_update_lock = 0 - self.carousel.bind(current_slide=self.onSlideChange) + self.carousel.bind(current_slide=self.on_slide_change) parent.add_widget(self.carousel) self.carousel.add_widget(wid, index) else: # no Carousel requested, we add the widget as a direct child parent.add_widget(wid) - G.host._addVisibleWidget(wid) + G.host._add_visible_widget(wid) - def changeWidget(self, new_widget): + def change_widget(self, new_widget): """Change currently displayed widget slides widgets will be updated @@ -419,7 +419,7 @@ # we have the same class, we reuse carousel and screen manager setting if self.carousel.current_slide != new_widget: - # slides update need to be blocked to avoid the update in onSlideChange + # slides update need to be blocked to avoid the update in on_slide_change # which would mess the removal of current widgets self._slides_update_lock += 1 new_wid = None @@ -429,23 +429,23 @@ continue self.carousel.remove_widget(w) if isinstance(w, quick_widgets.QuickWidget): - G.host.widgets.deleteWidget(w) + G.host.widgets.delete_widget(w) if new_wid is None: - new_wid = G.host.getOrClone(new_widget) + new_wid = G.host.get_or_clone(new_widget) self.carousel.add_widget(new_wid) - self._updateHiddenSlides() + self._update_hidden_slides() self._slides_update_lock -= 1 if self.screen_manager is not None: self.screen_manager.clear_widgets([ s for s in self.screen_manager.screens if s.name != '']) - new_wid.screenManagerInit(self.screen_manager) + new_wid.screen_manager_init(self.screen_manager) else: # else, we restart fresh self.clear_widgets() - self.set_widget(G.host.getOrClone(new_widget)) + self.set_widget(G.host.get_or_clone(new_widget)) - def onScreenChange(self, screen_manager, new_screen): + def on_screen_change(self, screen_manager, new_screen): try: new_screen_wid = self.current_slide except IndexError: @@ -453,32 +453,32 @@ log.warning("Switching to a screen without children") if new_screen == '' and self.carousel is not None: # carousel may have been changed in the background, so we update slides - self._updateHiddenSlides() + self._update_hidden_slides() former_screen_wid = self.former_screen_wid if isinstance(former_screen_wid, cagou_widget.CagouWidget): - G.host._removeVisibleWidget(former_screen_wid) + G.host._remove_visible_widget(former_screen_wid) if isinstance(new_screen_wid, cagou_widget.CagouWidget): - G.host._addVisibleWidget(new_screen_wid) + G.host._add_visible_widget(new_screen_wid) self._former_screen_name = new_screen G.host.selected_widget = new_screen_wid - def onSlideChange(self, handler, new_slide): + def on_slide_change(self, handler, new_slide): if self._former_slide is new_slide: # FIXME: workaround for Kivy a95d67f (and above?), Carousel.current_slide - # binding now calls onSlideChange twice with the same widget (here + # binding now calls on_slide_change twice with the same widget (here # "new_slide"). To be checked with Kivy team. return log.debug(f"Slide change: new_slide = {new_slide}") if self._former_slide is not None: - G.host._removeVisibleWidget(self._former_slide, ignore_missing=True) + G.host._remove_visible_widget(self._former_slide, ignore_missing=True) self._former_slide = new_slide if self.carousel_active: G.host.selected_widget = new_slide if new_slide is not None: - G.host._addVisibleWidget(new_slide) - self._updateHiddenSlides() + G.host._add_visible_widget(new_slide) + self._update_hidden_slides() - def hiddenList(self, visible_list, ignore=None): + def hidden_list(self, visible_list, ignore=None): """return widgets of same class as carousel current one, if they are hidden @param visible_list(list[QuickWidget]): widgets visible @@ -488,7 +488,7 @@ # we want to avoid recreated widgets added = [w.widget_hash for w in visible_list] current_slide = self.carousel.current_slide - for w in G.host.widgets.getWidgets(current_slide.__class__, + for w in G.host.widgets.get_widgets(current_slide.__class__, profiles=current_slide.profiles): wid_hash = w.widget_hash if w in visible_list or wid_hash in added: @@ -498,7 +498,7 @@ yield w - def _updateHiddenSlides(self): + def _update_hidden_slides(self): """adjust carousel slides according to visible widgets""" if self._slides_update_lock or not self.carousel_active: return @@ -507,10 +507,10 @@ return # lock must be used here to avoid recursions self._slides_update_lock += 1 - visible_list = G.host.getVisibleList(current_slide.__class__) + visible_list = G.host.get_visible_list(current_slide.__class__) # we ignore current_slide as it may not be visible yet (e.g. if an other # screen is shown - hidden = list(self.hiddenList(visible_list, ignore=current_slide)) + hidden = list(self.hidden_list(visible_list, ignore=current_slide)) slides_sorted = sorted(set(hidden + [current_slide])) to_remove = set(self.carousel.slides).difference({current_slide}) for w in to_remove: @@ -523,10 +523,10 @@ next_slide = slides_sorted[current_idx+1] except IndexError: next_slide = slides_sorted[0] - self.carousel.add_widget(G.host.getOrClone(next_slide)) + self.carousel.add_widget(G.host.get_or_clone(next_slide)) if len(hidden)>1: previous_slide = slides_sorted[current_idx-1] - self.carousel.add_widget(G.host.getOrClone(previous_slide)) + self.carousel.add_widget(G.host.get_or_clone(previous_slide)) self._slides_update_lock -= 1