Repository: kivy/kivy

Issue:
In TabbedPanel, custom default_tabs are not deleted when replaced
In a TabbedPanel, the default_tab can be explicitly set to one of the tabs present in the panel.
In this case, the original default tab gets deleted.
However, if the value of the default_tab is changed again, the previous default_tab (i.e. the first custom default_tab) is not deleted.
I find this behavior very disturbing.

I think the relevant code is the following from [TabbedPanel.set_def_tab](https://github.com/kivy/kivy/blob/master/kivy/uix/tabbedpanel.py#L359):

``` python
        if hasattr(self, '_original_tab') and self._original_tab == oltab:
            self.remove_widget(oltab)
            self._original_tab = None
```

The call to remove_widget should be made under all circumstances, and not just when the old default_tab is the one provided by default.



Discussion:
Hello Moreymat,

The reasoning behind the above mentioned behaviour was to only delete the auto-provided tab. The creation and deletion of this tab is automatic, all other tabs have to be manually added/deleted.

 If it seems inconsistent with your needs/situation, you can (this was introduce in the development branch) just disable the default_tab mechanism by setting `do_default_tab` to False

I can see the reasoning behind wanting the same behaviour when changing default_tab to some other tab.
 I think we can go for this as this should not break any existing functionality and only makes the behaviour of changing def_tab consistent

Hi akshayaurora,

Thanks for your answer.

I hope it can indeed be fixed without breaking anything.
Coherence of the default tabs behavior will be enhanced IMHO.

I cannot try the dev branch now, I need to do an internal alpha release these days.
I will definitely try the next stable version with the do_default_tab option and see if it is more appropriate for my use.


Resolving patch:
diff --git a/kivy/uix/tabbedpanel.py b/kivy/uix/tabbedpanel.py
--- a/kivy/uix/tabbedpanel.py
+++ b/kivy/uix/tabbedpanel.py
@@ -26,7 +26,7 @@
 .. note::
 
     A new Class :class:`TabbedPanelItem` has been introduced in 1.5.0 for
-    convineance. So now one can simply add a :class:`TabbedPanelItem` to a
+    conveniance. So now one can simply add a :class:`TabbedPanelItem` to a
     :class:`TabbedPanel` and the `content` to the :class:`TabbedPanelItem`
     like in the example provided above.
 
@@ -72,7 +72,7 @@
 The default tab machinery requires special consideration and management.
 Accordingly, an `on_default_tab` event is provided for associating a callback::
 
-    tp.bind(on_default_tab = my_default_tab_callback)
+    tp.bind(default_tab = my_default_tab_callback)
 
 It's important to note that as by default :data:`default_tab_cls` is of type
 :class:`TabbedPanelHeader` it has the same properties as other tabs.
@@ -342,12 +342,17 @@ def get_tab_list(self):
     '''
 
     content = ObjectProperty(None)
-    '''This is the object holding the content of the current tab.
+    '''This is the object holding(current_tab's content is added to this)
+    the content of the current tab. To Listen to the changes in the content
+    of the current tab you should bind to `current_tab` and then access it's
+    `content` property.
 
     :data:`content` is a :class:`~kivy.properties.ObjectProperty`,
     default to 'None'.
     '''
 
+    _default_tab = ObjectProperty(None)
+
     def get_def_tab(self):
         return self._default_tab
 
@@ -359,17 +364,19 @@ def set_def_tab(self, new_tab):
             return
         oltab = self._default_tab
         self._default_tab = new_tab
-        if hasattr(self, '_original_tab') and self._original_tab == oltab:
-            self.remove_widget(oltab)
-            self._original_tab = None
+        self.remove_widget(oltab)
+        self._original_tab = None
         self.switch_to(new_tab)
         new_tab.state = 'down'
 
-    default_tab = AliasProperty(get_def_tab, set_def_tab)
+    default_tab = AliasProperty(get_def_tab, set_def_tab,
+                                bind=('_default_tab', ))
     '''Holds the default tab.
 
     .. Note:: For convenience, the automatically provided default tab is
               deleted when you change default_tab to something else.
+              As of 1.5.0 This behaviour has been extended to every
+              `default_tab` for consistency not just the auto provided one.
 
     :data:`default_tab` is a :class:`~kivy.properties.AliasProperty`
     '''


Test patch: