6 This program will load and run one of the individual demos in this     7 directory within its own frame window.  Just specify the module name    14 import wx.lib.mixins.inspection
    15 from wx.lib.mixins.treemixin 
import ExpansionState
    23 from CfgFrame  
import *
    25 from libCatKernel 
import *
    36 _objectTypes = [
"Overview", 
"demo", 
"Processus",
"Doc", 
"Data",
"Doc"]
    47             (
'App',[
True,[0.01,0.04],[0.30,0.60]]),
    50             (
'Gph',[
False,[0.13,0.13],[0.75,0.75]])
    55     overviewText = 
"CAT Main Window"    57         wx.Frame.__init__(self, parent, wx.NewId(), title, size=(500, 650))
    74         self.
path=os.path.join(os.environ.get(
"CATPATH"),
"CatPython",
"python")
    75         sizeX=wx.SystemSettings.GetMetric( wx.SYS_SCREEN_X );
    76         sizeY=wx.SystemSettings.GetMetric( wx.SYS_SCREEN_Y );
    79         res=xrc.XmlResource(os.path.join(self.
path,
"xrc/AppPanel.xrc"))
    80         self.
panel=res.LoadPanel(self, 
"AppPanel")
    83         for window, items 
in _windows:
    85             Pt=wx.Point(items[1][0]*sizeX,items[1][1]*sizeY)
    86             Sz=wx.Size(items[2][0]*sizeX,items[2][1]*sizeY)
   118         self.
vbox=wx.BoxSizer(wx.VERTICAL)
   122         self.
vbox.Add(self.
tree,1,wx.EXPAND)
   137         self.Bind(wx.EVT_COMBOBOX, self.
updateCombo, id=xrc.XRCID(
"elementCombo"))        
   138         self.Bind(wx.EVT_BUTTON, self.
onLoad, id=xrc.XRCID(
"openConfFile"))
   139         self.Bind(wx.EVT_BUTTON, self.
onEdit, id=xrc.XRCID(
"onEdit"))
   140         self.Bind(wx.EVT_SPINCTRL, self.
runCtrl, id=xrc.XRCID(
"runCtrl"))
   141         self.Bind(wx.EVT_SPINCTRL, self.
eventCtrl, id=xrc.XRCID(
"eventCtrl"))
   142         self.Bind(wx.EVT_SPINCTRL, self.
printFreq, id=xrc.XRCID(
"printFreq"))
   143         self.Bind(wx.EVT_SPINCTRL, self.
plotFreq, id=xrc.XRCID(
"plotFreq"))
   144         self.Bind(wx.EVT_TEXT_ENTER, self.
onEnter, id=xrc.XRCID(
"cmdline"))
   145         self.Bind(wx.EVT_BUTTON, self.
onEnter, id=xrc.XRCID(
"onEnter"))
   146         self.Bind(wx.EVT_BUTTON, self.
onExpand, id=xrc.XRCID(
"onExpand"))
   147         self.Bind(wx.EVT_BUTTON, self.
onCollapse, id=xrc.XRCID(
"onCollapse"))
   148         self.Bind(wx.EVT_BUTTON, self.
deleteHardware, id=xrc.XRCID(
"deleteHardware"))
   149         self.Bind(wx.EVT_TOGGLEBUTTON, self.
onAutoCheck, id=xrc.XRCID(
"autoCheck"))
   150         self.Bind(wx.EVT_TOGGLEBUTTON, self.
onStopOnError, id=xrc.XRCID(
"stoponerror"))
   151         self.Bind(wx.EVT_TOGGLEBUTTON, self.
onLogCheck, id=xrc.XRCID(
"logCheck"))
   152         self.Bind(wx.EVT_TOGGLEBUTTON, self.
onFileCheck, id=xrc.XRCID(
"fileCheck"))
   157         '''Retrieves the given control (within a dialog) by its xmlid'''   158         control = self.FindWindowById(xrc.XRCID(xmlid))
   162         if control == 
None and self.GetMenuBar() != 
None:  
   163             control = self.GetMenuBar().FindItemById(xrc.XRCID(xmlid))
   164         assert control != 
