<s> import wx <EOL> from atom . api import Typed <EOL> from enaml . layout . geometry import Pos , Rect , Size <EOL> from enaml . widgets . window import ProxyWindow <EOL> from . wx_action import wxAction <EOL> from . wx_container import WxContainer <EOL> from . wx_layout_request import EVT_COMMAND_LAYOUT_REQUESTED <EOL> from . wx_single_widget_sizer import wxSingleWidgetSizer <EOL> from . wx_widget import WxWidget <EOL> class wxCustomWindow ( wx . Frame ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( wxCustomWindow , self ) . __init__ ( * args , ** kwargs ) <EOL> self . _central_widget = None <EOL> self . SetSizer ( wxSingleWidgetSizer ( ) ) <EOL> self . Bind ( wx . EVT_MENU , self . OnMenu ) <EOL> self . Bind ( wx . EVT_CLOSE , self . OnClose ) <EOL> def OnMenu ( self , event ) : <EOL> """<STR_LIT>""" <EOL> action = wxAction . FindById ( event . GetId ( ) ) <EOL> if action is not None : <EOL> if action . IsCheckable ( ) : <EOL> action . SetChecked ( event . Checked ( ) ) <EOL> action . Trigger ( ) <EOL> def OnClose ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . Hide ( ) <EOL> def UpdateClientSizeHints ( self ) : <EOL> """<STR_LIT>""" <EOL> sizer = self . GetSizer ( ) <EOL> min_w , min_h = self . ClientToWindowSize ( sizer . CalcMin ( ) ) <EOL> max_w , max_h = self . ClientToWindowSize ( sizer . CalcMax ( ) ) <EOL> self . SetSizeHints ( min_w , min_h , max_w , max_h ) <EOL> cur_w , cur_h = self . GetSize ( ) <EOL> new_w = min ( max_w , max ( min_w , cur_w ) ) <EOL> new_h = min ( max_h , max ( min_h , cur_h ) ) <EOL> if cur_w != new_w or cur_h != new_h : <EOL> self . SetSize ( wx . Size ( new_w , new_h ) ) <EOL> def GetCentralWidget ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _central_widget <EOL> def SetCentralWidget ( self , widget ) : <EOL> """<STR_LIT>""" <EOL> self . _central_widget = widget <EOL> self . GetSizer ( ) . Add ( widget ) <EOL> self . UpdateClientSizeHints ( ) <EOL> class WxWindow ( WxWidget , ProxyWindow ) : <EOL> """<STR_LIT>""" <EOL> widget = Typed ( wxCustomWindow ) <EOL> def create_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget = wxCustomWindow ( self . parent_widget ( ) ) <EOL> def init_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( WxWindow , self ) . init_widget ( ) <EOL> d = self . declaration <EOL> if d . title : <EOL> self . set_title ( d . title ) <EOL> if - <NUM_LIT:1> not in d . initial_size : <EOL> self . widget . SetClientSize ( wx . Size ( * d . initial_size ) ) <EOL> if - <NUM_LIT:1> not in d . initial_position : <EOL> self . widget . Move ( wx . Point ( * d . initial_position ) ) <EOL> if d . icon : <EOL> self . set_icon ( d . icon ) <EOL> self . widget . Bind ( wx . EVT_CLOSE , self . on_close ) <EOL> def init_layout ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( WxWindow , self ) . init_layout ( ) <EOL> widget = self . widget <EOL> widget . SetCentralWidget ( self . central_widget ( ) ) <EOL> widget . Bind ( EVT_COMMAND_LAYOUT_REQUESTED , self . on_layout_requested ) <EOL> def central_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> d = self . declaration . central_widget ( ) <EOL> if d is not None : <EOL> return d . proxy . widget or None <EOL> def child_removed ( self , child ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( child , WxContainer ) : <EOL> self . widget . SetCentralWidget ( self . central_widget ( ) ) <EOL> def child_added ( self , child ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( child , WxContainer ) : <EOL> self . widget . SetCentralWidget ( self . central_widget ( ) ) <EOL> def on_close ( self , event ) : <EOL> """<STR_LIT>""" <EOL> event . Skip ( ) <EOL> self . widget . MakeModal ( False ) <EOL> self . declaration . _handle_close ( ) <EOL> def on_layout_requested ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if self . widget : <EOL> self . widget . UpdateClientSizeHints ( ) <EOL> def set_title ( self , title ) : <EOL> """<STR_LIT>""" <EOL> self . widget . SetTitle ( title ) <EOL> def set_modality ( self , modality ) : <EOL> """<STR_LIT>""" <EOL> if modality == '<STR_LIT>' : <EOL> self . widget . MakeModal ( False ) <EOL> else : <EOL> self . widget . MakeModal ( True ) <EOL> def set_icon ( self , icon ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def position ( self ) : <EOL> """<STR_LIT>""" <EOL> point = self . widget . GetPosition ( ) <EOL> return Pos ( point . x , point . y ) <EOL> def set_position ( self , pos ) : <EOL> """<STR_LIT>""" <EOL> self . widget . SetPosition ( wx . Point ( * pos ) ) <EOL> def size ( self ) : <EOL> """<STR_LIT>""" <EOL> size = self . widget . GetClientSize ( ) <EOL> return Size ( size . GetWidth ( ) , size . GetHeight ( ) ) <EOL> def set_size ( self , size ) : <EOL> """<STR_LIT>""" <EOL> size = wx . Size ( * size ) <EOL> if size . IsFullySpecified ( ) : <EOL> self . widget . SetClientSize ( size ) <EOL> def geometry ( self ) : <EOL> """<STR_LIT>""" <EOL> point = self . widget . GetPosition ( ) <EOL> size = self . widget . GetClientSize ( ) <EOL> return Rect ( point . x , point . y , size . GetWidth ( ) , size . GetHeight ( ) ) <EOL> def set_geometry ( self , rect ) : <EOL> """<STR_LIT>""" <EOL> self . set_position ( rect [ : <NUM_LIT:2> ] ) <EOL> self . set_size ( rect [ <NUM_LIT:2> : ] ) <EOL> def frame_geometry ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . widget . GetRect ( ) <EOL> return Rect ( r . GetX ( ) , r . GetY ( ) , r . GetWidth ( ) , r . GetHeight ( ) ) <EOL> def maximize ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget . Maximize ( True ) <EOL> def minimize ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget . Iconize ( True ) <EOL> def restore ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget . maximize ( False ) <EOL> def send_to_front ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget . Raise ( ) <EOL> def send_to_back ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget . Lower ( ) <EOL> def center_on_screen ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget . CenterOnScreen ( ) <EOL> def center_on_widget ( self , other ) : <EOL> """<STR_LIT>""" <EOL> widget = self . widget <EOL> rect = widget . GetRect ( ) <EOL> geo = other . proxy . widget . GetScreenRect ( ) <EOL> widget . Move ( rect . CenterIn ( geo ) . GetPosition ( ) ) <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget . Close ( ) <EOL> def set_visible ( self , visible ) : <EOL> """<STR_LIT>""" <EOL> modality = self . declaration . modality <EOL> self . widget . MakeModal ( visible and modality != '<STR_LIT>' ) <EOL> self . widget . Show ( visible ) <EOL> def ensure_visible ( self ) : <EOL> """<STR_LIT>""" <EOL> self . set_visible ( True ) <EOL> def ensure_hidden ( self ) : <EOL> """<STR_LIT>""" <EOL> self . set_visible ( False ) </s>
