<s> """<STR_LIT>""" <EOL> import sys <EOL> import wx <EOL> from math import log10 <EOL> from traits . api import TraitError , Str , Float , Any , Bool <EOL> from traitsui . editors . range_editor import ToolkitEditorFactory <EOL> from editor_factory import TextEditor <EOL> from editor import Editor <EOL> from constants import OKColor , ErrorColor <EOL> from helper import TraitsUIPanel , Slider <EOL> class BaseRangeEditor ( Editor ) : <EOL> """<STR_LIT>""" <EOL> evaluate = Any <EOL> def _set_value ( self , value ) : <EOL> if self . evaluate is not None : <EOL> value = self . evaluate ( value ) <EOL> Editor . _set_value ( self , value ) <EOL> class SimpleSliderEditor ( BaseRangeEditor ) : <EOL> """<STR_LIT>""" <EOL> low = Any <EOL> high = Any <EOL> format = Str <EOL> ui_changing = Bool ( False ) <EOL> def init ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> factory = self . factory <EOL> if not factory . low_name : <EOL> self . low = factory . low <EOL> if not factory . high_name : <EOL> self . high = factory . high <EOL> self . format = factory . format <EOL> self . evaluate = factory . evaluate <EOL> self . sync_value ( factory . evaluate_name , '<STR_LIT>' , '<STR_LIT>' ) <EOL> size = wx . DefaultSize <EOL> if factory . label_width > <NUM_LIT:0> : <EOL> size = wx . Size ( factory . label_width , <NUM_LIT:20> ) <EOL> self . sync_value ( factory . low_name , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . sync_value ( factory . high_name , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . control = panel = TraitsUIPanel ( parent , - <NUM_LIT:1> ) <EOL> sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> fvalue = self . value <EOL> if not ( self . low <= fvalue <= self . high ) : <EOL> fvalue_text = '<STR_LIT>' <EOL> fvalue = self . low <EOL> else : <EOL> try : <EOL> fvalue_text = self . format % fvalue <EOL> except ( ValueError , TypeError ) , e : <EOL> fvalue_text = '<STR_LIT>' <EOL> ivalue = self . _convert_to_slider ( fvalue ) <EOL> self . _label_lo = wx . StaticText ( panel , - <NUM_LIT:1> , '<STR_LIT>' , size = size , <EOL> style = wx . ALIGN_RIGHT | wx . ST_NO_AUTORESIZE ) <EOL> sizer . Add ( self . _label_lo , <NUM_LIT:0> , wx . ALIGN_CENTER ) <EOL> panel . slider = slider = Slider ( panel , - <NUM_LIT:1> , ivalue , <NUM_LIT:0> , <NUM_LIT> , <EOL> size = wx . Size ( <NUM_LIT> , <NUM_LIT:20> ) , <EOL> style = wx . SL_HORIZONTAL | wx . SL_AUTOTICKS ) <EOL> slider . SetTickFreq ( <NUM_LIT:1000> , <NUM_LIT:1> ) <EOL> slider . SetPageSize ( <NUM_LIT:1000> ) <EOL> slider . SetLineSize ( <NUM_LIT:100> ) <EOL> wx . EVT_SCROLL ( slider , self . update_object_on_scroll ) <EOL> sizer . Add ( slider , <NUM_LIT:1> , wx . EXPAND ) <EOL> self . _label_hi = wx . StaticText ( panel , - <NUM_LIT:1> , '<STR_LIT>' , size = size ) <EOL> sizer . Add ( self . _label_hi , <NUM_LIT:0> , wx . ALIGN_CENTER ) <EOL> panel . text = text = wx . TextCtrl ( panel , - <NUM_LIT:1> , fvalue_text , <EOL> size = wx . Size ( <NUM_LIT> , <NUM_LIT:20> ) , <EOL> style = wx . TE_PROCESS_ENTER ) <EOL> wx . EVT_TEXT_ENTER ( panel , text . GetId ( ) , self . update_object_on_enter ) <EOL> wx . EVT_KILL_FOCUS ( text , self . update_object_on_enter ) <EOL> sizer . Add ( text , <NUM_LIT:0> , wx . LEFT | wx . EXPAND , <NUM_LIT:4> ) <EOL> low_label = factory . low_label <EOL> if factory . low_name != '<STR_LIT>' : <EOL> low_label = self . format % self . low <EOL> high_label = factory . high_label <EOL> if factory . high_name != '<STR_LIT>' : <EOL> high_label = self . format % self . high <EOL> self . _label_lo . SetLabel ( low_label ) <EOL> self . _label_hi . SetLabel ( high_label ) <EOL> self . set_tooltip ( slider ) <EOL> self . set_tooltip ( self . _label_lo ) <EOL> self . set_tooltip ( self . _label_hi ) <EOL> self . set_tooltip ( text ) <EOL> panel . SetSizerAndFit ( sizer ) <EOL> def update_object_on_scroll ( self , event ) : <EOL> """<STR_LIT>""" <EOL> value = self . _convert_from_slider ( event . GetPosition ( ) ) <EOL> event_type = event . GetEventType ( ) <EOL> if ( ( event_type == wx . wxEVT_SCROLL_ENDSCROLL ) or <EOL> ( self . factory . auto_set and <EOL> ( event_type == wx . wxEVT_SCROLL_THUMBTRACK ) ) or <EOL> ( self . factory . enter_set and <EOL> ( event_type == wx . wxEVT_SCROLL_THUMBRELEASE ) ) ) : <EOL> try : <EOL> self . ui_changing = True <EOL> self . control . text . SetValue ( self . format % value ) <EOL> self . value = value <EOL> except TraitError : <EOL> pass <EOL> finally : <EOL> self . ui_changing = False <EOL> def update_object_on_enter ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if self . control is None : <EOL> return <EOL> try : <EOL> try : <EOL> value = self . control . text . GetValue ( ) . strip ( ) <EOL> if self . factory . is_float : <EOL> value = float ( value ) <EOL> else : <EOL> value = int ( value ) <EOL> except Exception as ex : <EOL> value = self . value <EOL> self . control . text . SetValue ( str ( value ) ) <EOL> self . value = value <EOL> if not self . ui_changing : <EOL> self . control . slider . SetValue ( <EOL> self . _convert_to_slider ( self . value ) ) <EOL> self . control . text . SetBackgroundColour ( OKColor ) <EOL> self . control . text . Refresh ( ) <EOL> if self . _error is not None : <EOL> self . _error = None <EOL> self . ui . errors -= <NUM_LIT:1> <EOL> except TraitError : <EOL> pass <EOL> def error ( self , excp ) : <EOL> """<STR_LIT>""" <EOL> if self . _error is None : <EOL> self . _error = True <EOL> self . ui . errors += <NUM_LIT:1> <EOL> super ( SimpleSliderEditor , self ) . error ( excp ) <EOL> self . set_error_state ( True ) <EOL> def update_editor ( self ) : <EOL> """<STR_LIT>""" <EOL> value = self . value <EOL> try : <EOL> text = self . format % value <EOL> <NUM_LIT:1> / ( self . low <= value <= self . high ) <EOL> except : <EOL> text = '<STR_LIT>' <EOL> value = self . low <EOL> ivalue = self . _convert_to_slider ( value ) <EOL> self . control . text . SetValue ( text ) <EOL> self . control . slider . SetValue ( ivalue ) <EOL> def _convert_to_slider ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if self . high > self . low : <EOL> ivalue = int ( ( float ( value - self . low ) / <EOL> ( self . high - self . low ) ) * <NUM_LIT> ) <EOL> else : <EOL> ivalue = self . low <EOL> return ivalue <EOL> def _convert_from_slider ( self , ivalue ) : <EOL> """<STR_LIT>""" <EOL> value = self . low + ( ( float ( ivalue ) / <NUM_LIT> ) * <EOL> ( self . high - self . low ) ) <EOL> if not self . factory . is_float : <EOL> value = int ( round ( value ) ) <EOL> return value <EOL> def get_error_control ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . control . text <EOL> def _low_changed ( self , low ) : <EOL> if self . value < low : <EOL> if self . factory . is_float : <EOL> self . value = float ( low ) <EOL> else : <EOL> self . value = int ( low ) <EOL> if self . _label_lo is not None : <EOL> self . _label_lo . SetLabel ( self . format % low ) <EOL> self . update_editor ( ) <EOL> def _high_changed ( self , high ) : <EOL> if self . value > high : <EOL> if self . factory . is_float : <EOL> self . value = float ( high ) <EOL> else : <EOL> self . value = int ( high ) <EOL> if self . _label_hi is not None : <EOL> self . _label_hi . SetLabel ( self . format % high ) <EOL> self . update_editor ( ) <EOL> class LogRangeSliderEditor ( SimpleSliderEditor ) : <EOL> """<STR_LIT>""" <EOL> def _convert_to_slider ( self , value ) : <EOL> """<STR_LIT>""" <EOL> value = max ( value , self . low ) <EOL> ivalue = int ( ( log10 ( value ) - log10 ( self . low ) ) / <EOL> ( log10 ( self . high ) - log10 ( self . low ) ) * <NUM_LIT> ) <EOL> return ivalue <EOL> def _convert_from_slider ( self , ivalue ) : <EOL> """<STR_LIT>""" <EOL> value = float ( ivalue ) / <NUM_LIT> * ( log10 ( self . high ) - log10 ( self . low ) ) <EOL> fvalue = min ( self . low * <NUM_LIT:10> ** ( value ) , self . high ) <EOL> if not self . factory . is_float : <EOL> fvalue = int ( round ( fvalue ) ) <EOL> return fvalue <EOL> class LargeRangeSliderEditor ( BaseRangeEditor ) : <EOL> """<STR_LIT>""" <EOL> low = Any ( <NUM_LIT:0> ) <EOL> high = Any ( <NUM_LIT:1> ) <EOL> cur_low = Float <EOL> cur_high = Float <EOL> ui_changing = Bool ( False ) <EOL> def init ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> factory = self . factory <EOL> self . low = factory . low <EOL> self . high = factory . high <EOL> self . evaluate = factory . evaluate <EOL> self . sync_value ( factory . low_name , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . sync_value ( factory . high_name , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . sync_value ( factory . evaluate_name , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . init_range ( ) <EOL> low = self . cur_low <EOL> high = self . cur_high <EOL> self . _set_format ( ) <EOL> self . control = panel = TraitsUIPanel ( parent , - <NUM_LIT:1> ) <EOL> sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> fvalue = self . value <EOL> try : <EOL> fvalue_text = self . _format % fvalue <EOL> <NUM_LIT:1> / ( low <= fvalue <= high ) <EOL> except : <EOL> fvalue_text = '<STR_LIT>' <EOL> fvalue = low <EOL> if high > low : <EOL> ivalue = int ( ( float ( fvalue - low ) / ( high - low ) ) * <NUM_LIT> ) <EOL> else : <EOL> ivalue = low <EOL> label_lo = wx . StaticText ( panel , - <NUM_LIT:1> , '<STR_LIT>' ) <EOL> panel . label_lo = label_lo <EOL> sizer . Add ( label_lo , <NUM_LIT:2> , wx . ALIGN_CENTER ) <EOL> bmp = wx . ArtProvider . GetBitmap ( wx . ART_GO_BACK , <EOL> size = ( <NUM_LIT:15> , <NUM_LIT:15> ) ) <EOL> button_lo = wx . BitmapButton ( panel , - <NUM_LIT:1> , bitmap = bmp , size = ( - <NUM_LIT:1> , <NUM_LIT:20> ) , <EOL> style = wx . BU_EXACTFIT | wx . NO_BORDER ) <EOL> panel . button_lo = button_lo <EOL> button_lo . Bind ( wx . EVT_BUTTON , self . reduce_range , button_lo ) <EOL> sizer . Add ( button_lo , <NUM_LIT:1> , wx . ALIGN_CENTER ) <EOL> panel . slider = slider = Slider ( panel , - <NUM_LIT:1> , ivalue , <NUM_LIT:0> , <NUM_LIT> , <EOL> size = wx . Size ( <NUM_LIT> , <NUM_LIT:20> ) , <EOL> style = wx . SL_HORIZONTAL | wx . SL_AUTOTICKS ) <EOL> slider . SetTickFreq ( <NUM_LIT:1000> , <NUM_LIT:1> ) <EOL> slider . SetPageSize ( <NUM_LIT:1000> ) <EOL> slider . SetLineSize ( <NUM_LIT:100> ) <EOL> wx . EVT_SCROLL ( slider , self . update_object_on_scroll ) <EOL> sizer . Add ( slider , <NUM_LIT:6> , wx . EXPAND ) <EOL> bmp = wx . ArtProvider . GetBitmap ( wx . ART_GO_FORWARD , <EOL> size = ( <NUM_LIT:15> , <NUM_LIT:15> ) ) <EOL> button_hi = wx . BitmapButton ( panel , - <NUM_LIT:1> , bitmap = bmp , size = ( - <NUM_LIT:1> , <NUM_LIT:20> ) , <EOL> style = wx . BU_EXACTFIT | wx . NO_BORDER ) <EOL> panel . button_hi = button_hi <EOL> button_hi . Bind ( wx . EVT_BUTTON , self . increase_range , button_hi ) <EOL> sizer . Add ( button_hi , <NUM_LIT:1> , wx . ALIGN_CENTER ) <EOL> label_hi = wx . StaticText ( panel , - <NUM_LIT:1> , '<STR_LIT>' ) <EOL> panel . label_hi = label_hi <EOL> sizer . Add ( label_hi , <NUM_LIT:2> , wx . ALIGN_CENTER ) <EOL> panel . text = text = wx . TextCtrl ( panel , - <NUM_LIT:1> , fvalue_text , <EOL> size = wx . Size ( <NUM_LIT> , <NUM_LIT:20> ) , <EOL> style = wx . TE_PROCESS_ENTER ) <EOL> wx . EVT_TEXT_ENTER ( panel , text . GetId ( ) , self . update_object_on_enter ) <EOL> wx . EVT_KILL_FOCUS ( text , self . update_object_on_enter ) <EOL> sizer . Add ( text , <NUM_LIT:0> , wx . LEFT | wx . EXPAND , <NUM_LIT:4> ) <EOL> panel . SetSizerAndFit ( sizer ) <EOL> label_lo . SetLabel ( str ( low ) ) <EOL> label_hi . SetLabel ( str ( high ) ) <EOL> self . set_tooltip ( slider ) <EOL> self . set_tooltip ( label_lo ) <EOL> self . set_tooltip ( label_hi ) <EOL> self . set_tooltip ( text ) <EOL> self . update_range_ui ( ) <EOL> def update_object_on_scroll ( self , event ) : <EOL> """<STR_LIT>""" <EOL> low = self . cur_low <EOL> high = self . cur_high <EOL> value = low + ( ( float ( event . GetPosition ( ) ) / <NUM_LIT> ) * <EOL> ( high - low ) ) <EOL> self . control . text . SetValue ( self . _format % value ) <EOL> event_type = event . GetEventType ( ) <EOL> try : <EOL> self . ui_changing = True <EOL> if ( ( event_type == wx . wxEVT_SCROLL_ENDSCROLL ) or <EOL> ( self . factory . auto_set and <EOL> ( event_type == wx . wxEVT_SCROLL_THUMBTRACK ) ) or <EOL> ( self . factory . enter_set and <EOL> ( event_type == wx . wxEVT_SCROLL_THUMBRELEASE ) ) ) : <EOL> if self . factory . is_float : <EOL> self . value = value <EOL> else : <EOL> self . value = int ( value ) <EOL> finally : <EOL> self . ui_changing = False <EOL> def update_object_on_enter ( self , event ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> value = self . control . text . GetValue ( ) . strip ( ) <EOL> try : <EOL> if self . factory . is_float : <EOL> value = float ( value ) <EOL> else : <EOL> value = int ( value ) <EOL> except Exception as ex : <EOL> value = self . value <EOL> self . control . text . SetValue ( str ( value ) ) <EOL> self . value = value <EOL> self . control . text . SetBackgroundColour ( OKColor ) <EOL> self . control . text . Refresh ( ) <EOL> if not self . ui_changing : <EOL> self . ui_changing = True <EOL> self . init_range ( ) <EOL> self . update_range_ui ( ) <EOL> self . ui_changing = False <EOL> if self . _error is not None : <EOL> self . _error = None <EOL> self . ui . errors -= <NUM_LIT:1> <EOL> except TraitError as excp : <EOL> pass <EOL> def error ( self , excp ) : <EOL> """<STR_LIT>""" <EOL> if self . _error is None : <EOL> self . _error = True <EOL> self . ui . errors += <NUM_LIT:1> <EOL> super ( LargeRangeSliderEditor , self ) . error ( excp ) <EOL> self . set_error_state ( True ) <EOL> def update_editor ( self ) : <EOL> """<STR_LIT>""" <EOL> value = self . value <EOL> low = self . low <EOL> high = self . high <EOL> try : <EOL> text = self . _format % value <EOL> <NUM_LIT:1> / ( low <= value <= high ) <EOL> except : <EOL> value = low <EOL> self . value = value <EOL> if not self . ui_changing : <EOL> self . init_range ( ) <EOL> self . update_range_ui ( ) <EOL> def update_range_ui ( self ) : <EOL> """<STR_LIT>""" <EOL> low , high = self . cur_low , self . cur_high <EOL> value = self . value <EOL> self . _set_format ( ) <EOL> self . control . label_lo . SetLabel ( self . _format % low ) <EOL> self . control . label_hi . SetLabel ( self . _format % high ) <EOL> if high > low : <EOL> ivalue = int ( ( float ( value - low ) / ( high - low ) ) * <NUM_LIT> ) <EOL> else : <EOL> ivalue = low <EOL> self . control . slider . SetValue ( ivalue ) <EOL> text = self . _format % self . value <EOL> self . control . text . SetValue ( text ) <EOL> factory = self . factory <EOL> f_low , f_high = self . low , self . high <EOL> if low == f_low : <EOL> self . control . button_lo . Disable ( ) <EOL> else : <EOL> self . control . button_lo . Enable ( ) <EOL> if high == f_high : <EOL> self . control . button_hi . Disable ( ) <EOL> else : <EOL> self . control . button_hi . Enable ( ) <EOL> def init_range ( self ) : <EOL> """<STR_LIT>""" <EOL> value = self . value <EOL> factory = self . factory <EOL> low , high = self . low , self . high <EOL> if ( high is None ) and ( low is not None ) : <EOL> high = - low <EOL> mag = abs ( value ) <EOL> if mag <= <NUM_LIT> : <EOL> cur_low = max ( value - <NUM_LIT:10> , low ) <EOL> cur_high = min ( value + <NUM_LIT:10> , high ) <EOL> else : <EOL> d = <NUM_LIT:0.5> * ( <NUM_LIT:10> ** int ( log10 ( mag ) + <NUM_LIT:1> ) ) <EOL> cur_low = max ( low , value - d ) <EOL> cur_high = min ( high , value + d ) <EOL> self . cur_low , self . cur_high = cur_low , cur_high <EOL> def reduce_range ( self , event ) : <EOL> """<STR_LIT>""" <EOL> factory = self . factory <EOL> low , high = self . low , self . high <EOL> if abs ( self . cur_low ) < <NUM_LIT:10> : <EOL> self . cur_low = max ( - <NUM_LIT:10> , low ) <EOL> self . cur_high = min ( <NUM_LIT:10> , high ) <EOL> elif self . cur_low > <NUM_LIT:0> : <EOL> self . cur_high = self . cur_low <EOL> self . cur_low = max ( low , self . cur_low / <NUM_LIT:10> ) <EOL> else : <EOL> self . cur_high = self . cur_low <EOL> self . cur_low = max ( low , self . cur_low * <NUM_LIT:10> ) <EOL> self . ui_changing = True <EOL> self . value = min ( max ( self . value , self . cur_low ) , self . cur_high ) <EOL> self . ui_changing = False <EOL> self . update_range_ui ( ) <EOL> def increase_range ( self , event ) : <EOL> """<STR_LIT>""" <EOL> factory = self . factory <EOL> low , high = self . low , self . high <EOL> if abs ( self . cur_high ) < <NUM_LIT:10> : <EOL> self . cur_low = max ( - <NUM_LIT:10> , low ) <EOL> self . cur_high = min ( <NUM_LIT:10> , high ) <EOL> elif self . cur_high > <NUM_LIT:0> : <EOL> self . cur_low = self . cur_high <EOL> self . cur_high = min ( high , self . cur_high * <NUM_LIT:10> ) <EOL> else : <EOL> self . cur_low = self . cur_high <EOL> self . cur_high = min ( high , self . cur_high / <NUM_LIT:10> ) <EOL> self . ui_changing = True <EOL> self . value = min ( max ( self . value , self . cur_low ) , self . cur_high ) <EOL> self . ui_changing = False <EOL> self . update_range_ui ( ) <EOL> def _set_format ( self ) : <EOL> self . _format = '<STR_LIT>' <EOL> factory = self . factory <EOL> low , high = self . cur_low , self . cur_high <EOL> diff = high - low <EOL> if factory . is_float : <EOL> if diff > <NUM_LIT> : <EOL> self . _format = '<STR_LIT>' <EOL> elif diff > <NUM_LIT:1> : <EOL> self . _format = '<STR_LIT>' % max ( <NUM_LIT:0> , <NUM_LIT:4> - <EOL> int ( log10 ( high - low ) ) ) <EOL> else : <EOL> self . _format = '<STR_LIT>' <EOL> def get_error_control ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . control . text <EOL> def _low_changed ( self , low ) : <EOL> if self . control is not None : <EOL> if self . value < low : <EOL> if self . factory . is_float : <EOL> self . value = float ( low ) <EOL> else : <EOL> self . value = int ( low ) <EOL> self . update_editor ( ) <EOL> def _high_changed ( self , high ) : <EOL> if self . control is not None : <EOL> if self . value > high : <EOL> if self . factory . is_float : <EOL> self . value = float ( high ) <EOL> else : <EOL> self . value = int ( high ) <EOL> self . update_editor ( ) <EOL> class SimpleSpinEditor ( BaseRangeEditor ) : <EOL> """<STR_LIT>""" <EOL> low = Any <EOL> high = Any <EOL> def init ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> factory = self . factory <EOL> if not factory . low_name : <EOL> self . low = factory . low <EOL> if not factory . high_name : <EOL> self . high = factory . high <EOL> self . sync_value ( factory . low_name , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . sync_value ( factory . high_name , '<STR_LIT>' , '<STR_LIT>' ) <EOL> low = self . low <EOL> high = self . high <EOL> self . control = wx . SpinCtrl ( parent , - <NUM_LIT:1> , self . str_value , <EOL> min = low , <EOL> max = high , <EOL> initial = self . value ) <EOL> wx . EVT_SPINCTRL ( parent , self . control . GetId ( ) , self . update_object ) <EOL> wx . EVT_TEXT ( parent , self . control . GetId ( ) , self . update_object ) <EOL> self . set_tooltip ( ) <EOL> def update_object ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . _locked = True <EOL> try : <EOL> self . value = self . control . GetValue ( ) <EOL> finally : <EOL> self . _locked = False <EOL> def update_editor ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _locked : <EOL> try : <EOL> self . control . SetValue ( int ( self . value ) ) <EOL> except : <EOL> pass <EOL> def _low_changed ( self , low ) : <EOL> if self . value < low : <EOL> if self . factory . is_float : <EOL> self . value = float ( low ) <EOL> else : <EOL> self . value = int ( low ) <EOL> if self . control : <EOL> self . control . SetRange ( self . low , self . high ) <EOL> self . control . SetValue ( int ( self . value ) ) <EOL> def _high_changed ( self , high ) : <EOL> if self . value > high : <EOL> if self . factory . is_float : <EOL> self . value = float ( high ) <EOL> else : <EOL> self . value = int ( high ) <EOL> if self . control : <EOL> self . control . SetRange ( self . low , self . high ) <EOL> self . control . SetValue ( int ( self . value ) ) <EOL> class RangeTextEditor ( TextEditor ) : <EOL> """<STR_LIT>""" <EOL> evaluate = Any <EOL> def init ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> if self . factory . enter_set : <EOL> control = wx . TextCtrl ( parent , - <NUM_LIT:1> , self . str_value , <EOL> style = wx . TE_PROCESS_ENTER ) <EOL> wx . EVT_TEXT_ENTER ( parent , control . GetId ( ) , self . update_object ) <EOL> else : <EOL> control = wx . TextCtrl ( parent , - <NUM_LIT:1> , self . str_value ) <EOL> wx . EVT_KILL_FOCUS ( control , self . update_object ) <EOL> if self . factory . auto_set : <EOL> wx . EVT_TEXT ( parent , control . GetId ( ) , self . update_object ) <EOL> self . evaluate = self . factory . evaluate <EOL> self . sync_value ( self . factory . evaluate_name , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . control = control <EOL> self . set_tooltip ( ) <EOL> def update_object ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if self . control is None : <EOL> return <EOL> value = self . control . GetValue ( ) <EOL> try : <EOL> if self . evaluate is not None : <EOL> value = self . evaluate ( value ) <EOL> else : <EOL> if self . factory . is_float : <EOL> value = float ( value ) <EOL> else : <EOL> value = int ( value ) <EOL> except Exception as excp : <EOL> self . error ( excp ) <EOL> return <EOL> try : <EOL> self . value = value <EOL> self . control . SetBackgroundColour ( OKColor ) <EOL> self . control . Refresh ( ) <EOL> if self . _error is not None : <EOL> self . _error = None <EOL> self . ui . errors -= <NUM_LIT:1> <EOL> except TraitError as excp : <EOL> pass <EOL> def error ( self , excp ) : <EOL> """<STR_LIT>""" <EOL> if self . _error is None : <EOL> self . _error = True <EOL> self . ui . errors += <NUM_LIT:1> <EOL> super ( RangeTextEditor , self ) . error ( excp ) <EOL> self . set_error_state ( True ) <EOL> def SimpleEnumEditor ( parent , factory , ui , object , name , description ) : <EOL> return CustomEnumEditor ( parent , factory , ui , object , name , description , <EOL> '<STR_LIT>' ) <EOL> def CustomEnumEditor ( parent , factory , ui , object , name , description , <EOL> style = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if factory . _enum is None : <EOL> import traitsui . editors . enum_editor as enum_editor <EOL> factory . _enum = enum_editor . ToolkitEditorFactory ( <EOL> values = range ( factory . low , factory . high + <NUM_LIT:1> ) , <EOL> cols = factory . cols ) <EOL> if style == '<STR_LIT>' : <EOL> return factory . _enum . simple_editor ( ui , object , name , description , <EOL> parent ) <EOL> return factory . _enum . custom_editor ( ui , object , name , description , parent ) <EOL> SimpleEditorMap = { <EOL> '<STR_LIT>' : SimpleSliderEditor , <EOL> '<STR_LIT>' : LargeRangeSliderEditor , <EOL> '<STR_LIT>' : SimpleSpinEditor , <EOL> '<STR_LIT>' : SimpleEnumEditor , <EOL> '<STR_LIT:text>' : RangeTextEditor , <EOL> '<STR_LIT>' : LogRangeSliderEditor <EOL> } <EOL> CustomEditorMap = { <EOL> '<STR_LIT>' : SimpleSliderEditor , <EOL> '<STR_LIT>' : LargeRangeSliderEditor , <EOL> '<STR_LIT>' : SimpleSpinEditor , <EOL> '<STR_LIT>' : CustomEnumEditor , <EOL> '<STR_LIT:text>' : RangeTextEditor , <EOL> '<STR_LIT>' : LogRangeSliderEditor <EOL> } </s>
