<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> import wx <EOL> import wx . lib . scrolledpanel as scrolled <EOL> from . util import nice <EOL> from . import signal <EOL> IS_MAC = ( wx . Platform == '<STR_LIT>' ) <EOL> NUMPIX = <NUM_LIT> <EOL> NUMTICKS = NUMPIX * <NUM_LIT:5> - <NUM_LIT:1> <EOL> class SummaryView ( scrolled . ScrolledPanel ) : <EOL> """<STR_LIT>""" <EOL> title = '<STR_LIT>' <EOL> default_size = ( <NUM_LIT> , <NUM_LIT> ) <EOL> def __init__ ( self , * args , ** kw ) : <EOL> scrolled . ScrolledPanel . __init__ ( self , * args , ** kw ) <EOL> self . display_list = [ ] <EOL> self . sizer = wx . GridBagSizer ( hgap = <NUM_LIT:0> , vgap = <NUM_LIT:3> ) <EOL> self . SetSizer ( self . sizer ) <EOL> self . sizer . Fit ( self ) <EOL> self . SetAutoLayout ( True ) <EOL> self . SetupScrolling ( ) <EOL> self . _need_update_parameters = self . _need_update_model = False <EOL> self . Bind ( wx . EVT_SHOW , self . OnShow ) <EOL> def OnShow ( self , event ) : <EOL> if not event . Show : return <EOL> if self . _need_update_model : <EOL> self . update_model ( self . model ) <EOL> elif self . _need_update_parameters : <EOL> self . update_parameters ( self . model ) <EOL> event . Skip ( ) <EOL> def get_state ( self ) : <EOL> return self . model <EOL> def set_state ( self , state ) : <EOL> self . set_model ( state ) <EOL> def set_model ( self , model ) : <EOL> self . model = model <EOL> self . update_model ( model ) <EOL> def update_model ( self , model ) : <EOL> if self . model != model : return <EOL> if not IS_MAC and not self . IsShown ( ) : <EOL> self . _need_update_model = True <EOL> else : <EOL> self . _update_model ( ) <EOL> self . _need_update_parameters = self . _need_update_model = False <EOL> def update_parameters ( self , model ) : <EOL> if self . model != model : return <EOL> if not IS_MAC and not self . IsShown ( ) : <EOL> self . _need_update_parameters = True <EOL> else : <EOL> self . _need_update_parameters = False <EOL> self . _update_parameters ( ) <EOL> def _update_model ( self ) : <EOL> self . sizer . Clear ( deleteWindows = True ) <EOL> self . display_list = [ ] <EOL> self . layer_label = wx . StaticText ( self , wx . ID_ANY , '<STR_LIT>' , <EOL> size = ( <NUM_LIT> , - <NUM_LIT:1> ) ) <EOL> self . slider_label = wx . StaticText ( self , wx . ID_ANY , '<STR_LIT>' , <EOL> size = ( <NUM_LIT:100> , - <NUM_LIT:1> ) ) <EOL> self . value_label = wx . StaticText ( self , wx . ID_ANY , '<STR_LIT>' , <EOL> size = ( <NUM_LIT:100> , - <NUM_LIT:1> ) ) <EOL> self . low_label = wx . StaticText ( self , wx . ID_ANY , '<STR_LIT>' , <EOL> size = ( <NUM_LIT:100> , - <NUM_LIT:1> ) ) <EOL> self . high_label = wx . StaticText ( self , wx . ID_ANY , '<STR_LIT>' , <EOL> size = ( <NUM_LIT:100> , - <NUM_LIT:1> ) ) <EOL> hbox = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> hbox . Add ( self . layer_label , <NUM_LIT:0> , wx . LEFT , <NUM_LIT:1> ) <EOL> hbox . Add ( self . slider_label , <NUM_LIT:0> , wx . LEFT , <NUM_LIT:1> ) <EOL> hbox . Add ( self . value_label , <NUM_LIT:0> , wx . LEFT , <NUM_LIT> ) <EOL> hbox . Add ( self . low_label , <NUM_LIT:0> , wx . LEFT , <NUM_LIT:1> ) <EOL> hbox . Add ( self . high_label , <NUM_LIT:0> , wx . LEFT , <NUM_LIT:1> ) <EOL> self . sizer . Add ( hbox , pos = ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> line = wx . StaticLine ( self , wx . ID_ANY ) <EOL> self . sizer . Add ( line , pos = ( <NUM_LIT:2> , <NUM_LIT:0> ) , flag = wx . EXPAND | wx . RIGHT , border = <NUM_LIT:5> ) <EOL> if self . model is not None : <EOL> pars = self . model . _parameters <EOL> for p in pars : <EOL> self . display_list . append ( ParameterSummary ( self , p , self . model ) ) <EOL> for index , item in enumerate ( self . display_list ) : <EOL> self . sizer . Add ( item , pos = ( index + <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> self . SetupScrolling ( ) <EOL> self . Layout ( ) <EOL> def _update_parameters ( self ) : <EOL> for p in self . display_list : <EOL> p . update_slider ( ) <EOL> class ParameterSummary ( wx . Panel ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent , parameter , model ) : <EOL> wx . Panel . __init__ ( self , parent = parent , id = wx . ID_ANY ) <EOL> self . parameter = parameter <EOL> self . model = model <EOL> self . low , self . high = ( v for v in self . parameter . bounds . limits ) <EOL> text_hbox = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> self . layer_name = wx . StaticText ( self , wx . ID_ANY , <EOL> str ( self . parameter . name ) , <EOL> size = ( <NUM_LIT> , - <NUM_LIT:1> ) , style = wx . TE_LEFT ) <EOL> self . slider = wx . Slider ( self , wx . ID_ANY , <EOL> value = <NUM_LIT:0> , minValue = <NUM_LIT:0> , maxValue = NUMPIX * <NUM_LIT:5> - <NUM_LIT:1> , <EOL> size = ( NUMPIX , <NUM_LIT:16> ) , style = wx . SL_HORIZONTAL ) <EOL> self . value = wx . StaticText ( self , wx . ID_ANY , str ( self . parameter . value ) , <EOL> size = ( <NUM_LIT:100> , - <NUM_LIT:1> ) , style = wx . TE_LEFT ) <EOL> self . min_range = wx . StaticText ( self , wx . ID_ANY , str ( self . low ) , <EOL> size = ( <NUM_LIT:100> , - <NUM_LIT:1> ) , style = wx . TE_LEFT ) <EOL> self . max_range = wx . StaticText ( self , wx . ID_ANY , str ( self . high ) , <EOL> size = ( <NUM_LIT:100> , - <NUM_LIT:1> ) , style = wx . TE_LEFT ) <EOL> text_hbox . Add ( self . layer_name , <NUM_LIT:0> , wx . LEFT , <NUM_LIT:1> ) <EOL> text_hbox . Add ( self . slider , <NUM_LIT:0> , wx . LEFT , <NUM_LIT:1> ) <EOL> text_hbox . Add ( self . value , <NUM_LIT:0> , wx . LEFT , <NUM_LIT> ) <EOL> text_hbox . Add ( self . min_range , <NUM_LIT:0> , wx . LEFT , <NUM_LIT:1> ) <EOL> text_hbox . Add ( self . max_range , <NUM_LIT:0> , wx . LEFT , <NUM_LIT:1> ) <EOL> self . SetSizer ( text_hbox ) <EOL> self . slider . Bind ( wx . EVT_SCROLL , self . OnScroll ) <EOL> self . update_slider ( ) <EOL> def update_slider ( self ) : <EOL> slider_pos = int ( self . parameter . bounds . get01 ( self . parameter . value ) * NUMTICKS ) <EOL> self . slider . SetValue ( slider_pos ) <EOL> self . value . SetLabel ( str ( nice ( self . parameter . value ) ) ) <EOL> newlow , newhigh = ( v for v in self . parameter . bounds . limits ) <EOL> if newlow != self . low : <EOL> self . min_range . SetLabel ( str ( newlow ) ) <EOL> self . max_range . SetLabel ( str ( newhigh ) ) <EOL> def OnScroll ( self , event ) : <EOL> value = self . slider . GetValue ( ) <EOL> new_value = self . parameter . bounds . put01 ( value / NUMTICKS ) <EOL> self . parameter . value = new_value <EOL> self . value . SetLabel ( str ( nice ( new_value ) ) ) <EOL> signal . update_parameters ( model = self . model , delay = <NUM_LIT:1> ) </s>
