<s> """<STR_LIT>""" <EOL> import wx <EOL> from traits . api import Bool , Enum , Instance , Str , Tuple <EOL> from pyface . image_cache import ImageCache <EOL> from pyface . action . action_manager import ActionManager <EOL> class ToolBarManager ( ActionManager ) : <EOL> """<STR_LIT>""" <EOL> enabled = Bool ( True ) <EOL> visible = Bool ( True ) <EOL> image_size = Tuple ( ( <NUM_LIT:16> , <NUM_LIT:16> ) ) <EOL> name = Str ( '<STR_LIT>' ) <EOL> orientation = Enum ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> show_tool_names = Bool ( True ) <EOL> show_divider = Bool ( False ) <EOL> _image_cache = Instance ( ImageCache ) <EOL> def __init__ ( self , * args , ** traits ) : <EOL> """<STR_LIT>""" <EOL> super ( ToolBarManager , self ) . __init__ ( * args , ** traits ) <EOL> self . _image_cache = ImageCache ( self . image_size [ <NUM_LIT:0> ] , self . image_size [ <NUM_LIT:1> ] ) <EOL> return <EOL> def create_tool_bar ( self , parent , controller = None ) : <EOL> """<STR_LIT>""" <EOL> if controller is None : <EOL> controller = self . controller <EOL> style = wx . NO_BORDER | wx . TB_FLAT | wx . CLIP_CHILDREN <EOL> if self . show_tool_names : <EOL> style |= wx . TB_TEXT <EOL> if self . orientation == '<STR_LIT>' : <EOL> style |= wx . TB_HORIZONTAL <EOL> else : <EOL> style |= wx . TB_VERTICAL <EOL> if not self . show_divider : <EOL> style |= wx . TB_NODIVIDER <EOL> tool_bar = _ToolBar ( self , parent , - <NUM_LIT:1> , style = style ) <EOL> tool_bar . SetToolBitmapSize ( self . image_size ) <EOL> self . _wx_add_tools ( parent , tool_bar , controller ) <EOL> tool_bar . Realize ( ) <EOL> self . _wx_set_initial_tool_state ( tool_bar ) <EOL> return tool_bar <EOL> def _wx_add_tools ( self , parent , tool_bar , controller ) : <EOL> """<STR_LIT>""" <EOL> previous_non_empty_group = None <EOL> for group in self . groups : <EOL> if len ( group . items ) > <NUM_LIT:0> : <EOL> if previous_non_empty_group is not None and group . separator : <EOL> tool_bar . AddSeparator ( ) <EOL> previous_non_empty_group = group <EOL> for item in group . items : <EOL> item . add_to_toolbar ( <EOL> parent , <EOL> tool_bar , <EOL> self . _image_cache , <EOL> controller , <EOL> self . show_tool_names <EOL> ) <EOL> return <EOL> def _wx_set_initial_tool_state ( self , tool_bar ) : <EOL> """<STR_LIT>""" <EOL> for group in self . groups : <EOL> checked = False <EOL> for item in group . items : <EOL> if item . action . style == '<STR_LIT>' : <EOL> tool_bar . ToggleTool ( item . control_id , item . action . checked ) <EOL> checked = checked or item . action . checked <EOL> else : <EOL> break <EOL> else : <EOL> if not checked and len ( group . items ) > <NUM_LIT:0> : <EOL> group . items [ <NUM_LIT:0> ] . action . checked = True <EOL> return <EOL> class _ToolBar ( wx . ToolBar ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , tool_bar_manager , parent , id , style ) : <EOL> """<STR_LIT>""" <EOL> wx . ToolBar . __init__ ( self , parent , - <NUM_LIT:1> , style = style ) <EOL> self . tool_bar_manager = tool_bar_manager <EOL> self . tool_bar_manager . on_trait_change ( <EOL> self . _on_tool_bar_manager_enabled_changed , '<STR_LIT>' <EOL> ) <EOL> self . tool_bar_manager . on_trait_change ( <EOL> self . _on_tool_bar_manager_visible_changed , '<STR_LIT>' <EOL> ) <EOL> return <EOL> def _on_tool_bar_manager_enabled_changed ( self , obj , trait_name , old , new ) : <EOL> """<STR_LIT>""" <EOL> obj . window . _wx_enable_tool_bar ( self , new ) <EOL> return <EOL> def _on_tool_bar_manager_visible_changed ( self , obj , trait_name , old , new ) : <EOL> """<STR_LIT>""" <EOL> obj . window . _wx_show_tool_bar ( self , new ) <EOL> return </s>
