#! /usr/env/python #-------------------------------------------------------------------------------- """ Application: Dialog_Cmd for DAQ_96_Gui Local Command File Dialog for the Graphical User Interface to the DAQ_96 Control Program """ #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- import os import sys import string import time from Tkinter import * import Pmw from MultiShell import updateComboBox from Print_Utils import printLine from showException import showException from Site_Dependent import CommandFileDir #-------------------------------------------------------------------------------- # these are not needed in this module per se, but useful in the command files being called from Misc_Constants import eOk, eError from Misc_Constants import TT_EM, TT_HD, TtType_str, TtType_tot from Misc_Constants import SlotNumMax #-------------------------------------------------------------------------------- from threading import Semaphore #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- class Dialog_Cmd : def __init__ ( self, MShell, FrameNum ) : self.MShell = MShell self.CmdFrame = FrameNum self.CmdStopRequest = Semaphore () # printLine ( "Dialog", 'Frame #%d is "%s"' % ( FrameNum, MShell.frameName[FrameNum] ) ) #-------------------------------------------------------------------------------- def createInterface(self): MShell = self.MShell MShell.addFieldLabel ( nFrame = self.CmdFrame, labelName = 'GUI Command File', column = 1, columnspan = 3, height = 3, width = 35, row = MShell.nextFieldRow() ) self.CmdComFile = \ MShell.addFieldCombo ( nFrame = self.CmdFrame, labelName ="Cmd File", helpMessage ="GUI Python Command File", statusMessage="GUI Python Command File", columnspan = 3, width = 35 ) MShell.addFieldButton ( nFrame = self.CmdFrame, labelName = 'Exec GUI CmdFile', helpMessage = 'Execute CmdFile', statusMessage= 'Execute CmdFile', width = 15, column = 2, row = MShell.nextFieldRow(), command = lambda : self.Cmd_Exec_ComFile ( ArgDict={} ) ) # had to explictely specify empty ArgDict, # or it would persist from one call to the next # (maybe due to callback mechanism?) MShell.addFieldButton ( nFrame = self.CmdFrame, labelName ="Locate File...", helpMessage ="Find GUI Python Command File", statusMessage="Find GUI Python Command File", width = 15, column = 3, row = MShell.currentFieldRow(), command = lambda: MShell.Find_File( ComboBox=self.CmdComFile ) ) MShell.addFieldLabel ( nFrame = self.CmdFrame, labelName = '', row = MShell.nextFieldRow() ) MShell.addFieldButton ( nFrame = self.CmdFrame, labelName = 'Request Command File Stop', helpMessage = 'Command File Stop (if supported)', statusMessage= 'Command File Stop (if supported)', width = 30, column = 2, columnspan = 2, row = MShell.nextFieldRow(), command = self.RequestCmdFileStop ) #-------------------------------------------------------------------------------- def ClearStopRequest ( self ) : do_not_block = 0 while self.CmdStopRequest.acquire ( do_not_block ) : printLine ( "Start", "StopRequest Semaphore is cleared" ) #-------------------------------------------------------------------------------- def CheckIfStopRequested ( self ) : do_not_block = 0 if self.CmdStopRequest.acquire ( do_not_block ) : printLine ( "Stop", "SubProcess has noticed GUI request to stop" ) return 1 else : return 0 #-------------------------------------------------------------------------------- def RequestCmdFileStop ( self ) : printLine ( "Stop", "GUI is requesting CmdFile SubProcess to Stop" ) self.CmdStopRequest.release ( ) #-------------------------------------------------------------------------------- def Cmd_Exec_ComFile ( self, ComFile = '', ArgDict = {} ): if ( ComFile == '' ) : gotFileFromComboBox = 'Yes' ComFile = self.CmdComFile.get() else : gotFileFromComboBox = 'No' #Separate path and directory ComFile_split = os.path.split ( ComFile ) ComFile_name = ComFile_split[1] if ( ComFile_split[0] != '' ) : ComFile_path = ComFile_split[0] + '/' else : ComFile_path = os.getcwd() + '/' ComFile = ComFile_path + ComFile_name #check for file existence ComFile_path_list = os.listdir( ComFile_path ) if ( ComFile_name not in ComFile_path_list ) : printLine ( "ComFile", "Could not locate Command File <%s>" % ComFile ) else : # add file name to ComboBox list if ( gotFileFromComboBox == 'Yes' ) : updateComboBox ( self.CmdComFile, ComFile ) # Ready to Execute the Command File MShell = self.MShell # make aliases to avoid needing the prefix 'self.MShell.Dialog_Xyz' in the command files Vme_Read = MShell.Dialog_Vio.Vio_Vme_Read Vme_Write = MShell.Dialog_Vio.Vio_Vme_Write Rio_Read = MShell.Dialog_Rio.Rio_Reg_Read Rio_Write = MShell.Dialog_Rio.Rio_Reg_Write ProbeCrateSlots = MShell.Dialog_Rio.Rio_ProbeCrateSlots ProbeSlot = MShell.Dialog_Rio.Rio_ProbeSlot Adf_InitCard = MShell.Dialog_Adf.Adf_InitCard Adf_SendPrn = MShell.Dialog_Adf.Adf_SendPrn Adf_SendBls = MShell.Dialog_Adf.Adf_SendBls Hst_Histogram = MShell.Dialog_Hst.Hst_10BitHisto Config_Fpga = MShell.Dialog_Cfg.Cfg_Config_FPGA Write_Dac = MShell.Dialog_Dac.Dac_Write_Dac Find_Dac = MShell.Dialog_Dac.Dac_Find_Dac RandomRegTest_Clear = MShell.Dialog_Rrt.Rrt_ClearAll RandomRegTest_Range = MShell.Dialog_Rrt.Rrt_AddRange RandomRegTest_Start = MShell.Dialog_Rrt.Rrt_StartTest Adc_Capture = MShell.Dialog_Adc.Adc_Capture Send_COOR_Msg = MShell.Dialog_Msg.Msg_Send_COOR_Msg Exec_ComFile = MShell.Dialog_Cmd.Cmd_Exec_ComFile Gui_Exec_CmdFile = MShell.Dialog_Cmd.Cmd_Exec_ComFile Tcs_Exec_VioFile = MShell.Dialog_Com.Com_Exec_VioFile Tcs_Exec_RioFile = MShell.Dialog_Com.Com_Exec_RioFile Tcs_Exec_CfgFile = MShell.Dialog_Com.Com_Exec_CfgFile Tcs_Exec_TtiFile = MShell.Dialog_Com.Com_Exec_TtiFile Tcs_Exec_MsgFile = MShell.Dialog_Com.Com_Exec_MsgFile Tcs_Exec_McfFile = MShell.Dialog_Com.Com_Exec_McfFile # access to GUI fields and actions from Collect Event SetRunIsUnderway = MShell.Dialog_Col.SetRunIsUnderway GetAdfIncluded = MShell.Dialog_Col.GetAdfIncluded GetEventTotal = MShell.Dialog_Col.GetEventTotal SetRunNumber = MShell.Dialog_Col.SetRunNumber SetEventNumber = MShell.Dialog_Col.SetEventNumber SetRunStatus = MShell.Dialog_Col.SetRunStatus SetEventStatus = MShell.Dialog_Col.SetEventStatus CheckIfPaused = MShell.Dialog_Col.CheckIfPaused GetCoolDownSec = MShell.Dialog_Col.GetCoolDownSec HandleAutoPause = MShell.Dialog_Col.HandleAutoPause # cosmetic alias of Command Stop Request CheckIfStopRequested = MShell.Dialog_Cmd.CheckIfStopRequested ClearStopRequest = MShell.Dialog_Cmd.ClearStopRequest # we will restore the default directory current_path = os.getcwd ( ) try : printLine ( "ComFile", "Starting %s" % ComFile ) execfile ( ComFile ) printLine ( "ComFile", "Done with %s" % ComFile ) except : printLine ( "ComFile", "Execution Failure" ) showException ( ) # restore path os.chdir ( current_path )