Cat
GraphFrame.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #----------------------------------------------------------------------------
3 #----------------------------------------------------------------------------
4 
5 """
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
8 on the command line.
9 """
10 
11 import wx
12 import wx.xrc as xrc
13 import wx.lib.mixins.inspection
14 
15 import sys, os
16 
17 import images
18 
19 from libCatKernel import *
20 
21 from wrapper import *
22 from tools import opj
23 
24 #----------------------------------------------------------------------------
25 class GraphFrame(wx.Frame):
26  overviewText = "CAT Graphical Window"
27  def __init__(self,app,parent,title):
28  wx.Frame.__init__(self, parent, wx.NewId(), title)
29  self.figId=0
30  self.parent=parent
31  self.app=app
32  self.path=os.path.join(os.environ.get("CATPATH"), "CatPython", "python")
33  self.makeToolBar()
34  res=xrc.XmlResource(os.path.join(self.path,"xrc/GraphPanel.xrc"))
35  self.panel=res.LoadPanel(self, "GraphPanel")
36  self.notebook=xrc.XRCCTRL(self, 'notebook')
37  self.panels=list()
38  self.objs=list()
39  self.figs=list()
40 
41  self.Bind(wx.EVT_CLOSE, self.onIconize)
42  self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.onChange)
43 
44  def getControl(self, panel, xmlid):
45  '''Retrieves the given control (within a dialog) by its xmlid'''
46  control = panel.FindWindowById(xrc.XRCID(xmlid))
47  assert control != None, 'Programming error: a control with xml id ' + xmlid + ' was not found.'
48  return control
49 
50  def makeToolBar(self):
51  TB_PRINT=wx.NewId()
52  TB_SAVE=wx.NewId()
53  TB_CLOSEALL=wx.NewId()
54  TB_CLOSE=wx.NewId()
55  #
56  self.toolBar = self.CreateToolBar(wx.TB_DOCKABLE)
57  self.toolBar.AddLabelTool(TB_CLOSEALL, '', wx.Bitmap(os.path.join(self.path,"xrc/icons/closeall.png")))
58  self.toolBar.AddLabelTool(TB_CLOSE , '', wx.Bitmap(os.path.join(self.path,"xrc/icons/close.png")))
59  self.toolBar.AddSeparator()
60  self.toolBar.AddLabelTool(TB_PRINT, '', wx.Bitmap(os.path.join(self.path,"xrc/icons/fileprint.png")))
61  self.toolBar.AddLabelTool(TB_SAVE, '', wx.Bitmap(os.path.join(self.path,"xrc/icons/filesave.png")))
62  self.toolBar.Realize()
63 
64  self.Bind(wx.EVT_TOOL, self.onCloseAll , id=TB_CLOSEALL)
65  self.Bind(wx.EVT_TOOL, self.onClose , id=TB_CLOSE)
66  self.Bind(wx.EVT_TOOL, self.onPrint , id=TB_PRINT)
67  self.Bind(wx.EVT_TOOL, self.onSave , id=TB_SAVE)
68 
69  def onIdle(self, event):
70  '''Responds to idle time in the system'''
71  # when the timer says it's time, we do the actual downloading in the main thread (wx doesn't work well in secondary threads)
72  print "hello"
73 
74  def onChange(self, event):
75  self.update()
76 
77  def onIconize(self, event):
78  self.parent.gphFrame.Show(False)
79  self.parent.gphState=False
80 
81  def onReLoad(self, event):
82  self.update(self.notebook.GetSelection())
83 
84  def onPrint(self, event):
85  print "printing..."
86 
87  def onSave(self, event):
88  print "save..."
89 
90  def onClose(self, event):
91  pos=self.notebook.GetSelection()
92  self.notebook.DeletePage(pos)
93 # self.panels(pos).killFigure()
94 # self.panels(pos).Destroy()
95  self.panels.pop(pos)
96  self.objs.pop(pos)
97  self.figs.pop(pos)
98 
99  def onCloseAll(self, event):
100  self.notebook.DeleteAllPages()
101  self.panels=[]
102  self.objs =[]
103  self.figs =[]
104 
105  def onPlot(self, obj):
106  wrap=wrapper(self.app,obj,"proc")
107  if (wrap.ok):
108  module=wrap.GetActive()
109  panel=module.Plot(self.app,obj,self.notebook,self.figId)
110  if panel!=None :
111  self.figId+=1
112  self.panels.append(panel)
113  self.objs.append(obj)
114  self.figs.append(panel)
115  self.notebook.AddPage(panel,obj.name(),True)
116 
117  def update(self):
118  pos=self.notebook.GetSelection()
119  self.figs[pos].current()
120 
121 #----------------------------------------------------------------------------
122 
123 
124 
def onPlot(self, obj)
Definition: GraphFrame.py:105
def onClose(self, event)
Definition: GraphFrame.py:90
def onReLoad(self, event)
Definition: GraphFrame.py:81
def onChange(self, event)
Definition: GraphFrame.py:74
def onIconize(self, event)
Definition: GraphFrame.py:77
def onCloseAll(self, event)
Definition: GraphFrame.py:99
def __init__(self, app, parent, title)
Definition: GraphFrame.py:27
def makeToolBar(self)
Definition: GraphFrame.py:50
def getControl(self, panel, xmlid)
Definition: GraphFrame.py:44
def onPrint(self, event)
Definition: GraphFrame.py:84
def onIdle(self, event)
Definition: GraphFrame.py:69
def onSave(self, event)
Definition: GraphFrame.py:87