Salome HOME
The application now has separate desktop for each study, so desktop should be reiniti...
[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
12 # LifeCycle and component PYHELLO
13 import salome
14 lifecycle = salome.lcc
15 import PYHELLO_ORB
16 pyhello=lifecycle.FindOrLoadComponent("FactoryServerPy", "PYHELLO")
17
18 def setWorkSpace(pyws):
19     global WORKSPACE
20     print "setWorkSpace: ",pyws
21     WORKSPACE=pyws
22
23 def OnGUIEvent(commandID) :
24     print "PYHELLOGUI::OnGUIEvent::commandID,WORKSPACE= ",commandID,WORKSPACE
25     if dict_command.has_key(commandID):
26        try:
27           r=dict_command[commandID](WORKSPACE)
28           print r
29        except:
30           traceback.print_exc()
31     else:
32        print "Pas de commande associĆ©e a : ",commandID
33
34 def setSettings():
35     print "setSettings"
36
37 def activeStudyChanged(ID):
38     print "activeStudyChanged: ",ID
39
40 def definePopup(theContext, theObject, theParent):
41     print "PYHELLOGUI --- definePopup: ",theContext,theObject,theParent
42
43 def customPopup(popup, theContext, theObject, theParent):
44     print "PYHELLOGUI --- customPopup: ",theContext,theObject,theParent
45
46 class MyDialog(qt.QDialog):
47       def __init__(self,parent=None, name=None, modal=0, flags=0):
48           qt.QDialog.__init__(self,parent, name, modal, flags)
49           self.vb = qt.QVBoxLayout(self, 8)
50           self.vb.setAutoAdd(1)
51           self.hb0 = qt.QHBox(self)
52           label=QLabel("Prenom",self.hb0)
53           self.entry=QLineEdit( self.hb0)
54
55           self.hb = qt.QHBox(self)
56           c = qt.QPushButton("OK", self.hb)
57           self.connect(c, qt.SIGNAL('clicked()'), self, SLOT('accept()'))
58           d = qt.QPushButton("CANCEL", self.hb)
59           self.connect(d, qt.SIGNAL('clicked()'), self, SLOT('reject()'))
60
61 def ExecPYHELLO(ws):
62     # Modal dialog, parent desktop
63     desktop=sgPyQt.getDesktop()
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              }