<s> """<STR_LIT>""" <EOL> import wx <EOL> from wx . lib . scrolledpanel import ScrolledPanel as wxScrolledPanel <EOL> from traits . api import HasTraits <EOL> class SwitcherModel ( HasTraits ) : <EOL> """<STR_LIT>""" <EOL> __traits__ = { <EOL> '<STR_LIT>' : - <NUM_LIT:1> , <EOL> } <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . items = [ ] <EOL> return <EOL> def create_page ( self , parent , index ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class SwitcherControl ( wx . Panel ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent , id , model , label = None , ** kw ) : <EOL> """<STR_LIT>""" <EOL> wx . Panel . __init__ ( self , parent , id , ** kw ) <EOL> self . model = model <EOL> self . label = label <EOL> self . _create_widget ( model , label ) <EOL> model . on_trait_change ( self . _on_selected_changed , '<STR_LIT>' ) <EOL> return <EOL> def _on_selected_changed ( self , selected ) : <EOL> """<STR_LIT>""" <EOL> self . combo . SetSelection ( selected ) <EOL> return <EOL> def _on_combobox ( self , event ) : <EOL> """<STR_LIT>""" <EOL> combo = event . GetEventObject ( ) <EOL> self . model . selected = combo . GetSelection ( ) <EOL> return <EOL> def _create_widget ( self , model , label ) : <EOL> """<STR_LIT>""" <EOL> self . sizer = sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> self . SetSizer ( sizer ) <EOL> self . SetAutoLayout ( True ) <EOL> sizer . Add ( self . _combo ( self , model , label ) , <NUM_LIT:1> , wx . EXPAND ) <EOL> sizer . Fit ( self ) <EOL> return <EOL> def _combo ( self , parent , model , label ) : <EOL> """<STR_LIT>""" <EOL> sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> if label is not None : <EOL> text = wx . StaticText ( parent , - <NUM_LIT:1> , label ) <EOL> sizer . Add ( text , <NUM_LIT:0> , wx . ALIGN_CENTER | wx . ALL , <NUM_LIT:5> ) <EOL> self . combo = combo = wx . ComboBox ( <EOL> parent , <EOL> - <NUM_LIT:1> , <EOL> style = wx . CB_DROPDOWN | wx . CB_READONLY <EOL> ) <EOL> sizer . Add ( combo , <NUM_LIT:1> , wx . EXPAND | wx . ALIGN_CENTER | wx . ALL , <NUM_LIT:5> ) <EOL> items = model . items <EOL> if len ( items ) > <NUM_LIT:0> : <EOL> for name , data in model . items : <EOL> combo . Append ( name , data ) <EOL> wx . EVT_COMBOBOX ( self , combo . GetId ( ) , self . _on_combobox ) <EOL> if model . selected != - <NUM_LIT:1> : <EOL> combo . SetSelection ( model . selected ) <EOL> return sizer <EOL> class SwitcherPanel ( wxScrolledPanel ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent , id , model , label = None , cache = True , ** kw ) : <EOL> wxScrolledPanel . __init__ ( self , parent , id , ** kw ) <EOL> self . SetupScrolling ( ) <EOL> self . model = model <EOL> self . cache = cache <EOL> self . _page_cache = { } <EOL> self . current = None <EOL> self . _create_widget ( model , label ) <EOL> model . on_trait_change ( self . _on_selected_changed , '<STR_LIT>' ) <EOL> return <EOL> def _on_selected_changed ( self , selected ) : <EOL> """<STR_LIT>""" <EOL> self . _show_page ( selected ) <EOL> return <EOL> def _create_widget ( self , model , label ) : <EOL> """<STR_LIT>""" <EOL> self . sizer = sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> self . SetSizer ( sizer ) <EOL> self . SetAutoLayout ( True ) <EOL> if model . selected != - <NUM_LIT:1> : <EOL> self . _show_page ( model . selected ) <EOL> pass <EOL> sizer . Fit ( self ) <EOL> return <EOL> def _show_page ( self , index ) : <EOL> """<STR_LIT>""" <EOL> if self . current is not None : <EOL> self . current . Show ( False ) <EOL> self . sizer . Remove ( self . current ) <EOL> page = self . _page_cache . get ( index ) <EOL> if not self . cache or page is None : <EOL> page = self . model . create_page ( self , index ) <EOL> self . _page_cache [ index ] = page <EOL> self . sizer . Add ( page , <NUM_LIT:1> , wx . EXPAND ) <EOL> page . Show ( True ) <EOL> self . current = page <EOL> self . sizer . Layout ( ) <EOL> return <EOL> class Switcher ( wx . Panel ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent , id , model , label = None , ** kw ) : <EOL> wx . Panel . __init__ ( self , parent , id , ** kw ) <EOL> self . model = model <EOL> self . _create_widget ( model , label ) <EOL> return <EOL> def _create_widget ( self , model , label ) : <EOL> """<STR_LIT>""" <EOL> self . sizer = sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> self . SetSizer ( sizer ) <EOL> self . SetAutoLayout ( True ) <EOL> self . control = control = SwitcherControl ( self , - <NUM_LIT:1> , model , label ) <EOL> sizer . Add ( control , <NUM_LIT:0> , wx . EXPAND ) <EOL> self . panel = panel = SwitcherPanel ( self , - <NUM_LIT:1> , model , label ) <EOL> sizer . Add ( panel , <NUM_LIT:1> , wx . EXPAND ) <EOL> sizer . Fit ( self ) <EOL> return </s>
