From bd72cbc5aa586f348d06b1b3ce5676e51c960b3a Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 21 Feb 2021 20:28:41 +0800 Subject: [PATCH] bugfix --- kivyblocks/toolbar.py | 7 +++++-- kivyblocks/widgetExt/scrollwidget.py | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/kivyblocks/toolbar.py b/kivyblocks/toolbar.py index ba64007..cc3cc39 100644 --- a/kivyblocks/toolbar.py +++ b/kivyblocks/toolbar.py @@ -222,19 +222,22 @@ class ToolPage(BGColorBehavior, BoxLayout): name = o.getValue() t = self.get_tool_by_name(name) w = self.content_widgets.get(name) + self.content.clear_widgets() if w is None or t.fresh: if t.url: w = self.build_widget(t.url) self.content_widgets[name] = w + self.content.add_widget(w) return if t.rfname: rf = RegisterFunction() f = rf.get(t.rfname) if f: - return f() + r = f() + if isinstance(r,Widget): + self.content.add_widget(r) return if w: print('toolbar.py: Use old widget') - self.content.clear_widgets() self.content.add_widget(w) diff --git a/kivyblocks/widgetExt/scrollwidget.py b/kivyblocks/widgetExt/scrollwidget.py index a5207c3..ce11dd0 100755 --- a/kivyblocks/widgetExt/scrollwidget.py +++ b/kivyblocks/widgetExt/scrollwidget.py @@ -6,6 +6,7 @@ from kivy.graphics import Color, Ellipse,Rectangle class ScrollWidget(ScrollView): def __init__(self,**kw): super(ScrollWidget,self).__init__(**kw) + self.sized_widgets = [] self._inner = BoxLayout(orientation='vertical',padding=5, spacing=8,size_hint=(None,None)) self._inner.bind( @@ -13,15 +14,30 @@ class ScrollWidget(ScrollView): self._inner.bind( minimum_width=self._inner.setter('width')) super(ScrollWidget,self).add_widget(self._inner) - + self.bind(size=self.change_all_sized_widgets) + + def change_all_sized_widgets(self, *args): + for w in self.sized_widgets: + self.change_widget_width(w) + + def change_widget_width(self, w): + w.size_hint_x = None + w.width = self.width * w.org_size_hint_x + def add_widget(self,widget,**kw): + if widget.size_hint_x: + widget.org_size_hint_x = widget.size_hint_x + self.change_widget_width(widget) + self.sized_widgets.append(widget) a = self._inner.add_widget(widget,**kw) return a def clear_widgets(self,**kw): + self.sized_widgets = [] a = self._inner.clear_widgets(**kw) def remove_widget(self,widget,**kw): + self.sized_widgets = [i for i in self.sized_widgets if i != widget] a = self._inner.remove_widget(widget,**kw) return a