From c1913d54bb843b3b0c6e933ccb82172a7ffa1858 2014-01-16 10:56:03 From: Jonathan Frederic Date: 2014-01-16 10:56:03 Subject: [PATCH] Added selected_index property to TabView --- diff --git a/IPython/html/static/notebook/js/widgets/multicontainer.js b/IPython/html/static/notebook/js/widgets/multicontainer.js index 6e42751..182b1bd 100644 --- a/IPython/html/static/notebook/js/widgets/multicontainer.js +++ b/IPython/html/static/notebook/js/widgets/multicontainer.js @@ -64,6 +64,7 @@ require(["notebook/js/widget"], function(){ render: function(){ this.$el = $('
'); var uuid = IPython.utils.uuid(); + var that = this; this.$tabs = $('
', {id: uuid}) .addClass('nav') .addClass('nav-tabs') @@ -85,6 +86,11 @@ require(["notebook/js/widget"], function(){ } } + var selected_index = this.model.get('selected_index'); + if (0 <= selected_index && selected_index < this.containers.length) { + this.select_page(selected_index); + } + return IPython.WidgetView.prototype.update.call(this); }, @@ -103,8 +109,9 @@ require(["notebook/js/widget"], function(){ .html('Page ' + index) .appendTo(tab) .click(function (e) { - that.$tabs.find('li') - .removeClass('active'); + that.model.set("selected_index", index); + that.model.update_other_views(that); + that.select_page(index); }); this.containers.push(tab_text); @@ -119,6 +126,12 @@ require(["notebook/js/widget"], function(){ } this.update(); }, + + select_page: function(index) { + this.$tabs.find('li') + .removeClass('active'); + this.containers[index].tab('show'); + }, }); IPython.notebook.widget_manager.register_widget_view('TabView', TabView); diff --git a/IPython/html/widgets/widget_multicontainer.py b/IPython/html/widgets/widget_multicontainer.py index 58f2a5a..49448cb 100644 --- a/IPython/html/widgets/widget_multicontainer.py +++ b/IPython/html/widgets/widget_multicontainer.py @@ -15,7 +15,7 @@ pages. # Imports #----------------------------------------------------------------------------- from widget import Widget -from IPython.utils.traitlets import Unicode, Dict +from IPython.utils.traitlets import Unicode, Dict, Int #----------------------------------------------------------------------------- # Classes @@ -25,8 +25,9 @@ class MulticontainerWidget(Widget): default_view_name = Unicode('TabView') # Keys - _keys = ['_titles'] + _keys = ['_titles', 'selected_index'] _titles = Dict(help="Titles of the pages") + selected_index = Int(0) # Public methods def set_title(self, index, title):