Cat
ConfFrame.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 import sys, os
15 
16 import images
17 from libCatKernel import *
18 
19 from wrapper import *
20 from tools import opj
21 
22 #----------------------------------------------------------------------------
23 class ConfFrame(wx.Frame):
24  overviewText = "CAT Configuration Window"
25  def __init__(self,app,parent,title):
26  wx.Frame.__init__(self, parent, wx.NewId(), title)
27  self.parent=parent
28  self.app=app
29  self.path=os.path.join(os.environ.get("CATPATH"), "CatPython", "python")
30  self.makeToolBar()
31  res=xrc.XmlResource(os.path.join(self.path,"xrc/ConfPanel.xrc"))
32  self.panel=res.LoadPanel(self, "ConfPanel")
33 # self.notebook=xrc.XRCCTRL(self, 'notebook')
34  self.notebook=self.getControl(self.panel,'notebook')
35  self.panels=list()
36  self.objs=list()
37  self.paths=list()
38  self.wraps=list()
39  self.confs=list()
40  self.Bind(wx.EVT_CLOSE, self.onIconize)
41  self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.onChange)
42 
43  def getControl(self, panel, xmlid):
44  '''Retrieves the given control (within a dialog) by its xmlid'''
45  control = panel.FindWindowById(xrc.XRCID(xmlid))
46  assert control != None, 'Programming error: a control with xml id ' + xmlid + ' was not found.'
47  return control
48 
49 
50  def makeToolBar(self):
51  TB_RELOAD=wx.NewId()
52  TB_CLOSEALL=wx.NewId()
53  TB_CLOSE=wx.NewId()
54  #
55  self.toolBar = self.CreateToolBar(wx.TB_DOCKABLE)
56  self.toolBar.AddLabelTool(TB_CLOSEALL, '', wx.Bitmap(os.path.join(self.path,"xrc/icons/closeall.png")))
57  self.toolBar.AddLabelTool(TB_CLOSE , '', wx.Bitmap(os.path.join(self.path,"xrc/icons/close.png")))
58  self.toolBar.AddSeparator()
59  self.toolBar.AddLabelTool(TB_RELOAD, '', wx.Bitmap(os.path.join(self.path,"xrc/icons/reload.png")))
60  self.toolBar.Realize()
61  self.Bind(wx.EVT_TOOL, self.onReLoad , id=TB_RELOAD)
62  self.Bind(wx.EVT_TOOL, self.onCloseAll , id=TB_CLOSEALL)
63  self.Bind(wx.EVT_TOOL, self.onClose , id=TB_CLOSE)
64 
65  def onIdle(self, event):
66  '''Responds to idle time in the system'''
67  # when the timer says it's time, we do the actual downloading in the main thread (wx doesn't work well in secondary threads)
68 
69  def onIconize(self, event):
70  self.parent.cfgFrame.Show(False)
71  self.parent.cfgState=False
72 
73  def onChange(self, event):
74  self.update()
75 
76  def onReLoad(self, event):
77  self.update()
78 
79  def onClose(self, event):
80  pos=self.notebook.GetSelection()
81  self.notebook.DeletePage(pos)
82  self.panels.pop(pos)
83  self.objs.pop(pos)
84  self.paths.pop(pos)
85  self.wraps.pop(pos)
86  self.confs.pop(pos)
87 
88  def onCloseAll(self, event):
89  self.notebook.DeleteAllPages()
90  self.panels=[]
91  self.objs =[]
92  self.paths=[]
93  self.wraps=[]
94  self.confs=[]
95 
96  def onEdit(self, obj, path, type):
97  objpanel=-1
98  for i in range(len(self.objs)):
99  if path==self.paths[i]:
100  objpanel=i
101  if objpanel!=-1:
102  self.notebook.SetSelection(objpanel)
103  self.update()
104  else:
105 # if (type=='element'):
106 # res=xrc.XmlResource(os.path.join(self.path,"xrc/ElementMain.xrc"))
107 # elif (type=='proc'):
108 # res=xrc.XmlResource(os.path.join(self.path,"xrc/ProcMain.xrc"))
109  #panel=res.LoadPanel(self.notebook,"NotebookId")
110  #self.panels.append(panel)
111  self.objs.append(obj)
112  self.paths.append(path)
113  wrap=wrapper(self.app,obj,type)
114  self.wraps.append(wrap)
115 #
116 # if (type=='element'):
117 # namectrl=self.getControl(panel,'ObjName')
118 # pathctrl=self.getControl(panel,'ObjPath')
119 # namectrl.SetValue(obj.name())
120 # pathctrl.SetValue(path)
121 # elif (type=='proc'):
122 # namectrl=self.getControl(panel,'ProcName')
123 # pathctrl=self.getControl(panel,'ProcPath')
124 # namectrl.SetValue(obj.name())
125 # pathctrl.SetValue(obj.type())
126  module=wrap.GetActive()
127  panel=module.Edit(self.app,obj,self.notebook,wrap.GetFilePath())
128  self.panels.append(panel)
129  self.confs.append(panel)
130  self.notebook.AddPage(panel.page(),obj.name(),True)
131 # self.notebook.Fit()
132 # self.notebook.SetSize(self.GetSize())
133  self.Layout()
134 # panel.Fit()
135 # print "panel size=",panel.GetSize()
136 # print "notebook size=",self.notebook.GetSize()
137 
138  def update(self):
139  pos=self.notebook.GetSelection()
140  self.panels[pos].update()
141 
142 #----------------------------------------------------------------------------
143 
144 
145 
def onChange(self, event)
Definition: ConfFrame.py:73
def onCloseAll(self, event)
Definition: ConfFrame.py:88
def onReLoad(self, event)
Definition: ConfFrame.py:76
def __init__(self, app, parent, title)
Definition: ConfFrame.py:25
def onIdle(self, event)
Definition: ConfFrame.py:65
def onClose(self, event)
Definition: ConfFrame.py:79
def onIconize(self, event)
Definition: ConfFrame.py:69
def getControl(self, panel, xmlid)
Definition: ConfFrame.py:43
def update(self)
Definition: ConfFrame.py:138
def makeToolBar(self)
Definition: ConfFrame.py:50
def onEdit(self, obj, path, type)
Definition: ConfFrame.py:96