1
# Copyright (c) 2007, Enthought, Inc.
5
This shows how the currently active notebook tab of a ListEditor can be
6
controlled using the ListEditor's 'selected' trait.
8
Note the interaction between the spinner control (for the 'index' trait) and
9
the currently selected notebook tab. Try changing the spinner value, then try
10
clicking on various notebook tabs.
12
Also note that rearranging the notebook tabs (using drag and drop) does not
13
affect the correspondence between the index value and its associated notebook
14
tab. The correspondence is determined by the contents of the 'people' trait,
15
and not by the physical layout of the notebook tabs.
17
Finally, note that the ListEditor will automatically scroll the tabs to make
18
the selected tab completely visible.
21
#-- Imports --------------------------------------------------------------------
24
import HasStrictTraits, Str, Int, Regex, List, Instance, Range
27
import View, VGroup, Item, ListEditor
29
#-- Person Class ---------------------------------------------------------------
31
class Person ( HasStrictTraits ):
36
phone = Regex( value = '000-0000', regex = '\d\d\d[-]\d\d\d\d' )
38
# Traits view definition:
39
traits_view = View( 'name', 'age', 'phone',
41
buttons = [ 'OK', 'Cancel' ] )
43
#-- Sample Data ----------------------------------------------------------------
46
Person( name = 'Dave Chomsky', age = 39, phone = '555-1212' ),
47
Person( name = 'Mike Wakowski', age = 28, phone = '555-3526' ),
48
Person( name = 'Joe Higginbotham', age = 34, phone = '555-6943' ),
49
Person( name = 'Tom Derringer', age = 22, phone = '555-7586' ),
50
Person( name = 'Dick Van Der Hooten', age = 63, phone = '555-3895' ),
51
Person( name = 'Harry McCallum', age = 46, phone = '555-3285' ),
52
Person( name = 'Sally Johnson', age = 43, phone = '555-8797' ),
53
Person( name = 'Fields Timberlawn', age = 31, phone = '555-3547' )
56
#-- ListEditorNotebookSelectionDemo Class --------------------------------------
58
class ListEditorNotebookSelectionDemo ( HasStrictTraits ):
60
#-- Trait Definitions ------------------------------------------------------
63
people = List( Person )
65
# The currently selected person:
66
selected = Instance( Person )
68
# The index of the currently selected person:
69
index = Range( 0, 7, mode = 'spinner' )
71
#-- Traits View Definitions ------------------------------------------------
80
editor = ListEditor( use_notebook = True,
82
selected = 'selected',
83
export = 'DockWindowShell',
87
id = 'traitsui.demo.Traits UI Demo.Advanced.'
88
'List_editor_notebook_selection_demo',
91
#-- Trait Event Handlers ---------------------------------------------------
93
def _selected_changed ( self, selected ):
94
self.index = self.people.index( selected )
96
def _index_changed ( self, index ):
97
self.selected = self.people[ index ]
99
#-- Set Up The Demo ------------------------------------------------------------
101
demo = ListEditorNotebookSelectionDemo( people = people )
103
if __name__ == "__main__":
104
demo.configure_traits()