1 # Copyright (C) 2010-2016 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, or (at your option) any later version.
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 qtsalome import *
24 from tubedialog_ui import TubeDialog_UI
27 class TubeDialog(TubeDialog_UI):
29 TubeDialog_UI.setupUi(self)
30 self.handleAcceptWith(self.accept)
31 self.handleRejectWith(self.reject)
33 def handleAcceptWith(self,callbackFunction):
34 """This defines the function to be connected to the signal 'accepted()' (click on Ok)"""
35 self.buttonBox.accepted.connect(callbackFunction)
37 def handleRejectWith(self,callbackFunction):
38 """This defines the function to be connected to the signal 'rejected()' (click on Cancel)"""
39 self.buttonBox.rejected.connect(callbackFunction)
41 def handleApplyWith(self,callbackFunction):
42 """This defines the function to be connected to the signal 'apply()' (click on Apply)"""
43 button = self.buttonBox.button(QDialogButtonBox.Apply)
44 button.clicked.connect(callbackFunction);
47 '''Callback function when dialog is accepted (click Ok)'''
49 # We should test here the validity of values
53 '''Callback function when dialog is rejected (click Cancel)'''
60 def setData(self, radius, length, width):
61 self.txtRadius.setText(str(radius))
62 self.txtLength.setText(str(length))
63 self.txtWidth.setText(str(width))
67 radius=eval(str(self.txtRadius.text()))
68 length=eval(str(self.txtLength.text()))
69 width=eval(str(self.txtWidth.text()))
71 print("pb a la saisie")
73 return radius, length, width
76 class TubeDialogOnTopWithApply(TubeDialog):
79 This setupUi adds a button 'Apply' to execute a processing
80 tasks (ex: preview), and set a flag that keeps the dialog on
83 TubeDialog.setupUi(self)
84 # Add a button "Apply"
85 self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|
86 QDialogButtonBox.Apply|
89 # Keep the dialog on top of the windows
90 self.setWindowFlags(self.windowFlags() |
91 Qt.WindowStaysOnTopHint)
95 # ======================================================================
97 # ======================================================================
99 def TEST_getData_synchrone():
100 """This use case illustrates the MVC pattern on this simple dialog example"""
101 tubedialog = TubeDialog()
102 tubedialog.setData(10,50,3)
104 if tubedialog.wasOk():
105 radius, length, width = tubedialog.getData()
106 print(radius, length, width)
110 a = QApplication(sys.argv)
111 TEST_getData_synchrone()
114 if __name__=="__main__":