None, 
'Programming error: a control with xml id ' + xmlid + 
' was not found.'   172         file.Append(MB_FILE,
"&File",
"Open new configuration file")
   173         file.Append(MB_CLOSE,
"&Close",
"Close configuration file")
   174         file.Append(wx.ID_EXIT, 
"E&xit", 
"Terminate the program")
   180         help.Append(wx.ID_ABOUT, 
"&About",
"More information about this program")
   181         help.AppendSeparator()
   182         help.Append(wx.ID_HELP, 
"&Help", 
"CAT application help")
   184         self.
menuBar.Append(file   , 
"&File")
   185         self.
menuBar.Append(windows, 
"&Windows")
   186         self.
menuBar.Append(help   , 
"&Help")
   188         self.Bind(wx.EVT_MENU, self.
onExit      , id=wx.ID_EXIT )
   189         self.Bind(wx.EVT_MENU, self.
onAbout     , id=wx.ID_ABOUT )
   190         self.Bind(wx.EVT_MENU, self.
onHelp      , id=wx.ID_HELP )
   194         self.Bind(wx.EVT_MENU, self.
onLoad      , id=MB_FILE  )
   195         self.Bind(wx.EVT_MENU, self.
onClose     , id=MB_CLOSE  )
   200         TB_CONFIGURE=wx.NewId()
   207         self.
toolBar = self.CreateToolBar(wx.TB_DOCKABLE)
   208         self.
toolBar.AddLabelTool(TB_OPEN  , 
'', wx.Bitmap(os.path.join(self.
path,
"xrc/icons/fileopen.png")))
   209         self.
toolBar.AddLabelTool(TB_RELOAD, 
'', wx.Bitmap(os.path.join(self.
path,
"xrc/icons/reload.png")))
   210         self.
toolBar.AddLabelTool(TB_CONFIGURE, 
'', wx.Bitmap(os.path.join(self.
path,
"xrc/icons/conf.png")))
   211         self.
toolBar.AddLabelTool(TB_INIT, 
'', wx.Bitmap(os.path.join(self.
path,
"xrc/icons/init.png")))
   212         self.
toolBar.AddLabelTool(TB_DELETE, 
'', wx.Bitmap(os.path.join(self.
path,
"xrc/icons/delete.png")))
   215         self.
toolBar.AddCheckLabelTool(self.
TB_GRAPH, 
'', wx.Bitmap(os.path.join(self.
path,
"xrc/icons/graph.png")))
   218         self.
toolBar.AddLabelTool(TB_START, 
'', wx.Bitmap(os.path.join(self.
path,
"xrc/icons/start.png")))
   219         self.
toolBar.AddLabelTool(TB_SINGLE, 
'', wx.Bitmap(os.path.join(self.
path,
"xrc/icons/single.png")))
   221         self.
toolBar.AddLabelTool(wx.ID_EXIT, 
'', wx.Bitmap(os.path.join(self.
path,
"xrc/icons/exit.png")))
   223         self.Bind(wx.EVT_TOOL, self.
onExit      , id=wx.ID_EXIT)
   227         self.Bind(wx.EVT_TOOL, self.
onLoad , id=TB_OPEN)
   228         self.Bind(wx.EVT_TOOL, self.
onReLoad , id=TB_RELOAD)
   229         self.Bind(wx.EVT_TOOL, self.
onConfigure , id=TB_CONFIGURE)
   230         self.Bind(wx.EVT_TOOL, self.
onInit , id=TB_INIT)
   231         self.Bind(wx.EVT_TOOL, self.
onDelete , id=TB_DELETE)
   232         self.Bind(wx.EVT_TOOL, self.
onStart , id=TB_START)
   233         self.Bind(wx.EVT_TOOL, self.
onSingle , id=TB_SINGLE)
   241         '''Responds to idle time in the system'''   246         '''Closes the application'''   247         dlg = wx.MessageDialog(self, 
"Exit the program?", 
"Exit", wx.YES_NO | wx.ICON_QUESTION)
   248         if dlg.ShowModal() == wx.ID_YES:
   253         '''Closes the application'''   270         cat.options().setRunNumberMgr(self.
getControl(
"autoCheck").GetValue())
   271         print cat.options().runNumberMgr()
   274         cat.options().setStopOnError(self.
getControl(
"stoponerror").GetValue())
   277         cat.options().setDataStorage(self.
getControl(
"fileCheck").GetValue())
   278         print cat.options().dataStorage()
   281         cat.options().setLogStorage(self.
getControl(
"logCheck").GetValue())
   282         print cat.options().logStorage()
   285         cat.options().setNEvtMax(self.
getControl(
"eventCtrl").GetValue()) 
   288         cat.options().setRunNumber(self.
getControl(
"runCtrl").GetValue()) 
   291         cat.options().setPrintFreq(self.
getControl(
"printFreq").GetValue()) 
   294         cat.options().setPlotFreq(self.
getControl(
"plotFreq").GetValue()) 
   331             self, message=
