1 # Copyright (C) 2010-2012 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 # Author : Guillaume Boulant (EDF)
22 from PyQt4 import QtGui
23 from PyQt4 import QtCore
25 from tubedialog_ui import TubeDialog_UI
28 class TubeDialog(TubeDialog_UI):
30 TubeDialog_UI.setupUi(self)
31 self.handleAcceptWith(self.accept)
32 self.handleRejectWith(self.reject)
34 def handleAcceptWith(self,callbackFunction):
35 """This defines the function to be connected to the signal 'accepted()' (click on Ok)"""
36 QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), callbackFunction)
38 def handleRejectWith(self,callbackFunction):
39 """This defines the function to be connected to the signal 'rejected()' (click on Cancel)"""
40 QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), callbackFunction)
42 def handleApplyWith(self,callbackFunction):
43 """This defines the function to be connected to the signal 'apply()' (click on Apply)"""
44 button = self.buttonBox.button(QtGui.QDialogButtonBox.Apply)
45 QtCore.QObject.connect(button, QtCore.SIGNAL("clicked()"), callbackFunction);
48 '''Callback function when dialog is accepted (click Ok)'''
50 # We should test here the validity of values
51 QtGui.QDialog.accept(self)
54 '''Callback function when dialog is rejected (click Cancel)'''
56 QtGui.QDialog.reject(self)
61 def setData(self, radius, length, width):
62 self.txtRadius.setText(str(radius))
63 self.txtLength.setText(str(length))
64 self.txtWidth.setText(str(width))
68 radius=eval(str(self.txtRadius.text()))
69 length=eval(str(self.txtLength.text()))
70 width=eval(str(self.txtWidth.text()))
72 print "pb a la saisie"
74 return radius, length, width
77 class TubeDialogOnTopWithApply(TubeDialog):
80 This setupUi adds a button 'Apply' to execute a processing
81 tasks (ex: preview), and set a flag that keeps the dialog on
84 TubeDialog.setupUi(self)
85 # Add a button "Apply"
86 self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|
87 QtGui.QDialogButtonBox.Apply|
88 QtGui.QDialogButtonBox.Ok)
90 # Keep the dialog on top of the windows
91 self.setWindowFlags(self.windowFlags() |
92 QtCore.Qt.WindowStaysOnTopHint)
96 # ======================================================================
98 # ======================================================================
100 def TEST_getData_synchrone():
101 """This use case illustrates the MVC pattern on this simple dialog example"""
102 tubedialog = TubeDialog()
103 tubedialog.setData(10,50,3)
105 if tubedialog.wasOk():
106 radius, length, width = tubedialog.getData()
107 print radius, length, width
111 a = QtGui.QApplication(sys.argv)
112 TEST_getData_synchrone()
115 if __name__=="__main__":