<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import time <EOL> import copy <EOL> from functools import partial <EOL> import wx <EOL> import wx . lib . mixins . inspection <EOL> import wx . lib . scrolledpanel as scrolled <EOL> try : <EOL> from wx . _core import PyDeadObjectError <EOL> except : <EOL> PyDeadObjectError = Exception <EOL> import wx . lib . colourselect as csel <EOL> import numpy as np <EOL> import matplotlib <EOL> HAS_PLOT = False <EOL> try : <EOL> from wxmplot import PlotPanel <EOL> HAS_PLOT = True <EOL> except ImportError : <EOL> HAS_PLOT = False <EOL> HAS_DV = False <EOL> try : <EOL> import wx . dataview as dv <EOL> HAS_DV = True <EOL> except : <EOL> pass <EOL> from wxutils import ( SimpleText , EditableListBox , Font , FloatCtrl , <EOL> pack , Popup , Button , get_icon , Check , MenuItem , <EOL> Choice , FileOpen , FileSave , fix_filename , HLine , <EOL> GridPanel , CEN , LEFT , RIGHT ) <EOL> import larch <EOL> from larch_plugins . wx import ( PeriodicTablePanel , XRFDisplayFrame , <EOL> FILE_WILDCARDS , CalibrationFrame ) <EOL> ROI_WILDCARD = '<STR_LIT>' <EOL> larch . use_plugin_path ( '<STR_LIT>' ) <EOL> try : <EOL> from larch_plugins . epics import Epics_MultiXMAP , Epics_Xspress3 <EOL> from scandb import ScanDB <EOL> except : <EOL> pass <EOL> class DetectorSelectDialog ( wx . Dialog ) : <EOL> """<STR_LIT>""" <EOL> msg = '''<STR_LIT>''' <EOL> det_types = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def_prefix = '<STR_LIT>' <EOL> def_nelem = <NUM_LIT:4> <EOL> def __init__ ( self , parent = None , prefix = None , det_type = '<STR_LIT>' , <EOL> is_xsp3 = False , nmca = <NUM_LIT:4> , <EOL> title = '<STR_LIT>' ) : <EOL> if prefix is None : prefix = self . def_prefix <EOL> if det_type not in self . det_types : <EOL> det_type = self . det_types [ <NUM_LIT:0> ] <EOL> wx . Dialog . __init__ ( self , parent , wx . ID_ANY , title = title ) <EOL> self . SetBackgroundColour ( ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> self . SetFont ( Font ( <NUM_LIT:9> ) ) <EOL> if parent is not None : <EOL> self . SetFont ( parent . GetFont ( ) ) <EOL> self . is_xsp3 = Check ( self , size = ( <NUM_LIT> , - <NUM_LIT:1> ) , default = False ) <EOL> self . dettype = Choice ( self , size = ( <NUM_LIT> , - <NUM_LIT:1> ) , choices = self . det_types ) <EOL> self . dettype . SetStringSelection ( det_type ) <EOL> self . prefix = wx . TextCtrl ( self , - <NUM_LIT:1> , prefix , size = ( <NUM_LIT> , - <NUM_LIT:1> ) ) <EOL> self . nelem = FloatCtrl ( self , value = nmca , precision = <NUM_LIT:0> , minval = <NUM_LIT:1> , <EOL> size = ( <NUM_LIT> , - <NUM_LIT:1> ) ) <EOL> btnsizer = wx . StdDialogButtonSizer ( ) <EOL> if wx . Platform != "<STR_LIT>" : <EOL> btn = wx . ContextHelpButton ( self ) <EOL> btnsizer . AddButton ( btn ) <EOL> btn = wx . Button ( self , wx . ID_OK ) <EOL> btn . SetHelpText ( "<STR_LIT>" ) <EOL> btn . SetDefault ( ) <EOL> btnsizer . AddButton ( btn ) <EOL> btn = wx . Button ( self , wx . ID_CANCEL ) <EOL> btnsizer . AddButton ( btn ) <EOL> btnsizer . Realize ( ) <EOL> hline = wx . StaticLine ( self , size = ( <NUM_LIT> , <NUM_LIT:3> ) , style = wx . LI_HORIZONTAL ) <EOL> sty = LEFT | wx . ALIGN_CENTER_VERTICAL <EOL> sizer = wx . GridBagSizer ( <NUM_LIT:5> , <NUM_LIT:2> ) <EOL> def txt ( label ) : <EOL> return SimpleText ( self , label , size = ( <NUM_LIT> , - <NUM_LIT:1> ) , style = LEFT ) <EOL> sizer . Add ( txt ( '<STR_LIT>' ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , sty , <NUM_LIT:2> ) <EOL> sizer . Add ( txt ( '<STR_LIT>' ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , sty , <NUM_LIT:2> ) <EOL> sizer . Add ( txt ( '<STR_LIT>' ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , sty , <NUM_LIT:2> ) <EOL> sizer . Add ( txt ( '<STR_LIT>' ) , ( <NUM_LIT:3> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , sty , <NUM_LIT:2> ) <EOL> sizer . Add ( self . dettype , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , sty , <NUM_LIT:2> ) <EOL> sizer . Add ( self . is_xsp3 , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , sty , <NUM_LIT:2> ) <EOL> sizer . Add ( self . prefix , ( <NUM_LIT:2> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , sty , <NUM_LIT:2> ) <EOL> sizer . Add ( self . nelem , ( <NUM_LIT:3> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , sty , <NUM_LIT:2> ) <EOL> sizer . Add ( hline , ( <NUM_LIT:4> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) , sty , <NUM_LIT:2> ) <EOL> sizer . Add ( btnsizer , ( <NUM_LIT:5> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) , sty , <NUM_LIT:2> ) <EOL> self . SetSizer ( sizer ) <EOL> sizer . Fit ( self ) <EOL> class EpicsXRFDisplayFrame ( XRFDisplayFrame ) : <EOL> _about = """<STR_LIT>""" <EOL> me4_layout = ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> main_title = '<STR_LIT>' <EOL> def __init__ ( self , parent = None , _larch = None , prefix = None , <EOL> det_type = '<STR_LIT>' , is_xsp3 = False , <EOL> nmca = <NUM_LIT:4> , size = ( <NUM_LIT> , <NUM_LIT> ) , scandb_conn = None , <EOL> title = '<STR_LIT>' , <EOL> output_title = '<STR_LIT>' , ** kws ) : <EOL> self . det_type = det_type <EOL> self . is_xsp3 = is_xsp3 <EOL> self . nmca = nmca <EOL> self . det_fore = <NUM_LIT:1> <EOL> self . det_back = <NUM_LIT:0> <EOL> self . scandb = None <EOL> if scandb_conn is not None : <EOL> self . ConnectScanDB ( ** scandb_conn ) <EOL> self . onConnectEpics ( event = None , prefix = prefix ) <EOL> XRFDisplayFrame . __init__ ( self , parent = parent , _larch = _larch , <EOL> title = title , size = size , ** kws ) <EOL> def onConnectEpics ( self , event = None , prefix = None , ** kws ) : <EOL> if prefix is None : <EOL> res = self . prompt_for_detector ( prefix = prefix , <EOL> is_xsp3 = self . is_xsp3 , <EOL> nmca = self . nmca ) <EOL> self . prefix , self . det_type , self . is_xsp3 , self . nmca = res <EOL> else : <EOL> self . prefix = prefix <EOL> self . det_fore = <NUM_LIT:1> <EOL> self . det_back = <NUM_LIT:0> <EOL> self . clear_mcas ( ) <EOL> self . connect_to_detector ( prefix = self . prefix , is_xsp3 = self . is_xsp3 , <EOL> det_type = self . det_type , nmca = self . nmca ) <EOL> def ConnectScanDB ( self , ** kws ) : <EOL> self . scandb = ScanDB ( ** kws ) <EOL> if self . scandb is not None : <EOL> basedir = self . scandb . get_info ( '<STR_LIT>' ) <EOL> fileroot = self . scandb . get_info ( '<STR_LIT>' ) <EOL> basedir = str ( basedir ) <EOL> fileroot = str ( fileroot ) <EOL> if basedir . startswith ( fileroot ) : <EOL> basedir = basedir [ len ( fileroot ) : ] <EOL> fullpath = os . path . join ( fileroot , basedir ) <EOL> fullpath = fullpath . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) . replace ( '<STR_LIT>' , '<STR_LIT:/>' ) <EOL> curdir = os . getcwd ( ) <EOL> try : <EOL> os . chdir ( fullpath ) <EOL> except : <EOL> os . chdir ( curdir ) <EOL> self . scandb . connect_pvs ( ) <EOL> def onSaveMCAFile ( self , event = None , ** kws ) : <EOL> tmp = '''<STR_LIT>''' <EOL> deffile = '<STR_LIT>' <EOL> outfile = FileSave ( self , "<STR_LIT>" , <EOL> default_file = deffile , <EOL> wildcard = FILE_WILDCARDS ) <EOL> environ = [ ] <EOL> if self . scandb is not None : <EOL> c , table = self . scandb . get_table ( '<STR_LIT>' ) <EOL> pvrows = self . scandb . query ( table ) . all ( ) <EOL> for row in pvrows : <EOL> addr = str ( row . name ) <EOL> desc = str ( row . notes ) <EOL> val = self . scandb . pvs [ addr ] . get ( as_string = True ) <EOL> environ . append ( ( addr , val , desc ) ) <EOL> if outfile is not None : <EOL> self . det . save_mcafile ( outfile , environ = environ ) <EOL> def onSaveColumnFile ( self , event = None , ** kws ) : <EOL> print ( '<STR_LIT>' ) <EOL> pass <EOL> def prompt_for_detector ( self , prefix = None , is_xsp3 = False , nmca = <NUM_LIT:4> ) : <EOL> dlg = DetectorSelectDialog ( prefix = prefix , is_xsp3 = is_xsp3 , nmca = nmca ) <EOL> dlg . Raise ( ) <EOL> if dlg . ShowModal ( ) == wx . ID_OK : <EOL> dpref = dlg . prefix . GetValue ( ) <EOL> atype = dlg . is_xsp3 . IsChecked ( ) <EOL> dtype = dlg . dettype . GetStringSelection ( ) <EOL> nmca = dlg . nelem . GetValue ( ) <EOL> dlg . Destroy ( ) <EOL> return dpref , dtype , atype , nmca <EOL> def connect_to_detector ( self , prefix = None , is_xsp3 = False , <EOL> det_type = None , nmca = <NUM_LIT:4> ) : <EOL> self . det = None <EOL> if is_xsp3 : <EOL> self . det = Epics_Xspress3 ( prefix = prefix , nmca = nmca ) <EOL> self . det . connect ( ) <EOL> time . sleep ( <NUM_LIT:0.5> ) <EOL> self . det . get_mca ( mca = <NUM_LIT:1> ) <EOL> self . needs_newplot = True <EOL> else : <EOL> self . det = Epics_MultiXMAP ( prefix = prefix , nmca = nmca ) <EOL> def show_mca ( self , init = False ) : <EOL> self . needs_newplot = False <EOL> if self . mca is None or self . needs_newplot : <EOL> self . mca = self . det . get_mca ( mca = self . det_fore ) <EOL> self . plotmca ( self . mca , set_title = False , init = init ) <EOL> title = "<STR_LIT>" . format ( self . det_fore ) <EOL> if self . det_back > <NUM_LIT:0> : <EOL> if self . mca2 is None : <EOL> self . mca2 = self . det . get_mca ( mca = self . det_back ) <EOL> c2 = self . det . get_array ( mca = self . det_back ) <EOL> e2 = self . det . get_energy ( mca = self . det_back ) <EOL> title = "<STR_LIT>" . format ( title , self . det_back ) <EOL> try : <EOL> self . oplot ( e2 , c2 ) <EOL> except ValueError : <EOL> pass <EOL> roiname = self . get_roiname ( ) <EOL> if roiname in self . wids [ '<STR_LIT>' ] . GetStrings ( ) : <EOL> i = self . wids [ '<STR_LIT>' ] . GetStrings ( ) . index ( roiname ) <EOL> self . wids [ '<STR_LIT>' ] . EnsureVisible ( i ) <EOL> self . onROI ( label = roiname ) <EOL> self . SetTitle ( "<STR_LIT>" % ( self . main_title , title ) ) <EOL> self . needs_newplot = False <EOL> def onSaveROIs ( self , event = None , ** kws ) : <EOL> dlg = wx . FileDialog ( self , message = "<STR_LIT>" , <EOL> defaultDir = os . getcwd ( ) , <EOL> wildcard = ROI_WILDCARD , <EOL> style = wx . FD_SAVE | wx . FD_CHANGE_DIR ) <EOL> if dlg . ShowModal ( ) == wx . ID_OK : <EOL> roifile = dlg . GetPath ( ) <EOL> self . det . save_rois ( roifile ) <EOL> def onRestoreROIs ( self , event = None , ** kws ) : <EOL> dlg = wx . FileDialog ( self , message = "<STR_LIT>" , <EOL> defaultDir = os . getcwd ( ) , <EOL> wildcard = ROI_WILDCARD , <EOL> style = wx . FD_OPEN | wx . FD_CHANGE_DIR ) <EOL> if dlg . ShowModal ( ) == wx . ID_OK : <EOL> roifile = dlg . GetPath ( ) <EOL> self . det . restore_rois ( roifile ) <EOL> self . set_roilist ( mca = self . mca ) <EOL> self . show_mca ( ) <EOL> self . onSelectDet ( event = None , index = <NUM_LIT:0> ) <EOL> def createCustomMenus ( self ) : <EOL> menu = wx . Menu ( ) <EOL> MenuItem ( self , menu , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> self . onConnectEpics ) <EOL> menu . AppendSeparator ( ) <EOL> self . _menus . insert ( <NUM_LIT:1> , ( menu , '<STR_LIT>' ) ) <EOL> def createMainPanel ( self ) : <EOL> epicspanel = self . createEpicsPanel ( ) <EOL> ctrlpanel = self . createControlPanel ( ) <EOL> plotpanel = self . panel = self . createPlotPanel ( ) <EOL> self . panel . SetName ( '<STR_LIT>' ) <EOL> tx , ty = self . wids [ '<STR_LIT>' ] . GetBestSize ( ) <EOL> cx , cy = ctrlpanel . GetBestSize ( ) <EOL> px , py = plotpanel . GetBestSize ( ) <EOL> self . SetSize ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> self . SetMinSize ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> style = wx . ALIGN_LEFT | wx . EXPAND | wx . ALL <EOL> bsizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> bsizer . Add ( ctrlpanel , <NUM_LIT:0> , style , <NUM_LIT:1> ) <EOL> bsizer . Add ( plotpanel , <NUM_LIT:1> , style , <NUM_LIT:1> ) <EOL> hline = wx . StaticLine ( self , size = ( <NUM_LIT> , <NUM_LIT:2> ) , style = wx . LI_HORIZONTAL | style ) <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> sizer . Add ( epicspanel , <NUM_LIT:0> , style , <NUM_LIT:1> ) <EOL> sizer . Add ( hline , <NUM_LIT:0> , style , <NUM_LIT:1> ) <EOL> sizer . Add ( bsizer , <NUM_LIT:1> , style , <NUM_LIT:1> ) <EOL> pack ( self , sizer ) <EOL> self . set_roilist ( mca = None ) <EOL> def createEpicsPanel ( self ) : <EOL> pane = wx . Panel ( self , name = '<STR_LIT>' ) <EOL> psizer = wx . GridBagSizer ( <NUM_LIT:4> , <NUM_LIT:12> ) <EOL> btnpanel = wx . Panel ( pane , name = '<STR_LIT>' ) <EOL> nmca = self . nmca <EOL> NPERROW = <NUM_LIT:6> <EOL> self . SetFont ( Font ( <NUM_LIT:9> ) ) <EOL> if self . det_type . lower ( ) . startswith ( '<STR_LIT>' ) and nmca < <NUM_LIT:5> : <EOL> btnsizer = wx . GridBagSizer ( <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> else : <EOL> btnsizer = wx . GridBagSizer ( int ( ( nmca + NPERROW - <NUM_LIT:2> ) / ( <NUM_LIT:1.0> * NPERROW ) ) , NPERROW ) <EOL> style = wx . ALIGN_LEFT | wx . ALIGN_CENTER_VERTICAL <EOL> rstyle = wx . ALIGN_RIGHT | wx . ALIGN_CENTER_VERTICAL <EOL> bkg_choices = [ '<STR_LIT:None>' ] <EOL> psizer . Add ( SimpleText ( pane , '<STR_LIT>' ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:1> + nmca ) : <EOL> bkg_choices . append ( "<STR_LIT>" % i ) <EOL> b = Button ( btnpanel , '<STR_LIT>' % i , size = ( <NUM_LIT:30> , <NUM_LIT> ) , <EOL> action = partial ( self . onSelectDet , index = i ) ) <EOL> self . wids [ '<STR_LIT>' % i ] = b <EOL> loc = divmod ( i - <NUM_LIT:1> , NPERROW ) <EOL> if self . det_type . lower ( ) . startswith ( '<STR_LIT>' ) and nmca < NPERROW - <NUM_LIT:1> : <EOL> loc = self . me4_layout [ i - <NUM_LIT:1> ] <EOL> btnsizer . Add ( b , loc , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> pack ( btnpanel , btnsizer ) <EOL> nrows = <NUM_LIT:1> + loc [ <NUM_LIT:0> ] <EOL> if self . det_type . lower ( ) . startswith ( '<STR_LIT>' ) and nmca < <NUM_LIT:5> : <EOL> nrows = <NUM_LIT:2> <EOL> psizer . Add ( btnpanel , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( nrows , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> self . wids [ '<STR_LIT>' ] = SimpleText ( pane , '<STR_LIT:U+0020>' , size = ( <NUM_LIT> , - <NUM_LIT:1> ) , style = style ) <EOL> self . wids [ '<STR_LIT>' ] = SimpleText ( pane , '<STR_LIT:U+0020>' , size = ( <NUM_LIT> , - <NUM_LIT:1> ) , style = style ) <EOL> self . wids [ '<STR_LIT>' ] = Choice ( pane , size = ( <NUM_LIT> , - <NUM_LIT:1> ) , choices = bkg_choices , <EOL> action = self . onSelectDet ) <EOL> self . wids [ '<STR_LIT>' ] = FloatCtrl ( pane , value = <NUM_LIT:0.0> , precision = <NUM_LIT:1> , minval = <NUM_LIT:0> , <EOL> size = ( <NUM_LIT> , - <NUM_LIT:1> ) , act_on_losefocus = True , <EOL> action = self . onSetDwelltime ) <EOL> self . wids [ '<STR_LIT>' ] = SimpleText ( pane , '<STR_LIT:U+0020>' , size = ( <NUM_LIT> , - <NUM_LIT:1> ) , style = style ) <EOL> b1 = Button ( pane , '<STR_LIT>' , size = ( <NUM_LIT> , <NUM_LIT> ) , action = self . onStart ) <EOL> b2 = Button ( pane , '<STR_LIT>' , size = ( <NUM_LIT> , <NUM_LIT> ) , action = self . onStop ) <EOL> b3 = Button ( pane , '<STR_LIT>' , size = ( <NUM_LIT> , <NUM_LIT> ) , action = self . onErase ) <EOL> b4 = Button ( pane , '<STR_LIT>' , size = ( <NUM_LIT> , <NUM_LIT> ) , action = partial ( self . onStart , <EOL> dtime = <NUM_LIT:0> ) ) <EOL> bkg_lab = SimpleText ( pane , '<STR_LIT>' , size = ( <NUM_LIT> , - <NUM_LIT:1> ) ) <EOL> pre_lab = SimpleText ( pane , '<STR_LIT>' , size = ( <NUM_LIT> , - <NUM_LIT:1> ) ) <EOL> ela_lab = SimpleText ( pane , '<STR_LIT>' , size = ( <NUM_LIT> , - <NUM_LIT:1> ) ) <EOL> sta_lab = SimpleText ( pane , '<STR_LIT>' , size = ( <NUM_LIT:100> , - <NUM_LIT:1> ) ) <EOL> dea_lab = SimpleText ( pane , '<STR_LIT>' , size = ( <NUM_LIT:100> , - <NUM_LIT:1> ) ) <EOL> psizer . Add ( bkg_lab , ( <NUM_LIT:0> , <NUM_LIT:2> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> psizer . Add ( self . wids [ '<STR_LIT>' ] , ( <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> psizer . Add ( pre_lab , ( <NUM_LIT:0> , <NUM_LIT:3> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> psizer . Add ( ela_lab , ( <NUM_LIT:1> , <NUM_LIT:3> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> psizer . Add ( self . wids [ '<STR_LIT>' ] , ( <NUM_LIT:0> , <NUM_LIT:4> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> psizer . Add ( self . wids [ '<STR_LIT>' ] , ( <NUM_LIT:1> , <NUM_LIT:4> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> psizer . Add ( b1 , ( <NUM_LIT:0> , <NUM_LIT:5> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> psizer . Add ( b4 , ( <NUM_LIT:0> , <NUM_LIT:6> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> psizer . Add ( b2 , ( <NUM_LIT:1> , <NUM_LIT:5> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> psizer . Add ( b3 , ( <NUM_LIT:1> , <NUM_LIT:6> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> psizer . Add ( sta_lab , ( <NUM_LIT:0> , <NUM_LIT:7> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> psizer . Add ( self . wids [ '<STR_LIT>' ] , ( <NUM_LIT:0> , <NUM_LIT:8> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> psizer . Add ( dea_lab , ( <NUM_LIT:1> , <NUM_LIT:7> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> psizer . Add ( self . wids [ '<STR_LIT>' ] , ( <NUM_LIT:1> , <NUM_LIT:8> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , style , <NUM_LIT:1> ) <EOL> pack ( pane , psizer ) <EOL> self . det . connect_displays ( status = self . wids [ '<STR_LIT>' ] , <EOL> elapsed = self . wids [ '<STR_LIT>' ] , <EOL> deadtime = self . wids [ '<STR_LIT>' ] ) <EOL> wx . CallAfter ( self . onSelectDet , index = <NUM_LIT:1> , init = True ) <EOL> self . timer_counter = <NUM_LIT:0> <EOL> self . mca_timer = wx . Timer ( self ) <EOL> self . Bind ( wx . EVT_TIMER , self . UpdateData , self . mca_timer ) <EOL> self . mca_timer . Start ( <NUM_LIT:100> ) <EOL> return pane <EOL> def UpdateData ( self , event = None , force = False ) : <EOL> self . timer_counter += <NUM_LIT:1> <EOL> if self . mca is None or self . needs_newplot : <EOL> self . show_mca ( ) <EOL> self . mca . real_time = self . det . elapsed_real <EOL> if force or self . det . needs_refresh : <EOL> self . det . needs_refresh = False <EOL> if self . det_back > <NUM_LIT:0> : <EOL> if self . mca2 is None : <EOL> self . mca2 = self . det . get_mca ( mca = self . det_back ) <EOL> counts = self . det . get_array ( mca = self . det_back ) <EOL> energy = self . det . get_energy ( mca = self . det_back ) <EOL> try : <EOL> self . update_mca ( counts , energy = energy , is_mca2 = True , draw = False ) <EOL> except ValueError : <EOL> pass <EOL> if self . mca is None : <EOL> self . mca = self . det . get_mca ( mca = self . det_fore ) <EOL> counts = self . det . get_array ( mca = self . det_fore ) * <NUM_LIT:1.0> <EOL> energy = self . det . get_energy ( mca = self . det_fore ) <EOL> if max ( counts ) < <NUM_LIT:1.0> : <EOL> counts = <NUM_LIT> * np . ones ( len ( counts ) ) <EOL> counts [ <NUM_LIT:0> ] = <NUM_LIT> <EOL> self . update_mca ( counts , energy = energy ) <EOL> def ShowROIStatus ( self , left , right , name = '<STR_LIT>' , panel = <NUM_LIT:0> ) : <EOL> if left > right : <EOL> return <EOL> sum = self . ydata [ left : right ] . sum ( ) <EOL> dt = self . mca . real_time <EOL> roi_ave = self . roi_aves [ panel ] <EOL> roi_ave . update ( sum ) <EOL> cps = roi_ave . get_cps ( ) <EOL> nmsg , cmsg , rmsg = '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> if len ( name ) > <NUM_LIT:0> : <EOL> nmsg = "<STR_LIT>" % name <EOL> cmsg = "<STR_LIT>" . format ( sum ) <EOL> if cps is not None and cps > <NUM_LIT:0> : <EOL> rmsg = "<STR_LIT>" . format ( cps ) <EOL> self . write_message ( "<STR_LIT>" % ( nmsg , cmsg , rmsg ) , panel = panel ) <EOL> def onSelectDet ( self , event = None , index = <NUM_LIT:0> , init = False , ** kws ) : <EOL> if index > <NUM_LIT:0> : <EOL> self . det_fore = index <EOL> self . det_back = self . wids [ '<STR_LIT>' ] . GetSelection ( ) <EOL> if self . det_fore == self . det_back : <EOL> self . det_back = <NUM_LIT:0> <EOL> for i in range ( <NUM_LIT:1> , self . nmca + <NUM_LIT:1> ) : <EOL> dname = '<STR_LIT>' % i <EOL> bcol = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> fcol = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> if i == self . det_fore : <EOL> bcol = ( <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT> ) <EOL> fcol = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:100> ) <EOL> if i == self . det_back : <EOL> bcol = ( <NUM_LIT> , <NUM_LIT:200> , <NUM_LIT:20> ) <EOL> self . wids [ dname ] . SetBackgroundColour ( bcol ) <EOL> self . wids [ dname ] . SetForegroundColour ( fcol ) <EOL> self . clear_mcas ( ) <EOL> self . show_mca ( init = init ) <EOL> self . Refresh ( ) <EOL> def swap_mcas ( self , event = None ) : <EOL> if self . mca2 is None : <EOL> return <EOL> self . mca , self . mca2 = self . mca2 , self . mca <EOL> fore , back = self . det_fore , self . det_back <EOL> self . wids [ '<STR_LIT>' ] . SetSelection ( fore ) <EOL> self . onSelectDet ( index = back ) <EOL> def onSetDwelltime ( self , event = None , ** kws ) : <EOL> if '<STR_LIT>' in self . wids : <EOL> self . det . set_dwelltime ( dtime = self . wids [ '<STR_LIT>' ] . GetValue ( ) ) <EOL> def clear_mcas ( self ) : <EOL> self . mca = self . mca2 = None <EOL> self . x2data = self . y2data = None <EOL> self . needs_newplot = True <EOL> def onStart ( self , event = None , dtime = None , ** kws ) : <EOL> if dtime is not None : <EOL> self . wids [ '<STR_LIT>' ] . SetValue ( "<STR_LIT>" % dtime ) <EOL> self . det . set_dwelltime ( dtime = dtime ) <EOL> else : <EOL> self . det . set_dwelltime ( dtime = self . wids [ '<STR_LIT>' ] . GetValue ( ) ) <EOL> [ rave . clear ( ) for rave in self . roi_aves ] <EOL> self . det . start ( ) <EOL> def onStop ( self , event = None , ** kws ) : <EOL> self . det . stop ( ) <EOL> self . det . needs_refresh = True <EOL> time . sleep ( <NUM_LIT> ) <EOL> self . UpdateData ( event = None , force = True ) <EOL> def onErase ( self , event = None , ** kws ) : <EOL> self . needs_newplot = True <EOL> self . det . erase ( ) <EOL> def onDelROI ( self , event = None ) : <EOL> roiname = self . get_roiname ( ) <EOL> errmsg = None <EOL> if self . roilist_sel is None : <EOL> errmsg = '<STR_LIT>' <EOL> if errmsg is not None : <EOL> return Popup ( self , errmsg , '<STR_LIT>' ) <EOL> self . det . del_roi ( roiname ) <EOL> XRFDisplayFrame . onDelROI ( self ) <EOL> def onNewROI ( self , event = None ) : <EOL> roiname = self . get_roiname ( ) <EOL> errmsg = None <EOL> if self . xmarker_left is None or self . xmarker_right is None : <EOL> errmsg = '<STR_LIT>' <EOL> elif roiname in self . wids [ '<STR_LIT>' ] . GetStrings ( ) : <EOL> errmsg = '<STR_LIT>' % roiname <EOL> if errmsg is not None : <EOL> return Popup ( self , errmsg , '<STR_LIT>' ) <EOL> confirmed = XRFDisplayFrame . onNewROI ( self ) <EOL> if confirmed : <EOL> self . det . add_roi ( roiname , lo = self . xmarker_left , <EOL> hi = self . xmarker_right ) <EOL> def onRenameROI ( self , event = None ) : <EOL> roiname = self . get_roiname ( ) <EOL> errmsg = None <EOL> if roiname in self . wids [ '<STR_LIT>' ] . GetStrings ( ) : <EOL> errmsg = '<STR_LIT>' % roiname <EOL> elif self . roilist_sel is None : <EOL> errmsg = '<STR_LIT>' <EOL> if errmsg is not None : <EOL> return Popup ( self , errmsg , '<STR_LIT>' ) <EOL> if self . roilist_sel < len ( self . det . mcas [ <NUM_LIT:0> ] . rois ) : <EOL> self . det . rename_roi ( self . roilist_sel , roiname ) <EOL> names = self . wids [ '<STR_LIT>' ] . GetStrings ( ) <EOL> names [ self . roilist_sel ] = roiname <EOL> self . wids [ '<STR_LIT>' ] . Clear ( ) <EOL> for sname in names : <EOL> self . wids [ '<STR_LIT>' ] . Append ( sname ) <EOL> self . wids [ '<STR_LIT>' ] . SetSelection ( self . roilist_sel ) <EOL> def onCalibrateEnergy ( self , event = None , ** kws ) : <EOL> try : <EOL> self . win_calib . Raise ( ) <EOL> except : <EOL> self . win_calib = CalibrationFrame ( self , mca = self . mca , <EOL> larch = self . larch , <EOL> callback = self . onSetCalib ) <EOL> def onSetCalib ( self , offset , slope , mca = None ) : <EOL> print ( '<STR_LIT>' , offset , slope , mca ) <EOL> def onClose ( self , event = None ) : <EOL> self . onStop ( ) <EOL> XRFDisplayFrame . onClose ( self ) <EOL> def onExit ( self , event = None ) : <EOL> self . onStop ( ) <EOL> XRFDisplayFrame . onExit ( self ) <EOL> class EpicsXRFApp ( wx . App , wx . lib . mixins . inspection . InspectionMixin ) : <EOL> def __init__ ( self , ** kws ) : <EOL> self . kws = kws <EOL> wx . App . __init__ ( self ) <EOL> def OnInit ( self ) : <EOL> self . Init ( ) <EOL> frame = EpicsXRFDisplayFrame ( ** self . kws ) <EOL> frame . Show ( ) <EOL> self . SetTopWindow ( frame ) <EOL> return True <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> EpicsXRFApp ( ) . MainLoop ( ) </s>
