<s> """<STR_LIT>""" <EOL> import wx <EOL> import wx . lib . newevent <EOL> from . . import options <EOL> from . input_list import InputListPanel <EOL> ( FitterChangedEvent , EVT_FITTER_CHANGED ) = wx . lib . newevent . NewCommandEvent ( ) <EOL> class FitConfig ( wx . Frame ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> parent = None , <EOL> id = wx . ID_ANY , <EOL> title = "<STR_LIT>" , <EOL> pos = wx . DefaultPosition , <EOL> size = wx . DefaultSize , <EOL> style = wx . DEFAULT_DIALOG_STYLE , <EOL> name = "<STR_LIT>" , <EOL> config = None , <EOL> help = None , <EOL> fontsize = None , <EOL> ) : <EOL> wx . Frame . __init__ ( self , parent , id , title , pos , size , style , name ) <EOL> self . config = config <EOL> self . help = help <EOL> pairs = [ ( config . names [ id ] , id ) for id in config . active_ids ] <EOL> self . active_ids = [ id for _ , id in sorted ( pairs ) ] <EOL> if parent is not None : <EOL> font = parent . GetFont ( ) <EOL> self . SetFont ( font ) <EOL> if fontsize is not None : <EOL> font = self . GetFont ( ) <EOL> font . SetPointSize ( fontsize ) <EOL> self . SetFont ( font ) <EOL> self . panel1 = wx . Panel ( self , - <NUM_LIT:1> ) <EOL> static_box1 = wx . StaticBox ( self . panel1 , - <NUM_LIT:1> , "<STR_LIT>" ) <EOL> rows = ( len ( self . active_ids ) + <NUM_LIT:1> ) / <NUM_LIT:2> <EOL> flexsizer = wx . FlexGridSizer ( rows , <NUM_LIT:2> , hgap = <NUM_LIT:20> , vgap = <NUM_LIT:10> ) <EOL> self . fitter_button = { } <EOL> for fitter in self . active_ids : <EOL> button = wx . RadioButton ( self . panel1 , - <NUM_LIT:1> , <EOL> label = config . names [ fitter ] , name = fitter ) <EOL> self . fitter_button [ fitter ] = button <EOL> self . Bind ( wx . EVT_RADIOBUTTON , self . OnRadio , id = button . GetId ( ) ) <EOL> flexsizer . Add ( button , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> fit_hsizer = wx . StaticBoxSizer ( static_box1 , orient = wx . VERTICAL ) <EOL> fit_hsizer . Add ( flexsizer , <NUM_LIT:0> , wx . ALL , <NUM_LIT:5> ) <EOL> self . panel1 . SetSizer ( fit_hsizer ) <EOL> self . vbox = wx . BoxSizer ( wx . VERTICAL ) <EOL> self . vbox . Add ( self . panel1 , <NUM_LIT:0> , wx . ALL , <NUM_LIT:10> ) <EOL> self . fitter_panel = { } <EOL> for fitter in self . active_ids : <EOL> items = [ ( options . FIT_FIELDS [ field ] [ <NUM_LIT:0> ] , <EOL> field , <EOL> config . values [ fitter ] [ field ] , <EOL> options . FIT_FIELDS [ field ] [ <NUM_LIT:1> ] ) <EOL> for field , default in config . settings [ fitter ] ] <EOL> panel = ParameterPanel ( self , items , config . names [ fitter ] ) <EOL> self . fitter_panel [ fitter ] = panel <EOL> self . vbox . Add ( panel , <NUM_LIT:1> , wx . EXPAND | wx . ALL , <NUM_LIT:10> ) <EOL> panel . Hide ( ) <EOL> self . fitter_button [ config . selected_id ] . SetValue ( True ) <EOL> self . fitter_panel [ config . selected_id ] . Show ( ) <EOL> accept_btn = wx . Button ( self , wx . ID_OK ) <EOL> accept_btn . SetToolTipString ( "<STR_LIT>" ) <EOL> accept_btn . SetDefault ( ) <EOL> cancel_btn = wx . Button ( self , wx . ID_CANCEL ) <EOL> cancel_btn . SetToolTipString ( "<STR_LIT>" ) <EOL> if help is not None : <EOL> help_btn = wx . Button ( self , wx . ID_HELP , '<STR_LIT>' ) <EOL> help_btn . SetToolTipString ( "<STR_LIT>" ) <EOL> self . Bind ( wx . EVT_BUTTON , self . OnAccept , accept_btn ) <EOL> self . Bind ( wx . EVT_BUTTON , self . OnCancel , cancel_btn ) <EOL> if help is not None : <EOL> self . Bind ( wx . EVT_BUTTON , self . OnHelp , help_btn ) <EOL> self . Bind ( wx . EVT_CLOSE , self . OnClose ) <EOL> btn_sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> btn_sizer . Add ( ( <NUM_LIT:10> , <NUM_LIT:20> ) , <NUM_LIT:1> ) <EOL> btn_sizer . Add ( accept_btn , <NUM_LIT:0> ) <EOL> btn_sizer . Add ( ( <NUM_LIT:10> , <NUM_LIT:20> ) , <NUM_LIT:0> ) <EOL> btn_sizer . Add ( cancel_btn , <NUM_LIT:0> ) <EOL> btn_sizer . Add ( ( <NUM_LIT:10> , <NUM_LIT:20> ) , <NUM_LIT:0> ) <EOL> if help is not None : <EOL> btn_sizer . Add ( ( <NUM_LIT:10> , <NUM_LIT:20> ) , <NUM_LIT:0> ) <EOL> btn_sizer . Add ( help_btn , <NUM_LIT:0> ) <EOL> self . vbox . Add ( btn_sizer , <NUM_LIT:0> , wx . EXPAND | wx . ALL , <NUM_LIT:10> ) <EOL> self . SetSizer ( self . vbox ) <EOL> self . vbox . Fit ( self ) <EOL> self . Centre ( ) <EOL> def OnRadio ( self , event ) : <EOL> button = event . GetEventObject ( ) <EOL> for panel in self . fitter_panel . values ( ) : <EOL> panel . Hide ( ) <EOL> self . fitter_panel [ button . Name ] . Show ( ) <EOL> self . vbox . Layout ( ) <EOL> def OnCancel ( self , event ) : <EOL> """<STR_LIT>""" <EOL> fitter = self . _get_fitter ( ) <EOL> panel = self . fitter_panel [ fitter ] <EOL> panel . Parameters = dict ( self . config . settings [ fitter ] ) <EOL> self . Hide ( ) <EOL> def OnAccept ( self , event ) : <EOL> """<STR_LIT>""" <EOL> fitter = self . _get_fitter ( ) <EOL> options = self . fitter_panel [ fitter ] . Parameters <EOL> self . config . selected_id = fitter <EOL> self . config . values [ fitter ] = options <EOL> self . Hide ( ) <EOL> event = FitterChangedEvent ( self . Id , config = self . config ) <EOL> wx . PostEvent ( self , event ) <EOL> def OnHelp ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if self . help is not None : <EOL> self . help ( self . _get_fitter ( ) ) <EOL> def OnClose ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if event . CanVeto ( ) : <EOL> self . Hide ( ) <EOL> event . Veto ( ) <EOL> else : <EOL> event . Skip ( ) <EOL> def _get_fitter ( self ) : <EOL> """<STR_LIT>""" <EOL> for button in self . fitter_button . values ( ) : <EOL> if button . Value : <EOL> return button . Name <EOL> else : <EOL> return None <EOL> def _get_options ( self ) : <EOL> fitter = self . _get_fitter ( ) <EOL> options = self . fitter_panel [ fitter ] . Parameters <EOL> return fitter , options <EOL> class ParameterPanel ( wx . Panel ) : <EOL> def __init__ ( self , parent , parameters , fitter_name ) : <EOL> wx . Panel . __init__ ( self , parent = parent , id = wx . ID_ANY ) <EOL> self . fields = [ ] <EOL> itemlist = [ ] <EOL> sbox = wx . StaticBox ( self , wx . ID_ANY , fitter_name + "<STR_LIT>" ) <EOL> for parameter in parameters : <EOL> label , field , curr_value , datatype = parameter <EOL> if not label . endswith ( '<STR_LIT::>' ) : <EOL> label += '<STR_LIT::>' <EOL> if hasattr ( datatype , '<STR_LIT>' ) : <EOL> extra = [ str ( v ) for v in datatype . choices ] <EOL> mode = '<STR_LIT>' <EOL> else : <EOL> mode = '<STR_LIT>' <EOL> extra = None <EOL> sub_list = [ label , curr_value , datatype , mode , extra ] <EOL> itemlist . append ( sub_list ) <EOL> self . fields . append ( field ) <EOL> self . fit_params = InputListPanel ( parent = self , itemlist = itemlist , <EOL> align = True , size = ( - <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> sbox_sizer = wx . StaticBoxSizer ( sbox , wx . VERTICAL ) <EOL> sbox_sizer . Add ( self . fit_params , <NUM_LIT:1> , wx . EXPAND | wx . ALL , <NUM_LIT:5> ) <EOL> self . SetSizer ( sbox_sizer ) <EOL> sbox_sizer . Fit ( self ) <EOL> @ property <EOL> def Parameters ( self ) : <EOL> values = self . fit_params . GetResults ( ) <EOL> return dict ( zip ( self . fields , values ) ) <EOL> @ Parameters . setter <EOL> def Parameters ( self , parameters ) : <EOL> values = [ parameters [ k ] for k in self . fields ] <EOL> self . fit_params . update_items_in_panel ( values ) <EOL> _fit_config_frame = None <EOL> def show_fit_config ( parent , help = None ) : <EOL> global _fit_config_frame <EOL> if _fit_config_frame is None : <EOL> _fit_config_frame = FitConfig ( parent = parent , <EOL> config = options . FIT_CONFIG , help = help ) <EOL> _fit_config_frame . Show ( ) <EOL> _fit_config_frame . Raise ( ) <EOL> return _fit_config_frame <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> opts = options . getopts ( ) <EOL> def _help ( algo ) : <EOL> print ( "<STR_LIT>" + algo ) <EOL> app = wx . App ( ) <EOL> top = wx . Frame ( None ) <EOL> text = wx . TextCtrl ( top , wx . ID_ANY , "<STR_LIT>" ) <EOL> button = wx . Button ( top , wx . ID_ANY , "<STR_LIT>" ) <EOL> button . Bind ( wx . EVT_BUTTON , <EOL> lambda ev : show_fit_config ( top , help = _help ) ) <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> sizer . Add ( text ) <EOL> sizer . Add ( button ) <EOL> sizer . Fit ( top ) <EOL> top . SetSizer ( sizer ) <EOL> top . Show ( ) <EOL> app . MainLoop ( ) </s>
