diff --git a/examples/widgets/tabbed_panel_showcase.py b/examples/widgets/tabbed_panel_showcase.py index b1d27786c..a7dcfdbf3 100644 --- a/examples/widgets/tabbed_panel_showcase.py +++ b/examples/widgets/tabbed_panel_showcase.py @@ -61,8 +61,8 @@ Builder.load_string(''' FloatLayout: RstDocument: id: default_content - text: 'Standing tabs\\n-------------\\n'+\ - 'Tabs in \\'%s\\' position' %root.tab_pos + text: '\\n'.join(("Standing tabs", "-------------",\ + "Tabs in \\'%s\\' position" %root.tab_pos)) Image: id: tab_2_content pos:self.parent.pos @@ -120,9 +120,9 @@ Builder.load_string(''' FloatLayout: RstDocument: id: default_content - text: 'Closable tabs\\n-------------\\n'+\ - '- The tabs above are also scrollable\\n'+\ - '- Tabs in \\'%s\\' position' %root.tab_pos + text: '\\n'.join(("Closable tabs", "-------------",\ + "- The tabs above are also scrollable",\ + "- Tabs in \\'%s\\' position" %root.tab_pos)) Image: id: tab_2_content pos:self.parent.pos @@ -176,8 +176,8 @@ Builder.load_string(''' FloatLayout: RstDocument: id: default_content - text: 'Normal tabs\\n-------------\\n'+\ - 'Tabs in \\'%s\\' position' %root.tab_pos + text: '\\n'.join(("Normal tabs", "-------------",\ + "Tabs in \\'%s\\' position" %root.tab_pos)) Image: id: tab_2_content pos: self.parent.pos @@ -204,9 +204,9 @@ Builder.load_string(''' FloatLayout: RstDocument: id: default_content - text: 'Image tabs\\n-------------\\n'+\ - '1. Normal image tab\\n2. Image with Text\\n3. Rotated Image'+\ - '\\n4. Tabs in \\'%s\\' position' %root.tab_pos + text: '\\n'.join(("Image tabs","-------------",\ + "1. Normal image tab","2. Image with Text","3. Rotated Image",\ + "4. Tabs in \\'%s\\' position" %root.tab_pos)) Image: id: tab_2_content pos:self.parent.pos diff --git a/kivy/uix/tabbedpanel.py b/kivy/uix/tabbedpanel.py index 8ac95a063..b3c931413 100644 --- a/kivy/uix/tabbedpanel.py +++ b/kivy/uix/tabbedpanel.py @@ -2,6 +2,9 @@ TabbedPanel =========== +.. image:: images/tabbed_panel.jpg + :align: right + .. versionadded:: 1.3.0 .. warning:: @@ -9,12 +12,12 @@ TabbedPanel This widget is still experimental, and its API is subject to change in a future version. -.. image:: images/tabbed_panel.jpg - :align: right +The `TabbedPanel` widget provides you a way to manage different widgets in +each tab. -The `TabbedPanel` widget is exactly what it sounds like, a Tabbed Panel. - -The :class:`TabbedPanel` contains one tab by default. +The :class:`TabbedPanel` auto provides one (default tab) tab and also +automatically deletes it when `default_tab` is changed, thus maintaining +at least one default tab at any given time. Simple example -------------- @@ -332,35 +335,34 @@ class TabbedPanel(GridLayout): parent.remove_widget(header.content) self.add_widget(header.content) - def add_widget(self, *l): + def add_widget(self, widget, index=0): content = self.content if content is None: return - if l[0] == content or l[0] == self._tab_layout: - super(TabbedPanel, self).add_widget(*l) - elif isinstance(l[0], TabbedPanelHeader): + if widget == content or widget == self._tab_layout: + super(TabbedPanel, self).add_widget(widget, index) + elif isinstance(widget, TabbedPanelHeader): self_tabs = self._tab_strip - self_tabs.add_widget(l[0]) - l[0].group = '__tab%r__' % self_tabs.uid - self_tabs.width += l[0].width if not l[0].size_hint_x else\ - self.tab_width - self.reposition_tabs() + self_tab_width = self.tab_width + self_tabs.add_widget(widget) + widget.group = '__tab%r__' % self_tabs.uid + self.on_tab_width() else: - content.add_widget(l[0]) + content.add_widget(widget, index) - def remove_widget(self, *l): + def remove_widget(self, widget): content = self.content if content is None: return - if l[0] == content or l[0] == self._tab_layout: - super(TabbedPanel, self).remove_widget(*l) - elif isinstance(l[0], TabbedPanelHeader): - if l[0]!= self._default_tab: + if widget == content or widget == self._tab_layout: + super(TabbedPanel, self).remove_widget(widget) + elif isinstance(widget, TabbedPanelHeader): + if widget != self._default_tab: self_tabs = self._tab_strip - self_tabs.remove_widget(l[0]) - if l[0].state == 'down': + self_tabs.width -= widget.width + self_tabs.remove_widget(widget) + if widget.state == 'down': self._default_tab.on_release() - self_tabs.width -= l[0].width self.reposition_tabs() else: Logger.info('TabbedPanel: default tab! can\'t be removed.\n' + @@ -414,11 +416,21 @@ class TabbedPanel(GridLayout): def update_tab_width(self, *l): if self.tab_width: - tsw = self.tab_width*len(self._tab_strip.children) + for tab in self.tab_list: + tab.size_hint_x = 1 + tsw = self.tab_width * len(self._tab_strip.children) else: + # tab_width = None tsw = 0 for tab in self.tab_list: - tsw += tab.width + if tab.size_hint_x: + # size_hint_x: x/.xyz + tab.size_hint_x = 1 + #drop to default tab_width + tsw = 100 * len(self._tab_strip.children) + else: + # size_hint_x: None + tsw += tab.width self._tab_strip.width = tsw self.reposition_tabs()