]> SALOME platform Git repositories - samples/pyhello.git/blob - src/PYHELLOGUI/PYHELLOGUI.py
Salome HOME
8f81e8d4bc620bae1c89b2dfdc7e433e2c148612
[samples/pyhello.git] / src / PYHELLOGUI / PYHELLOGUI.py
1 import qt
2 from qt import *
3 import traceback
4
5 # Global variable to store Salome Workspace
6 WORKSPACE=None
7
8 import SalomePyQt
9 # Communication with Salome : desktop, signal and slots
10 sgPyQt=SalomePyQt.SalomePyQt()
11 desktop=sgPyQt.getDesktop()
12
13 # LifeCycle and component PYHELLO
14 import salome
15 lifecycle = salome.lcc
16 import PYHELLO_ORB
17 pyhello=lifecycle.FindOrLoadComponent("FactoryServerPy", "PYHELLO")
18
19 def setWorkSpace(pyws):
20     global WORKSPACE
21     print "setWorkSpace: ",pyws
22     WORKSPACE=pyws
23
24 def OnGUIEvent(commandID) :
25     print "PYHELLOGUI::OnGUIEvent::commandID,WORKSPACE= ",commandID,WORKSPACE
26     if dict_command.has_key(commandID):
27        try:
28           r=dict_command[commandID](WORKSPACE)
29           print r
30        except:
31           traceback.print_exc()
32     else:
33        print "Pas de commande associée a : ",commandID
34
35 def setSettings():
36     print "setSettings"
37
38 def activeStudyChanged(ID):
39     print "activeStudyChanged: ",ID
40
41 def definePopup(theContext, theObject, theParent):
42     print "PYHELLOGUI --- definePopup: ",theContext,theObject,theParent
43
44 def customPopup(popup, theContext, theObject, theParent):
45     print "PYHELLOGUI --- customPopup: ",theContext,theObject,theParent
46
47 class MyDialog(qt.QDialog):
48       def __init__(self,parent=None, name=None, modal=0, flags=0):
49           qt.QDialog.__init__(self,parent, name, modal, flags)
50           self.vb = qt.QVBoxLayout(self, 8)
51           self.vb.setAutoAdd(1)
52           self.hb0 = qt.QHBox(self)
53           label=QLabel("Prenom",self.hb0)
54           self.entry=QLineEdit( self.hb0)
55
56           self.hb = qt.QHBox(self)
57           c = qt.QPushButton("OK", self.hb)
58           self.connect(c, qt.SIGNAL('clicked()'), self.accept)
59           d = qt.QPushButton("CANCEL", self.hb)
60           self.connect(d, qt.SIGNAL('clicked()'), self.reject)
61
62 def ExecPYHELLO(ws):
63     # Modal dialog, parent desktop
64     w=MyDialog(desktop,"Name",1)
65     # Wait answer
66     r=w.exec_loop()
67     if r == QDialog.Accepted:
68        name=str(w.entry.text())
69        banner=pyhello.makeBanner(name)
70        QMessageBox.about(desktop,'Salome Example',banner)
71     else:
72        print "CANCEL"
73
74 dict_command={
75                941:ExecPYHELLO,
76              }