Added selected_index property to TabView

This commit is contained in:
Jonathan Frederic 2013-10-31 00:26:28 +00:00
parent 19f0372f54
commit 2c3d80c275
2 changed files with 18 additions and 4 deletions

View File

@ -64,6 +64,7 @@ require(["notebook/js/widget"], function(){
render: function(){
this.$el = $('<div />');
var uuid = IPython.utils.uuid();
var that = this;
this.$tabs = $('<div />', {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);

View File

@ -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):