21 class ErrorEvent(QCustomEvent):
22 def __init__(self,caption,msg):
23 QCustomEvent.__init__(self,8888)
26 def process(self,parent):
27 QMessageBox.warning(parent,self.caption,self.msg)
29 class Runner(threading.Thread):
30 def __init__(self,parent,executor,proc):
31 threading.Thread.__init__(self)
33 self.executor=executor
38 self.executor.RunW(self.proc,0)
40 #traceback.print_exc()
41 QApplication.postEvent(self.parent, ErrorEvent('YACS execution error',str(ex)))
44 def __init__(self,parent,proc):
45 QVBox.__init__(self,parent)
49 self.hSplitter = QSplitter(self,"hSplitter")
50 self.objectBrowser=Tree.Tree(self.hSplitter,self.onSelect,self.onDblSelect)
51 self.objectBrowser.additem(pp)
52 self.panelManager=PanelManager.PanelManager(self.hSplitter)
53 self.panelManager.setRootItem(pp)
54 self.boxManager=BoxManager.BoxManager(self.hSplitter)
55 self.boxManager.setRootItem(pp)
60 self.log=logview.LogView()
63 self.log.text.setText(self.proc.getLogger("parser").getStr())
66 def onDblSelect(self,item):
67 #item is instance of Item.Item
70 def onSelect(self,item):
71 #item is instance of Item.Item
74 def customEvent(self,ev):
80 self.executor = pilot.ExecutorSwig()
81 if self.thr and self.thr.isAlive():
83 #continue execution mode
84 self.executor.setExecMode(0)
85 #execute it in a thread
86 self.thr = Runner(self, self.executor, self.proc)
87 #as a daemon (no need to join)
95 """Suspend or resume an executing schema"""
98 if not self.thr.isAlive():
102 #continue execution mode
103 self.executor.setExecMode(0)
105 self.executor.resumeCurrentBreakPoint()
108 #step by step execution mode
109 self.executor.setExecMode(1)
113 """Step on a paused schema"""
114 if not self.executor:
115 self.executor = pilot.ExecutorSwig()
116 if not self.thr or not self.thr.isAlive():
117 #start in step by step mode
118 self.executor.setExecMode(1)
119 self.thr = Runner(self, self.executor, self.proc)
120 self.thr.setDaemon(1)
125 #step by step execution mode
127 self.executor.setExecMode(1)
129 self.executor.resumeCurrentBreakPoint()
132 """Stop the schema"""
133 if not self.executor:
135 if not self.thr.isAlive():
137 self.executor.setExecMode(1)
138 self.executor.waitPause()
139 self.executor.resumeCurrentBreakPoint()
140 #self.executor.stopExecution()
142 class Appli(QMainWindow):
145 Cree la fenetre principale de l'interface utilisateur
148 QMainWindow.__init__(self)
156 def createWidgets(self):
157 self.tabWidget = QTabWidget(self)
158 self.currentPanel=None
159 self.connect(self.tabWidget, SIGNAL('currentChanged(QWidget *)'),self.handlePanelChanged)
160 self.setCentralWidget(self.tabWidget)
163 def handlePanelChanged(self,panel):
164 self.currentPanel=panel
166 def initActions(self):
169 self.newAct=QAction('New', QIconSet(Icons.get_image("new")), '&New',
170 QKeySequence("CTRL+N"),self)
171 self.newAct.setStatusTip('Open an empty editor window')
172 self.newAct.setWhatsThis( """<b>New</b>"""
173 """<p>An empty editor window will be created.</p>""")
174 self.newAct.connect(self.newAct,SIGNAL('activated()'), self.newProc)
175 self.actions.append(self.newAct)
177 self.prefAct=QAction('Preferences',QIconSet(Icons.get_image("configure.png")),'&Preferences...',
179 self.prefAct.setStatusTip('Set the prefered configuration')
180 self.prefAct.setWhatsThis("""<b>Preferences</b>"""
181 """<p>Set the configuration items of the application"""
182 """ with your prefered values.</p>""")
183 self.prefAct.connect(self.prefAct,SIGNAL('activated()'), self.handlePreferences)
184 self.actions.append(self.prefAct)
186 self.runAct=QAction('Run',QIconSet(Icons.get_image("run.png")),'&Run',0,self)
187 self.runAct.connect(self.runAct,SIGNAL('activated()'), self.run)
188 self.runAct.setStatusTip('Run the selected schema')
189 self.actions.append(self.runAct)
191 self.suspAct=QAction('Suspend/resume',QIconSet(Icons.get_image("suspend-resume.gif")),'&Suspend/resume',0,self)
192 self.suspAct.connect(self.suspAct,SIGNAL('activated()'), self.susp)
193 self.suspAct.setStatusTip('Suspend/resume the selected schema')
194 self.actions.append(self.suspAct)
196 self.stepAct=QAction('Step',QIconSet(Icons.get_image("steps.png")),'&Step',0,self)
197 self.stepAct.connect(self.stepAct,SIGNAL('activated()'), self.step)
198 self.stepAct.setStatusTip('Step the selected schema')
199 self.actions.append(self.stepAct)
201 self.stopAct=QAction('Stop',QIconSet(Icons.get_image("kill.png")),'&Stop',0,self)
202 self.stopAct.connect(self.stopAct,SIGNAL('activated()'), self.stop)
203 self.stopAct.setStatusTip('Stop the selected schema')
204 self.actions.append(self.stopAct)
206 self.cataToolAct=QAction('Catalog Tool',0,self,"catatool")
207 self.cataToolAct.connect(self.cataToolAct,SIGNAL('activated()'), self.cata_tool)
208 self.actions.append(self.cataToolAct)
211 menubar = self.menuBar()
214 self.fileMenu=QPopupMenu(self)
215 self.newAct.addTo(self.fileMenu)
216 self.fileMenu.insertItem("&Open", self.openFile)
217 self.fileMenu.insertItem("&Open Salome", self.openSalomeFile)
218 self.loadersMenu = QPopupMenu(self)
219 self.fileMenu.insertItem("Loaders", self.loadersMenu)
221 for file in glob.glob("/local/chris/SALOME2/SUPERV/YACS/BR_CC/YACS_SRC/src/pyqt/*loader.py"):
222 d,f=os.path.split(file)
224 def call_loader(event,obj=self,file=file):
225 obj.openFileWithLoader(file)
226 self.loaders.append(call_loader)
227 self.loadersMenu.insertItem(name, call_loader)
228 menubar.insertItem('&File',self.fileMenu)
231 self.settingsMenu = QPopupMenu(self)
232 menubar.insertItem('&Settings', self.settingsMenu)
233 self.settingsMenu.insertTearOffHandle()
234 self.prefAct.addTo(self.settingsMenu)
237 self.editMenu = QPopupMenu(self)
238 self.editMenu.insertItem("&Add node", self.addNode)
239 menubar.insertItem('&Edit', self.editMenu)
243 self.layoutMenu = QPopupMenu(self)
244 self.layoutMenu.insertItem("&Left Right", self.LR)
245 self.layoutMenu.insertItem("Right Left", self.RL)
246 self.layoutMenu.insertItem("Top Bottom", self.TB)
247 self.layoutMenu.insertItem("Bottom Top", self.BT)
248 self.canvasMenu = QPopupMenu(self)
249 self.canvasMenu.insertItem("&Zoom in", self.zoomIn)
250 self.canvasMenu.insertItem("Zoom &out", self.zoomOut)
251 self.canvasMenu.insertItem("Layout", self.layoutMenu)
252 self.canvasMenu.insertItem("Ortholinks", self.orthoLinks)
253 self.canvasMenu.insertItem("Clearlinks", self.clearLinks)
254 self.canvasMenu.insertItem("&Update", self.updateCanvas)
255 menubar.insertItem('&Canvas', self.canvasMenu)
258 self.windowMenu = QPopupMenu(self)
259 self.cataToolAct.addTo(self.windowMenu)
260 self.windowMenu.insertItem("&Log", self.view_log)
261 menubar.insertItem('&Window', self.windowMenu)
262 self.connect(self.windowMenu, SIGNAL('aboutToShow()'), self.handleWindowMenu)
265 self.help=QPopupMenu(self)
266 menubar.insertItem('&Help',self.help)
267 self.help.insertItem('&About',self.about,Qt.Key_F1)
268 self.help.insertItem('About &Qt',self.aboutQt)
274 self.runtime= pilot.getRuntime()
275 self.loader = loader.YACSLoader()
276 self.executor = pilot.ExecutorSwig()
277 self.salomeloader=salomeloader.SalomeLoader()
278 self.loader.registerProcCataLoader()
280 def openSalomeFile(self):
281 fn = QFileDialog.getOpenFileName(QString.null,QString.null,self)
283 self.statusBar().message('Loading aborted',2000)
286 proc=self.salomeloader.load(fileName)
287 logger=proc.getLogger("parser")
288 if logger.hasErrors():
289 self.logFile=logview.LogView()
290 self.logFile.text.setText(logger.getStr())
293 panel=Browser(self.tabWidget,proc)
294 self.currentPanel=panel
295 self.tabWidget.addTab( panel,os.path.basename(fileName))
296 self.tabWidget.showPage(panel)
299 fn = QFileDialog.getOpenFileName(QString.null,QString.null,self)
301 self.statusBar().message('Loading aborted',2000)
304 proc=self.loader.load(fileName)
305 logger=proc.getLogger("parser")
306 if logger.hasErrors():
307 self.logFile=logview.LogView()
308 self.logFile.text.setText(logger.getStr())
311 panel=Browser(self.tabWidget,proc)
312 self.currentPanel=panel
313 self.tabWidget.addTab( panel,os.path.basename(fileName))
314 self.tabWidget.showPage(panel)
318 proc=r.createProc("pr")
319 panel=Browser(self.tabWidget,proc)
320 self.currentPanel=panel
321 self.tabWidget.addTab( panel,proc.getName())
322 self.tabWidget.showPage(panel)
324 def openFileWithLoader(self,file):
325 d,f=os.path.split(file)
327 module=__import__(os.path.splitext(f)[0])
329 loader=module.Loader()
331 fn = QFileDialog.getOpenFileName(QString.null,QString.null,self)
333 self.statusBar().message('Loading aborted',2000)
336 proc=loader.load(fileName)
337 logger=proc.getLogger("parser")
338 if logger.hasErrors():
339 self.logFile=logview.LogView()
340 self.logFile.text.setText(logger.getStr())
343 panel=Browser(self.tabWidget,proc)
344 self.currentPanel=panel
345 self.tabWidget.addTab( panel,os.path.basename(fileName))
346 self.tabWidget.showPage(panel)
349 self.catalogTool=catalog.CatalogTool(self)
350 self.catalogTool.show()
354 if self.currentPanel:
355 self.currentPanel.view_log()
357 def LR(self,*args ):self.rankdir("LR")
358 def RL(self,*args ):self.rankdir("RL")
359 def TB(self,*args ):self.rankdir("TB")
360 def BT(self,*args ):self.rankdir("BT")
362 def rankdir(self,orient):
363 if self.currentPanel and self.currentPanel.panelManager.visible:
364 self.currentPanel.panelManager.visible.layout(orient)
366 def updateCanvas(self):
367 if self.currentPanel.selected:#item selected
368 if isinstance(self.currentPanel.selected,Items.ItemComposedNode):
370 self.currentPanel.selected.graph.editor.updateCanvas()
372 def addNode(self,node):
373 if self.currentPanel and self.currentPanel.selected:#item selected
374 if isinstance(self.currentPanel.selected,Items.ItemComposedNode):
376 self.currentPanel.selected.addNode(node)
379 if self.currentPanel and self.currentPanel.panelManager.visible:
380 if isinstance(self.currentPanel.panelManager.visible,Items.ItemComposedNode):
382 self.currentPanel.panelManager.visible.graph.editor.zoomIn()
385 if self.currentPanel and self.currentPanel.panelManager.visible:
386 if isinstance(self.currentPanel.panelManager.visible,Items.ItemComposedNode):
388 self.currentPanel.panelManager.visible.graph.editor.zoomOut()
390 def orthoLinks(self):
391 if self.currentPanel and self.currentPanel.panelManager.visible:
392 if isinstance(self.currentPanel.panelManager.visible,Items.ItemComposedNode):
393 #it is a composed node with a graph
394 self.currentPanel.panelManager.visible.graph.orthoLinks()
396 def clearLinks(self):
397 if self.currentPanel and self.currentPanel.panelManager.visible:
398 if isinstance(self.currentPanel.panelManager.visible,Items.ItemComposedNode):
399 #it is a composed node with a graph
400 self.currentPanel.panelManager.visible.graph.clearLinks()
402 def handlePreferences(self):
405 def handleWindowMenu(self):
409 QMessageBox.about(self,'YACS browser GUI', 'YACS browser GUI')
412 QMessageBox.aboutQt(self,'YACS browser GUI')
415 if self.currentPanel:
416 self.currentPanel.run()
419 if self.currentPanel:
420 self.currentPanel.susp()
423 if self.currentPanel:
424 self.currentPanel.step()
427 if self.currentPanel:
428 self.currentPanel.stop()
430 def initToolbar(self):
432 self.newAct.addTo(tb)
433 self.runAct.addTo(tb)
434 self.suspAct.addTo(tb)
435 self.stepAct.addTo(tb)
436 self.stopAct.addTo(tb)
438 self.toolbars['File']=tb
440 def initStatusbar(self):
441 sb = self.statusBar()
442 self.SBfile=QLabel(sb)
443 sb.addWidget(self.SBfile)
444 QWhatsThis.add(self.SBfile,
445 """<p>Partie de la statusbar qui donne le nom"""
446 """du fichier courant. </p>""")
447 self.SBfile.setText("")
450 if __name__ == "__main__":
451 from Item import Item
452 app = QApplication(sys.argv)
454 t.objectBrowser.additem(Item("item1"))
455 n=t.objectBrowser.additem(Item("item2"))
456 n.additem(Item("item3"))