Version: 9.15.0
Appli.py
Go to the documentation of this file.
1 # Copyright (C) 2006-2025 CEA, EDF
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 
20 """
21 """
22 import sys,os
23 from qt import *
24 from . import Tree
25 from . import PanelManager
26 from . import BoxManager
27 from . import Icons
28 from . import Items
29 from . import adapt
30 from . import Item
31 from . import logview
32 import pilot
33 import threading
34 import time
35 from . import CONNECTOR
36 from . import catalog
37 import traceback
38 import glob
39 
41  def __init__(self,caption,msg):
42  QCustomEvent.__init__(self,8888)
43  self.captioncaption=caption
44  self.msgmsg=msg
45  def process(self,parent):
46  QMessageBox.warning(parent,self.captioncaption,self.msgmsg)
47 
48 class Runner(threading.Thread):
49  def __init__(self,parent,executor,proc):
50  threading.Thread.__init__(self)
51  self.parentparent=parent
52  self.executorexecutor=executor
53  self.procproc=proc
54 
55  def run(self):
56  try:
57  self.executorexecutor.RunW(self.procproc,0)
58  except ValueError as ex:
59  #traceback.print_exc()
60  QApplication.postEvent(self.parentparent, ErrorEvent('YACS execution error',str(ex)))
61 
62 class Browser(QVBox):
63  def __init__(self,parent,proc):
64  QVBox.__init__(self,parent)
65  pp=Item.adapt(proc)
66  self.procproc=proc
67  self.pprocpproc=pp
68  self.hSplitterhSplitter = QSplitter(self,"hSplitter")
69  self.objectBrowserobjectBrowser=Tree.Tree(self.hSplitterhSplitter,self.onSelectonSelect,self.onDblSelectonDblSelect)
70  self.objectBrowserobjectBrowser.additem(pp)
71  self.panelManagerpanelManager=PanelManager.PanelManager(self.hSplitterhSplitter)
72  self.panelManagerpanelManager.setRootItem(pp)
73  self.boxManagerboxManager=BoxManager.BoxManager(self.hSplitterhSplitter)
74  self.boxManagerboxManager.setRootItem(pp)
75  self.selectedselected=None
76  self.executorexecutor=None
77  self.resumeresume=0
78  self.thrthr=None
79  self.loglog=logview.LogView()
80 
81  def view_log(self):
82  self.loglog.text.setText(self.procproc.getLogger("parser").getStr())
83  self.loglog.show()
84 
85  def onDblSelect(self,item):
86  #item is instance of Item.Item
87  pass
88 
89  def onSelect(self,item):
90  #item is instance of Item.Item
91  self.selected=item
92 
93  def customEvent(self,ev):
94  if ev.type() == 8888:
95  ev.process(self)
96 
97  def run(self):
98  if not self.executorexecutor:
99  self.executorexecutor = pilot.ExecutorSwig()
100  if self.thrthr and self.thrthr.isAlive():
101  return
102  #continue execution mode
103  self.executorexecutor.setExecMode(0)
104  #execute it in a thread
105  self.thrthr = Runner(self, self.executorexecutor, self.procproc)
106  #as a daemon (no need to join)
107  self.thrthr.setDaemon(1)
108  #start the thread
109  self.thrthr.start()
110  time.sleep(0.1)
111  self.resumeresume=0
112 
113  def susp(self):
114  """Suspend or resume an executing schema"""
115  if not self.executorexecutor:
116  return
117  if not self.thrthr.isAlive():
118  return
119 
120  if self.resumeresume:
121  #continue execution mode
122  self.executorexecutor.setExecMode(0)
123  #resume it
124  self.executorexecutor.resumeCurrentBreakPoint()
125  self.resumeresume=0
126  else:
127  #step by step execution mode
128  self.executorexecutor.setExecMode(1)
129  self.resumeresume=1
130 
131  def step(self):
132  """Step on a paused schema"""
133  if not self.executorexecutor:
134  self.executorexecutor = pilot.ExecutorSwig()
135  if not self.thrthr or not self.thrthr.isAlive():
136  #start in step by step mode
137  self.executorexecutor.setExecMode(1)
138  self.thrthr = Runner(self, self.executorexecutor, self.procproc)
139  self.thrthr.setDaemon(1)
140  self.thrthr.start()
141  self.resumeresume=1
142  return
143 
144  #step by step execution mode
145  self.resumeresume=1
146  self.executorexecutor.setExecMode(1)
147  #resume it
148  self.executorexecutor.resumeCurrentBreakPoint()
149 
150  def stop(self):
151  """Stop the schema"""
152  if not self.executorexecutor:
153  return
154  if not self.thrthr.isAlive():
155  return
156  self.executorexecutor.setExecMode(1)
157  self.executorexecutor.waitPause()
158  self.executorexecutor.resumeCurrentBreakPoint()
159  #self.executor.stopExecution()
160 
162  """
163  Appli()
164  Cree la fenetre principale de l'interface utilisateur
165  """
166  def __init__(self):
167  QMainWindow.__init__(self)
168  self.createWidgetscreateWidgets()
169  self.initActionsinitActions()
170  self.initMenusinitMenus()
171  self.initToolbarinitToolbar()
172  self.initStatusbarinitStatusbar()
173  self.initYACSinitYACS()
174 
175  def createWidgets(self):
176  self.tabWidgettabWidget = QTabWidget(self)
177  self.currentPanelcurrentPanel=None
178  self.connect(self.tabWidgettabWidget, SIGNAL('currentChanged(QWidget *)'),self.handlePanelChangedhandlePanelChanged)
179  self.setCentralWidget(self.tabWidgettabWidget)
180  self.resize(800,600)
181 
182  def handlePanelChanged(self,panel):
183  self.currentPanelcurrentPanel=panel
184 
185  def initActions(self):
186  self.actionsactions = []
187 
188  self.newActnewAct=QAction('New', QIconSet(Icons.get_image("new")), '&New',
189  QKeySequence("CTRL+N"),self)
190  self.newActnewAct.setStatusTip('Open an empty editor window')
191  self.newActnewAct.setWhatsThis( """<b>New</b>"""
192  """<p>An empty editor window will be created.</p>""")
193  self.newActnewAct.connect(self.newActnewAct,SIGNAL('activated()'), self.newProcnewProc)
194  self.actionsactions.append(self.newActnewAct)
195 
196  self.prefActprefAct=QAction('Preferences',QIconSet(Icons.get_image("configure.png")),'&Preferences...',
197  0, self)
198  self.prefActprefAct.setStatusTip('Set the prefered configuration')
199  self.prefActprefAct.setWhatsThis("""<b>Preferences</b>"""
200  """<p>Set the configuration items of the application"""
201  """ with your prefered values.</p>""")
202  self.prefActprefAct.connect(self.prefActprefAct,SIGNAL('activated()'), self.handlePreferenceshandlePreferences)
203  self.actionsactions.append(self.prefActprefAct)
204 
205  self.runActrunAct=QAction('Run',QIconSet(Icons.get_image("run.png")),'&Run',0,self)
206  self.runActrunAct.connect(self.runActrunAct,SIGNAL('activated()'), self.runrun)
207  self.runActrunAct.setStatusTip('Run the selected schema')
208  self.actionsactions.append(self.runActrunAct)
209 
210  self.suspActsuspAct=QAction('Suspend/resume',QIconSet(Icons.get_image("suspend-resume.gif")),'&Suspend/resume',0,self)
211  self.suspActsuspAct.connect(self.suspActsuspAct,SIGNAL('activated()'), self.suspsusp)
212  self.suspActsuspAct.setStatusTip('Suspend/resume the selected schema')
213  self.actionsactions.append(self.suspActsuspAct)
214 
215  self.stepActstepAct=QAction('Step',QIconSet(Icons.get_image("steps.png")),'&Step',0,self)
216  self.stepActstepAct.connect(self.stepActstepAct,SIGNAL('activated()'), self.stepstep)
217  self.stepActstepAct.setStatusTip('Step the selected schema')
218  self.actionsactions.append(self.stepActstepAct)
219 
220  self.stopActstopAct=QAction('Stop',QIconSet(Icons.get_image("kill.png")),'&Stop',0,self)
221  self.stopActstopAct.connect(self.stopActstopAct,SIGNAL('activated()'), self.stopstop)
222  self.stopActstopAct.setStatusTip('Stop the selected schema')
223  self.actionsactions.append(self.stopActstopAct)
224 
225  self.cataToolActcataToolAct=QAction('Catalog Tool',0,self,"catatool")
226  self.cataToolActcataToolAct.connect(self.cataToolActcataToolAct,SIGNAL('activated()'), self.cata_toolcata_tool)
227  self.actionsactions.append(self.cataToolActcataToolAct)
228 
229  def initMenus(self):
230  menubar = self.menuBar()
231 
232  #menu file
233  self.fileMenufileMenu=QPopupMenu(self)
234  self.newActnewAct.addTo(self.fileMenufileMenu)
235  self.fileMenufileMenu.insertItem("&Open", self.openFileopenFile)
236  self.fileMenufileMenu.insertItem("&Open Salome", self.openSalomeFileopenSalomeFile)
237  self.loadersMenuloadersMenu = QPopupMenu(self)
238  self.fileMenufileMenu.insertItem("Loaders", self.loadersMenuloadersMenu)
239  self.loadersloaders=[]
240  for file in glob.glob("/local/chris/SALOME2/SUPERV/YACS/BR_CC/YACS_SRC/src/pyqt/*loader.py"):
241  d,f=os.path.split(file)
242  name=f[:-9]
243  def call_loader(event,obj=self,file=file):
244  obj.openFileWithLoader(file)
245  self.loadersloaders.append(call_loader)
246  self.loadersMenuloadersMenu.insertItem(name, call_loader)
247  menubar.insertItem('&File',self.fileMenufileMenu)
248 
249  #menu settings
250  self.settingsMenusettingsMenu = QPopupMenu(self)
251  menubar.insertItem('&Settings', self.settingsMenusettingsMenu)
252  self.settingsMenusettingsMenu.insertTearOffHandle()
253  self.prefActprefAct.addTo(self.settingsMenusettingsMenu)
254 
255  #menu Edit
256  self.editMenueditMenu = QPopupMenu(self)
257  self.editMenueditMenu.insertItem("&Add node", self.addNodeaddNode)
258  menubar.insertItem('&Edit', self.editMenueditMenu)
259 
260  #menu Canvas
261  #sous menu layout
262  self.layoutMenulayoutMenu = QPopupMenu(self)
263  self.layoutMenulayoutMenu.insertItem("&Left Right", self.LRLR)
264  self.layoutMenulayoutMenu.insertItem("Right Left", self.RLRL)
265  self.layoutMenulayoutMenu.insertItem("Top Bottom", self.TBTB)
266  self.layoutMenulayoutMenu.insertItem("Bottom Top", self.BTBT)
267  self.canvasMenucanvasMenu = QPopupMenu(self)
268  self.canvasMenucanvasMenu.insertItem("&Zoom in", self.zoomInzoomIn)
269  self.canvasMenucanvasMenu.insertItem("Zoom &out", self.zoomOutzoomOut)
270  self.canvasMenucanvasMenu.insertItem("Layout", self.layoutMenulayoutMenu)
271  self.canvasMenucanvasMenu.insertItem("Ortholinks", self.orthoLinksorthoLinks)
272  self.canvasMenucanvasMenu.insertItem("Clearlinks", self.clearLinksclearLinks)
273  self.canvasMenucanvasMenu.insertItem("&Update", self.updateCanvasupdateCanvas)
274  menubar.insertItem('&Canvas', self.canvasMenucanvasMenu)
275 
276  #menu window
277  self.windowMenuwindowMenu = QPopupMenu(self)
278  self.cataToolActcataToolAct.addTo(self.windowMenuwindowMenu)
279  self.windowMenuwindowMenu.insertItem("&Log", self.view_logview_log)
280  menubar.insertItem('&Window', self.windowMenuwindowMenu)
281  self.connect(self.windowMenuwindowMenu, SIGNAL('aboutToShow()'), self.handleWindowMenuhandleWindowMenu)
282 
283  #menu help
284  self.helphelp=QPopupMenu(self)
285  menubar.insertItem('&Help',self.helphelp)
286  self.helphelp.insertItem('&About',self.aboutabout,Qt.Key_F1)
287  self.helphelp.insertItem('About &Qt',self.aboutQtaboutQt)
288 
289  def initYACS(self):
290  import pilot
291  import loader
292  import salomeloader
293  self.runtimeruntime= pilot.getRuntime()
294  self.loaderloader = loader.YACSLoader()
295  self.executorexecutor = pilot.ExecutorSwig()
296  self.salomeloadersalomeloader=salomeloader.SalomeLoader()
297  self.loaderloader.registerProcCataLoader()
298 
299  def openSalomeFile(self):
300  fn = QFileDialog.getOpenFileName(QString.null,QString.null,self)
301  if fn.isEmpty():
302  self.statusBar().message('Loading aborted',2000)
303  return
304  fileName = str(fn)
305  proc=self.salomeloadersalomeloader.load(fileName)
306  logger=proc.getLogger("parser")
307  if logger.hasErrors():
308  self.logFilelogFile=logview.LogView()
309  self.logFilelogFile.text.setText(logger.getStr())
310  self.logFilelogFile.show()
311 
312  panel=Browser(self.tabWidgettabWidget,proc)
313  self.currentPanelcurrentPanel=panel
314  self.tabWidgettabWidget.addTab( panel,os.path.basename(fileName))
315  self.tabWidgettabWidget.showPage(panel)
316 
317  def openFile(self):
318  fn = QFileDialog.getOpenFileName(QString.null,QString.null,self)
319  if fn.isEmpty():
320  self.statusBar().message('Loading aborted',2000)
321  return
322  fileName = str(fn)
323  proc=self.loaderloader.load(fileName)
324  logger=proc.getLogger("parser")
325  if logger.hasErrors():
326  self.logFilelogFile=logview.LogView()
327  self.logFilelogFile.text.setText(logger.getStr())
328  self.logFilelogFile.show()
329 
330  panel=Browser(self.tabWidgettabWidget,proc)
331  self.currentPanelcurrentPanel=panel
332  self.tabWidgettabWidget.addTab( panel,os.path.basename(fileName))
333  self.tabWidgettabWidget.showPage(panel)
334 
335  def newProc(self):
336  r=pilot.getRuntime()
337  proc=r.createProc("pr")
338  panel=Browser(self.tabWidgettabWidget,proc)
339  self.currentPanelcurrentPanel=panel
340  self.tabWidgettabWidget.addTab( panel,proc.getName())
341  self.tabWidgettabWidget.showPage(panel)
342 
343  def openFileWithLoader(self,file):
344  d,f=os.path.split(file)
345  sys.path.insert(0,d)
346  module=__import__(os.path.splitext(f)[0])
347  del sys.path[0]
348  loader=module.Loader()
349 
350  fn = QFileDialog.getOpenFileName(QString.null,QString.null,self)
351  if fn.isEmpty():
352  self.statusBar().message('Loading aborted',2000)
353  return
354  fileName = str(fn)
355  proc=loader.load(fileName)
356  logger=proc.getLogger("parser")
357  if logger.hasErrors():
358  self.logFilelogFile=logview.LogView()
359  self.logFilelogFile.text.setText(logger.getStr())
360  self.logFilelogFile.show()
361 
362  panel=Browser(self.tabWidgettabWidget,proc)
363  self.currentPanelcurrentPanel=panel
364  self.tabWidgettabWidget.addTab( panel,os.path.basename(fileName))
365  self.tabWidgettabWidget.showPage(panel)
366 
367  def cata_tool(self):
368  self.catalogToolcatalogTool=catalog.CatalogTool(self)
369  self.catalogToolcatalogTool.show()
370  return
371 
372  def view_log(self):
373  if self.currentPanelcurrentPanel:
374  self.currentPanelcurrentPanel.view_log()
375 
376  def LR(self,*args ):self.rankdir("LR")
377  def RL(self,*args ):self.rankdir("RL")
378  def TB(self,*args ):self.rankdir("TB")
379  def BT(self,*args ):self.rankdir("BT")
380 
381  def rankdir(self,orient):
382  if self.currentPanelcurrentPanel and self.currentPanelcurrentPanel.panelManager.visible:
383  self.currentPanelcurrentPanel.panelManager.visible.layout(orient)
384 
385  def updateCanvas(self):
386  if self.currentPanelcurrentPanel.selected:#item selected
387  if isinstance(self.currentPanelcurrentPanel.selected,Items.ItemComposedNode):
388  #can update
389  self.currentPanelcurrentPanel.selected.graph.editor.updateCanvas()
390 
391  def addNode(self,node):
392  if self.currentPanelcurrentPanel and self.currentPanelcurrentPanel.selected:#item selected
393  if isinstance(self.currentPanelcurrentPanel.selected,Items.ItemComposedNode):
394  #can add node
395  self.currentPanelcurrentPanel.selected.addNode(node)
396 
397  def zoomIn(self):
398  if self.currentPanelcurrentPanel and self.currentPanelcurrentPanel.panelManager.visible:
399  if isinstance(self.currentPanelcurrentPanel.panelManager.visible,Items.ItemComposedNode):
400  #we can zoom
401  self.currentPanelcurrentPanel.panelManager.visible.graph.editor.zoomIn()
402 
403  def zoomOut(self):
404  if self.currentPanelcurrentPanel and self.currentPanelcurrentPanel.panelManager.visible:
405  if isinstance(self.currentPanelcurrentPanel.panelManager.visible,Items.ItemComposedNode):
406  #we can unzoom
407  self.currentPanelcurrentPanel.panelManager.visible.graph.editor.zoomOut()
408 
409  def orthoLinks(self):
410  if self.currentPanelcurrentPanel and self.currentPanelcurrentPanel.panelManager.visible:
411  if isinstance(self.currentPanelcurrentPanel.panelManager.visible,Items.ItemComposedNode):
412  #it is a composed node with a graph
413  self.currentPanelcurrentPanel.panelManager.visible.graph.orthoLinks()
414 
415  def clearLinks(self):
416  if self.currentPanelcurrentPanel and self.currentPanelcurrentPanel.panelManager.visible:
417  if isinstance(self.currentPanelcurrentPanel.panelManager.visible,Items.ItemComposedNode):
418  #it is a composed node with a graph
419  self.currentPanelcurrentPanel.panelManager.visible.graph.clearLinks()
420 
421  def handlePreferences(self):
422  pass
423 
424  def handleWindowMenu(self):
425  pass
426 
427  def about(self):
428  QMessageBox.about(self,'YACS browser GUI', 'YACS browser GUI')
429 
430  def aboutQt(self):
431  QMessageBox.aboutQt(self,'YACS browser GUI')
432 
433  def run(self):
434  if self.currentPanelcurrentPanel:
435  self.currentPanelcurrentPanel.run()
436 
437  def susp(self):
438  if self.currentPanelcurrentPanel:
439  self.currentPanelcurrentPanel.susp()
440 
441  def step(self):
442  if self.currentPanelcurrentPanel:
443  self.currentPanelcurrentPanel.step()
444 
445  def stop(self):
446  if self.currentPanelcurrentPanel:
447  self.currentPanelcurrentPanel.stop()
448 
449  def initToolbar(self):
450  tb = QToolBar(self)
451  self.newActnewAct.addTo(tb)
452  self.runActrunAct.addTo(tb)
453  self.suspActsuspAct.addTo(tb)
454  self.stepActstepAct.addTo(tb)
455  self.stopActstopAct.addTo(tb)
456  self.toolbarstoolbars={}
457  self.toolbarstoolbars['File']=tb
458 
459  def initStatusbar(self):
460  sb = self.statusBar()
461  self.SBfileSBfile=QLabel(sb)
462  sb.addWidget(self.SBfileSBfile)
463  QWhatsThis.add(self.SBfileSBfile,
464  """<p>Partie de la statusbar qui donne le nom"""
465  """du fichier courant. </p>""")
466  self.SBfileSBfile.setText("")
467 
468 
469 if __name__ == "__main__":
470  from .Item import Item
471  app = QApplication(sys.argv)
472  t=Appli()
473  t.objectBrowser.additem(Item("item1"))
474  n=t.objectBrowser.additem(Item("item2"))
475  n.additem(Item("item3"))
476  app.setMainWidget(t)
477  t.show()
478  app.exec_loop()
479 
480 
def LR(self, *args)
Definition: Appli.py:376
def cata_tool(self)
Definition: Appli.py:367
def addNode(self, node)
Definition: Appli.py:391
def step(self)
Definition: Appli.py:441
def initMenus(self)
Definition: Appli.py:229
def TB(self, *args)
Definition: Appli.py:378
def susp(self)
Definition: Appli.py:437
def orthoLinks(self)
Definition: Appli.py:409
def initActions(self)
Definition: Appli.py:185
def initToolbar(self)
Definition: Appli.py:449
def zoomIn(self)
Definition: Appli.py:397
def handleWindowMenu(self)
Definition: Appli.py:424
def newProc(self)
Definition: Appli.py:335
def initYACS(self)
Definition: Appli.py:289
def openFile(self)
Definition: Appli.py:317
def zoomOut(self)
Definition: Appli.py:403
def handlePreferences(self)
Definition: Appli.py:421
def openFileWithLoader(self, file)
Definition: Appli.py:343
def clearLinks(self)
Definition: Appli.py:415
def stop(self)
Definition: Appli.py:445
def RL(self, *args)
Definition: Appli.py:377
def about(self)
Definition: Appli.py:427
def __init__(self)
Definition: Appli.py:166
def BT(self, *args)
Definition: Appli.py:379
def createWidgets(self)
Definition: Appli.py:175
def initStatusbar(self)
Definition: Appli.py:459
def aboutQt(self)
Definition: Appli.py:430
def rankdir(self, orient)
Definition: Appli.py:381
def openSalomeFile(self)
Definition: Appli.py:299
def run(self)
Definition: Appli.py:433
def updateCanvas(self)
Definition: Appli.py:385
def handlePanelChanged(self, panel)
Definition: Appli.py:182
def view_log(self)
Definition: Appli.py:372
def __init__(self, parent, proc)
Definition: Appli.py:63
def view_log(self)
Definition: Appli.py:81
def onSelect(self, item)
Definition: Appli.py:89
def stop(self)
Definition: Appli.py:150
def onDblSelect(self, item)
Definition: Appli.py:85
def susp(self)
Definition: Appli.py:113
def step(self)
Definition: Appli.py:131
def customEvent(self, ev)
Definition: Appli.py:93
def run(self)
Definition: Appli.py:97
def __init__(self, caption, msg)
Definition: Appli.py:41
def process(self, parent)
Definition: Appli.py:45
def __init__(self, parent, executor, proc)
Definition: Appli.py:49
def run(self)
Definition: Appli.py:55