"Choose a file",
   332             defaultDir=os.getcwd(), 
   334             wildcard=
"Python source (*.py)|*.py|" "All files (*.*)|*.*",
   335             style=wx.OPEN | wx.CHANGE_DIR
   340         if dlg.ShowModal() == wx.ID_OK:
   342             path = dlg.GetPaths()
   347             filename=str(path[0])
   349             cat.options().setDefFile(filename)
   350             cat.computer().
tree()
   373         for i 
in range(len(self.
objs)):
   374             if objtype[0]==self.
paths[i]:
   379         self.
paths.append(objtype[0])
   380         if (objtype[1]==
'Element'):
   381             self.
objs.append(cat.computer().child(objtype[0]))
   384         if (objtype[1]==
'Processus'):
   385             list = cat.procDb().list()
   386             for p 
in range(len(list)):
   387                 if list[p].name()==objtype[0]:
   388                     self.
objs.append(list[p])
   394         cat.warning(
"Removing object "+objtype[0]+
" of type "+objtype[1])
   395         element=cat.computer().child(objtype[0])
   397             cat.computer().delChild(element)
   408         cat.computer().
tree()
   412         print "Not implemented yet"   418         cat.computer().
clear()        
   421         cat.options().setStorageDir(str(self.
getControl(
"fileCtrl").GetValue()))
   422         cat.options().setStoragePath(str(self.
getControl(
"pathCtrl").GetValue()))
   424         element=cat.computer().child(self.
listElement[item])
   425         list=cat.procDb().list(element)
   426         processus=list[self.
procCombo.GetSelection()]
   429         dlg = wx.ProgressDialog(processus.title(),
   433                                 style = wx.PD_CAN_ABORT
   436                                 | wx.PD_ESTIMATED_TIME
   437                                 | wx.PD_REMAINING_TIME
   441         processus.setElement(element)
   442         wrap = 
wrapper(cat, processus, 
"proc")
   447             module = wrap.GetActive()
   448             if module 
and online!=0 :
   449                 plts = module.createPlots(cat, processus, cat.options().runNumber())        
   460         dlg.Update(ievt, 
" Initializing"+processus.name())
   461         cat.prepare(processus.name(),element,nevt)
   466                 if module 
and ievt%online==0:
   467                     module.updatePlots(plts, processus)
   469                 elapsed = time.time() - timing
   470                 (keepGoing, skip)=dlg.Update(elapsed,
"Running "+processus.name())
   471                 if elapsed > evt: keepGoing = 
False   473                 (keepGoing, skip)=dlg.Update(ievt,
"Running "+processus.name())
   474                 if ievt >= evt: keepGoing = 
False   475         dlg.Update(evt,
"Finalizing "+processus.name())
   478         if module 
and online==0:
   479             plts = module.createPlots(cat, processus, cat.options().runNumber())        
   481                 module.updatePlots(plts, processus)
   490         cat.options().setStorageDir(str(self.
getControl(
"fileCtrl").GetValue()))
   491         cat.options().setStoragePath(str(self.
getControl(
"pathCtrl").GetValue()))
   493         element=cat.computer().child(self.
listElement[item])
   494         list=cat.procDb().list(element)
   495         processus=list[self.
procCombo.GetSelection()]
   496         cat.prepare(processus.name(),element,1)
   499         self.
plot(processus,
False)
   500         self.
getControl(
"runCtrl").SetValue(cat.options().runNumber())
   504         self.gphFrame.onPlot(proc)
   506             self.gphFrame.Show(
True)
   507             self.gphFrame.show=
True               512         def sublevel(list, element):
   513             if (element.hasChildren()):
   515                 children=element.children()
   516                 for child 
in range(len(children)):
   517                     newlist.append(children[child].name())
   518                     if (children[child].hasChildren()):
   519                         sublevel(newlist,children[child])
   522         list.append(cat.computer().name())
   523         sublevel(list,cat.computer())
   529         listPtr=cat.procDb().list()
   530         for proc 
in range(len(listPtr)):
   531             list.append(listPtr[proc].name())
   536         self.
getControl(
"cdffileCtrl").SetValue(cat.options().defFile());
   539         self.
getControl(
"eventCtrl").SetValue(cat.options().nEvtMax())
   540         self.
getControl(
"runCtrl").SetValue(cat.options().runNumber())
   541         self.
getControl(
"errorCtrl").SetValue(str(cat.options().nErrors()))
   542         self.
getControl(
"fileCtrl").SetValue(cat.options().storageDir())
   543         self.
getControl(
"pathCtrl").SetValue(cat.options().storagePath())
   544         self.
getControl(
"stoponerror").SetValue(cat.options().stopOnError())
   545         self.
getControl(
"autoCheck").SetValue(cat.options().runNumberMgr())
   546         self.
getControl(
"fileCheck").SetValue(cat.options().dataStorage())
   547         self.
getControl(
"logCheck").SetValue(cat.options().logStorage())
   548         level=cat.options().logOutputLevel()
   550         if level==MsgLevel.VERBOSE:
   551             combo.SetSelection(0)
   552         if level==MsgLevel.DEBUG:
   553             combo.SetSelection(1)
   554         if level==MsgLevel.INFO:
   555             combo.SetSelection(2)
   556         if level==MsgLevel.WARNING:
   557             combo.SetSelection(3)
   558         if level==MsgLevel.ERROR:
   559             combo.SetSelection(4)
   560         if level==MsgLevel.FATAL:
   561             combo.SetSelection(5)
   570             if (i==cat.current().
path(
"")):
   579         def sublevel(list, element):
   580             if (element.hasChildren()):
   581                 children=element.children()
   582                 for child 
in range(len(children)):
   583                     if (len(cat.procDb().list(children[child]))>0):
   584                        list.append(children[child].
path(
""))
   585                     if (children[child].hasChildren()):
   586                         sublevel(list,children[child])
   589         list.append(cat.computer().
path(
""))
   590         sublevel(list,cat.computer())
   594         item=event.GetSelection()
   596             element=cat.computer()
   598             element=cat.computer().child(self.
listElement[item])
   602         level=self.
getControl(
"outputLevel").GetValue()
   604             cat.options().setLogOutputLevel(MsgLevel.VERBOSE)
   606             cat.options().setLogOutputLevel(MsgLevel.DEBUG)            
   608             cat.options().setLogOutputLevel(MsgLevel.INFO)
   610             cat.options().setLogOutputLevel(MsgLevel.WARNING)            
   612             cat.options().setLogOutputLevel(MsgLevel.ERROR)            
   613         if level==
"Fatal Error":
   614             cat.options().setLogOutputLevel(MsgLevel.FATAL)
   615         print cat.options().logOutputLevel()
   620         list=cat.procDb().list(element)
   621         for i 
in range(len(list)):
 
def updateCombo(self, event)
def BuildProcessusList(self)
def RecreateTree(self, myElements, myProcessus)
def onCollapse(self, event)
def eventCtrl(self, event)
def onExpand(self, event)
def deleteHardware(self, event)
def onSingle(self, event)
def __init__(self, app, parent, title)
def plotFreq(self, event)
def printFreq(self, event)
def GetItem(self)
self.root = self.tree.AddRoot("The Root Item") self.tree.SetPyData(self.root, None) self...
def onCloseConfirm(self, event)
def onDelete(self, event)
def BuildElementList(self)
def onFileCheck(self, event)
def plot(self, proc, force)
def onAutoCheck(self, event)
def procComboUpdate(self, element)
def getControl(self, xmlid)
def onReLoad(self, event)
def onStopOnError(self, event)
def updateOutputLevel(self, event)
def onConfigure(self, event)
def onLogCheck(self, event)