#! /usr/env/python #-------------------------------------------------------------------------------- """ Application: Dialog_Plt 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 RunDataDir from Site_Dependent import CommandFileDir from Site_Dependent import DAQ96_Plot_CmdFile #-------------------------------------------------------------------------------- from threading import Semaphore #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- class Dialog_Plt : def __init__ ( self, MShell, FrameNum ) : self.MShell = MShell self.PltFrame = FrameNum self.PltStopRequest = Semaphore () # printLine ( "Dialog", 'Frame #%d is "%s"' % ( FrameNum, MShell.frameName[FrameNum] ) ) #-------------------------------------------------------------------------------- def createInterface(self): MShell = self.MShell MShell.addFieldLabel ( nFrame = self.PltFrame, labelName = 'DAQ96: Plot Raw Data', column = 1, columnspan = 3, height = 3, width = 35, row = MShell.nextFieldRow() ) self.PltEvtFile = \ MShell.addFieldCombo ( nFrame = self.PltFrame, labelName ="Event File", helpMessage ="Raw Data File", statusMessage="Raw Data File", columnspan = 3, width = 35 ) MShell.addFieldButton ( nFrame = self.PltFrame, labelName ="Plot Raw Data", helpMessage ="Plot Raw Data", statusMessage="Plot Raw Data", width = 15, column = 2, row = MShell.nextFieldRow(), command = self.Plt_Plot_File ) MShell.addFieldButton ( nFrame = self.PltFrame, labelName ="Locate File...", helpMessage ="Find Event Data File", statusMessage="Find Event Data File", width = 15, column = 3, row = MShell.currentFieldRow(), command = self.Plt_Loc_File ) #-------------------------------------------------------------------------------- def Plt_Plot_File ( self, EvtFile = '' ): if ( EvtFile == '' ) : EvtFile = self.PltEvtFile.get() #Separate path and directory EvtFile_split = os.path.split ( EvtFile ) EvtFile_name = EvtFile_split[1] if ( EvtFile_split[0] != '' ) : EvtFile_path = EvtFile_split[0] + '/' else : EvtFile_path = os.getcwd() + '/' EvtFile = EvtFile_path + EvtFile_name # check for file existence # first, try adding the standard location if ( os.path.exists ( RunDataDir + EvtFile_path ) \ and ( EvtFile_name in os.listdir( RunDataDir + EvtFile_path ) ) ) : EvtFile_path = RunDataDir + EvtFile_path # second, try to use the path as specified, # in case this event is elsewhere or was entered literally elif ( os.path.exists ( EvtFile_path ) \ and ( EvtFile_name in os.listdir( EvtFile_path ) ) ) : # nothing to do here EvtFile_path = EvtFile_path else : printLine ( "PltFile", "Could not locate Event File <%s>" % EvtFile ) return # add file name to ComboBox list updateComboBox ( self.PltEvtFile, EvtFile ) # the actual plotting is done in a command file # we need to pass the name of the file ArgDict = {} ArgDict['EvtFile'] = EvtFile_path + EvtFile_name printLine ( "PltFile", "Plot Raw Data from Event File <%s>" % ( EvtFile_path + EvtFile_name ) ) self.MShell.Dialog_Cmd.Cmd_Exec_ComFile ( ComFile = CommandFileDir + DAQ96_Plot_CmdFile, ArgDict = ArgDict ) #-------------------------------------------------------------------------------- def Plt_Loc_File ( self ) : # set path within output directory to make it easier to locate files print os.getcwd() if ( os.getcwd()[:len(RunDataDir)] != RunDataDir ) : os.chdir ( RunDataDir ) EvtFile = self.MShell.Find_File( ) # Strip the beginning of the path, if it is the standard location if ( EvtFile[:len(RunDataDir)] == RunDataDir ) : EvtFile = EvtFile[len(RunDataDir):] updateComboBox ( self.PltEvtFile, EvtFile )