<s> """<STR_LIT>""" <EOL> import wx <EOL> from traits . api import HasTraits , Int , Instance , Str , Callable <EOL> from traitsui . editor import Editor as UIEditor <EOL> from constants import WindowColor , OKColor , ErrorColor <EOL> class Editor ( UIEditor ) : <EOL> """<STR_LIT>""" <EOL> layout_style = Int ( wx . EXPAND ) <EOL> border_size = Int ( <NUM_LIT:4> ) <EOL> def _control_changed ( self , control ) : <EOL> """<STR_LIT>""" <EOL> if control is not None : <EOL> control . _editor = self <EOL> def set_focus ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . control is not None : <EOL> self . control . SetFocus ( ) <EOL> def update_editor ( self ) : <EOL> """<STR_LIT>""" <EOL> new_value = self . str_value <EOL> if self . control . GetValue ( ) != new_value : <EOL> self . control . SetValue ( new_value ) <EOL> def error ( self , excp ) : <EOL> """<STR_LIT>""" <EOL> dlg = wx . MessageDialog ( self . control , str ( excp ) , <EOL> self . description + '<STR_LIT>' , <EOL> wx . OK | wx . ICON_INFORMATION ) <EOL> dlg . ShowModal ( ) <EOL> dlg . Destroy ( ) <EOL> def set_tooltip ( self , control = None ) : <EOL> """<STR_LIT>""" <EOL> desc = self . description <EOL> if desc == '<STR_LIT>' : <EOL> desc = self . object . base_trait ( self . name ) . desc <EOL> if desc is None : <EOL> return False <EOL> desc = '<STR_LIT>' + desc <EOL> if control is None : <EOL> control = self . control <EOL> control . SetToolTipString ( desc ) <EOL> return True <EOL> def _enabled_changed ( self , enabled ) : <EOL> """<STR_LIT>""" <EOL> control = self . control <EOL> if control is not None : <EOL> control . Enable ( enabled ) <EOL> control . Refresh ( ) <EOL> def _visible_changed ( self , visible ) : <EOL> """<STR_LIT>""" <EOL> control = self . control <EOL> parent = control . GetParent ( ) <EOL> sizer = parent . GetSizer ( ) <EOL> from pyface . dock . api import DockSizer <EOL> if isinstance ( sizer , DockSizer ) : <EOL> dock_controls = sizer . GetContents ( ) . get_controls ( False ) <EOL> for dock_control in dock_controls : <EOL> if dock_control . control is control : <EOL> dock_control . visible = visible <EOL> sizer . Layout ( ) <EOL> else : <EOL> if self . label_control is not None : <EOL> self . label_control . Show ( visible ) <EOL> control . Show ( visible ) <EOL> if parent is None : <EOL> control . Layout ( ) <EOL> else : <EOL> parent . Layout ( ) <EOL> def get_error_control ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . control <EOL> def in_error_state ( self ) : <EOL> """<STR_LIT>""" <EOL> return False <EOL> def set_error_state ( self , state = None , control = None ) : <EOL> """<STR_LIT>""" <EOL> if state is None : <EOL> state = self . invalid <EOL> state = state or self . in_error_state ( ) <EOL> if control is None : <EOL> control = self . get_error_control ( ) or [ ] <EOL> if not isinstance ( control , list ) : <EOL> control = [ control ] <EOL> for item in control : <EOL> if state : <EOL> color = ErrorColor <EOL> if getattr ( item , '<STR_LIT>' , None ) is None : <EOL> item . _ok_color = item . GetBackgroundColour ( ) <EOL> else : <EOL> color = getattr ( item , '<STR_LIT>' , None ) <EOL> if color is None : <EOL> color = OKColor <EOL> if isinstance ( item , wx . Panel ) : <EOL> color = WindowColor <EOL> item . SetBackgroundColour ( color ) <EOL> item . Refresh ( ) <EOL> def _invalid_changed ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . set_error_state ( ) <EOL> class EditorWithList ( Editor ) : <EOL> """<STR_LIT>""" <EOL> list_object = Instance ( HasTraits ) <EOL> list_name = Str <EOL> list_value = Callable <EOL> def init ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> factory = self . factory <EOL> name = factory . name <EOL> if name != '<STR_LIT>' : <EOL> self . list_object , self . list_name , self . list_value = self . parse_extended_name ( name ) <EOL> else : <EOL> self . list_object , self . list_name = factory , '<STR_LIT>' <EOL> self . list_value = lambda : factory . values <EOL> self . list_object . on_trait_change ( <EOL> self . _list_updated , self . list_name + '<STR_LIT>' , dispatch = '<STR_LIT>' ) <EOL> self . _list_updated ( ) <EOL> def dispose ( self ) : <EOL> """<STR_LIT>""" <EOL> self . list_object . on_trait_change ( <EOL> self . _list_updated , self . list_name + '<STR_LIT>' , remove = True ) <EOL> super ( EditorWithList , self ) . dispose ( ) <EOL> def _list_updated ( self ) : <EOL> """<STR_LIT>""" <EOL> self . list_updated ( self . list_value ( ) ) <EOL> def list_updated ( self , values ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class EditorFromView ( Editor ) : <EOL> """<STR_LIT>""" <EOL> def init ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> self . _ui = ui = self . init_ui ( parent ) <EOL> if ui . history is None : <EOL> ui . history = self . ui . history <EOL> self . control = ui . control <EOL> def init_ui ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def update_editor ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def dispose ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _ui . dispose ( ) <EOL> super ( EditorFromView , self ) . dispose ( ) </s>
