<s> import wx <EOL> from atom . api import Typed <EOL> from enaml . widgets . action_group import ProxyActionGroup <EOL> from . wx_action import WxAction , EVT_ACTION_CHANGED <EOL> from . wx_toolkit_object import WxToolkitObject <EOL> class wxActionGroup ( wx . EvtHandler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent = None ) : <EOL> """<STR_LIT>""" <EOL> super ( wxActionGroup , self ) . __init__ ( ) <EOL> self . _parent = parent <EOL> self . _exclusive = True <EOL> self . _enabled = True <EOL> self . _visible = True <EOL> self . _actions = [ ] <EOL> self . _checked_action = None <EOL> def OnActionChanged ( self , event ) : <EOL> """<STR_LIT>""" <EOL> event . Skip ( ) <EOL> action = event . GetEventObject ( ) <EOL> if action . IsChecked ( ) : <EOL> old_action = self . _checked_action <EOL> self . _checked_action = action <EOL> if self . IsExclusive ( ) : <EOL> if action is not old_action : <EOL> if old_action is not None : <EOL> old_action . SetChecked ( False ) <EOL> def GetParent ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _parent <EOL> def SetParent ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> self . _parent = parent <EOL> def AddAction ( self , action ) : <EOL> """<STR_LIT>""" <EOL> actions = self . _actions <EOL> if action not in actions : <EOL> actions . append ( action ) <EOL> action . Bind ( EVT_ACTION_CHANGED , self . OnActionChanged ) <EOL> parent = action . GetParent ( ) <EOL> if isinstance ( parent , wxActionGroup ) and parent is not self : <EOL> parent . RemoveAction ( action ) <EOL> action . SetParent ( self ) <EOL> if action . IsChecked ( ) : <EOL> old_action = self . _checked_action <EOL> self . _checked_action = action <EOL> if self . IsExclusive ( ) : <EOL> if action is not old_action : <EOL> if old_action is not None : <EOL> old_action . SetChecked ( False ) <EOL> action . _SetGroupEnabled ( self . _enabled ) <EOL> action . _SetGroupVisible ( self . _visible ) <EOL> def RemoveAction ( self , action ) : <EOL> """<STR_LIT>""" <EOL> actions = self . _actions <EOL> if action in actions : <EOL> actions . remove ( action ) <EOL> action . Unbind ( EVT_ACTION_CHANGED , handler = self . OnActionChanged ) <EOL> if action is self . _checked_action : <EOL> self . _checked_action = None <EOL> def GetActions ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _actions <EOL> def GetCheckedAction ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _checked_action <EOL> def IsExclusive ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _exclusive <EOL> def SetExclusive ( self , exclusive ) : <EOL> """<STR_LIT>""" <EOL> if self . _exclusive != exclusive : <EOL> self . _exclusive = exclusive <EOL> if exclusive : <EOL> curr = self . _checked_action <EOL> for action in self . _actions : <EOL> if action is not curr : <EOL> action . SetChecked ( False ) <EOL> def IsEnabled ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _enabled <EOL> def SetEnabled ( self , enabled ) : <EOL> """<STR_LIT>""" <EOL> if self . _enabled != enabled : <EOL> self . _enabled = enabled <EOL> for action in self . _actions : <EOL> action . _SetGroupEnabled ( enabled ) <EOL> def IsVisible ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _visible <EOL> def SetVisible ( self , visible ) : <EOL> """<STR_LIT>""" <EOL> if self . _visible != visible : <EOL> self . _visible = visible <EOL> for action in self . _actions : <EOL> action . _SetGroupVisible ( visible ) <EOL> class WxActionGroup ( WxToolkitObject , ProxyActionGroup ) : <EOL> """<STR_LIT>""" <EOL> widget = Typed ( wxActionGroup ) <EOL> def create_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget = wxActionGroup ( self . parent_widget ( ) ) <EOL> def init_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( WxActionGroup , self ) . init_widget ( ) <EOL> d = self . declaration <EOL> self . set_exclusive ( d . exclusive ) <EOL> self . set_enabled ( d . enabled ) <EOL> self . set_visible ( d . visible ) <EOL> def init_layout ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( WxActionGroup , self ) . init_layout ( ) <EOL> widget = self . widget <EOL> for action in self . actions ( ) : <EOL> widget . addAction ( action ) <EOL> def find_next_action ( self , child ) : <EOL> """<STR_LIT>""" <EOL> found = False <EOL> for dchild in self . children ( ) : <EOL> if found and isinstance ( dchild , WxAction ) : <EOL> return dchild . widget <EOL> else : <EOL> found = child is dchild <EOL> parent = self . parent ( ) <EOL> if parent is not None : <EOL> return parent . find_next_action ( self ) <EOL> def child_added ( self , child ) : <EOL> """<STR_LIT>""" <EOL> super ( WxActionGroup , self ) . child_added ( child ) <EOL> if isinstance ( child , WxAction ) : <EOL> self . widget . AddAction ( child . widget ) <EOL> parent = self . parent ( ) <EOL> if parent is not None : <EOL> before = self . find_next_action ( child ) <EOL> parent . widget . InsertAction ( before , child . widget ) <EOL> def child_removed ( self , child ) : <EOL> """<STR_LIT>""" <EOL> super ( WxActionGroup , self ) . child_removed ( child ) <EOL> if isinstance ( child , WxAction ) and child . widget is not None : <EOL> self . widget . RemoveAction ( child . widget ) <EOL> parent = self . parent ( ) <EOL> if parent is not None : <EOL> parent . widget . RemoveAction ( child . widget ) <EOL> def actions ( self ) : <EOL> """<STR_LIT>""" <EOL> isinst = isinstance <EOL> return [ c . widget ( ) for c in self . children ( ) if isinst ( c , WxAction ) ] <EOL> def set_exclusive ( self , exclusive ) : <EOL> """<STR_LIT>""" <EOL> self . widget . SetExclusive ( exclusive ) <EOL> def set_enabled ( self , enabled ) : <EOL> """<STR_LIT>""" <EOL> self . widget . SetEnabled ( enabled ) <EOL> def set_visible ( self , visible ) : <EOL> """<STR_LIT>""" <EOL> self . widget . SetVisible ( visible ) </s>
