<s> """<STR_LIT>""" <EOL> from traits . api import Instance , Str , Any , List , Bool , Undefined , on_trait_change <EOL> from traits . trait_base import user_name_for <EOL> from traitsui . wx . editor import Editor <EOL> from traitsui . basic_editor_factory import BasicEditorFactory <EOL> from traitsui . ui_traits import AView , ATheme <EOL> from themed_vertical_notebook import ThemedVerticalNotebook <EOL> class _ThemedVerticalNotebookEditor ( Editor ) : <EOL> """<STR_LIT>""" <EOL> scrollable = True <EOL> selected_item = Any <EOL> selected_list = List <EOL> notebook = Instance ( ThemedVerticalNotebook ) <EOL> pages = Any ( { } ) <EOL> def init ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> factory = self . factory <EOL> self . notebook = ThemedVerticalNotebook ( ** factory . get ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) . set ( editor = self ) <EOL> self . control = self . notebook . create_control ( parent ) <EOL> self . context_object . on_trait_change ( self . update_editor_item , <EOL> self . extended_name + '<STR_LIT>' , dispatch = '<STR_LIT>' ) <EOL> if factory . multiple_open : <EOL> self . sync_value ( factory . selected , '<STR_LIT>' , '<STR_LIT>' , <EOL> is_list = True ) <EOL> else : <EOL> self . sync_value ( factory . selected , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . set_tooltip ( ) <EOL> def update_editor ( self ) : <EOL> """<STR_LIT>""" <EOL> self . notebook . pages = [ self . _create_page ( object ) <EOL> for object in self . value ] <EOL> def update_editor_item ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . notebook . pages [ event . index : event . index + len ( event . removed ) ] = [ self . _create_page ( object ) for object in event . added ] <EOL> def dispose ( self ) : <EOL> """<STR_LIT>""" <EOL> self . context_object . on_trait_change ( self . update_editor_item , <EOL> self . name + '<STR_LIT>' , remove = True ) <EOL> del self . notebook . pages [ : ] <EOL> super ( _ThemedVerticalNotebookEditor , self ) . dispose ( ) <EOL> def _selected_item_changed ( self , old , new ) : <EOL> """<STR_LIT>""" <EOL> if new is not None : <EOL> self . notebook . open ( self . _find_page ( new ) ) <EOL> elif old is not None : <EOL> self . notebook . close ( self . _find_page ( old ) ) <EOL> def _selected_list_changed ( self , old , new ) : <EOL> """<STR_LIT>""" <EOL> notebook = self . notebook <EOL> for object in old : <EOL> notebook . close ( self . _find_page ( object ) ) <EOL> for object in new : <EOL> notebook . open ( self . _find_page ( object ) ) <EOL> def _selected_list_items_changed ( self , event ) : <EOL> self . _selected_list_changed ( event . removed , event . added ) <EOL> @ on_trait_change ( '<STR_LIT>' ) <EOL> def _page_state_modified ( self , page , name , old , is_open ) : <EOL> if self . factory . multiple_open : <EOL> object = page . data <EOL> if is_open : <EOL> if object not in self . selected_list : <EOL> self . selected_list . append ( object ) <EOL> elif object in self . selected_list : <EOL> self . selected_list . remove ( object ) <EOL> elif is_open : <EOL> self . selected_item = page . data <EOL> else : <EOL> self . selected_item = None <EOL> def _create_page ( self , object ) : <EOL> """<STR_LIT>""" <EOL> page = self . notebook . create_page ( ) . set ( data = object ) <EOL> ui = object . edit_traits ( parent = page . parent , <EOL> view = self . factory . view , <EOL> kind = '<STR_LIT>' ) . set ( <EOL> parent = self . ui ) <EOL> name = '<STR_LIT>' <EOL> page_name = self . factory . page_name <EOL> if page_name [ <NUM_LIT:0> : <NUM_LIT:1> ] == '<STR_LIT:.>' : <EOL> if getattr ( object , page_name [ <NUM_LIT:1> : ] , Undefined ) is not Undefined : <EOL> page . register_name_listener ( object , page_name [ <NUM_LIT:1> : ] ) <EOL> else : <EOL> name = page_name <EOL> if name == '<STR_LIT>' : <EOL> name = user_name_for ( object . __class__ . __name__ ) <EOL> if page . name == '<STR_LIT>' : <EOL> self . pages [ name ] = count = self . pages . get ( name , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> if count > <NUM_LIT:1> : <EOL> name += ( '<STR_LIT>' % count ) <EOL> page . name = name <EOL> page . ui = ui <EOL> return page <EOL> def _find_page ( self , object ) : <EOL> """<STR_LIT>""" <EOL> for page in self . notebook . pages : <EOL> if object is page . data : <EOL> return page <EOL> return None <EOL> class ThemedVerticalNotebookEditor ( BasicEditorFactory ) : <EOL> klass = _ThemedVerticalNotebookEditor <EOL> closed_theme = ATheme <EOL> open_theme = ATheme <EOL> multiple_open = Bool ( False ) <EOL> scrollable = Bool ( False ) <EOL> double_click = Bool ( True ) <EOL> page_name = Str <EOL> view = AView <EOL> selected = Str </s>
