1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2010-2012 CEA/DEN, EDF R&D, OPEN CASCADE
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 __date__ ="$31 mars 2010 17:09:53$"
24 from PyQt4.QtGui import QDialog, QMessageBox
26 from genericdialog_ui import Ui_GenericDialog
28 class GenericDialog(QDialog):
30 This is an abstract generic dialog box for implementing default and
31 generic behaviour of dialog windows.
32 Note that this class can be instantiated but can't be used because the
33 OK behaviour is a default one indicating that the checkData function should
34 be implemented in a derived class. The general interface that should be
35 implemented in derived class is the MVC pattern:
37 - setData(<a_data_model_object>):
38 to initiate the values of the dialog windows from a given data model.
40 - boolean checkData():
41 to verify that the data are valid and notify user if not.
43 - <a_data_model_object> getData():
44 to get the valid data model from values read in the dialog window.
50 def __init__(self,parent = None,name = None,modal = 0,fl = 0):
51 QDialog.__init__(self,parent)
52 # Set up the user interface from Designer.
53 self.__ui = Ui_GenericDialog()
54 self.__ui.setupUi(self)
58 This returns the central panel where to draw the custom dialog
61 return self.__ui.myCenterPanel
63 def getButtonBox(self):
64 return self.__ui.buttonBox
68 Slot function connected to the button OK
70 if not self.checkData():
71 QMessageBox.warning( self, "Alerte", self.checkDataMessage)
76 def displayAndWait(self):
78 This function can be used to display the dialog in the case
79 where the dialog is modal and does not need interactivity with
80 parent windows and other part of the application. When called,
81 the dialog is raised visible and keep waiting until the button
82 OK or the button CANCEL is pressed. Then the flow can go on
83 (see an example of implementation in the tests functions at
84 the end of this file).
85 In the general case, in particular if you need interaction
86 with the graphical framework (clic on widgets embedded in
87 other dialogs), you should used instead the show() command
88 (for a non modal dialog) or the open() command (for a window
89 modal dialog, i.e. a dialog that can not interact with its
90 direct parent but can interact with the other parts).
97 Return True if the button OK was pressed to close the dialog windows.
103 This function should be implemented in a derived class. It should return
104 True in the case where the data are estimated to be valid data.
106 self.checkDataMessage = "The checkData() function is not implemented yet"
110 # ==============================================================================
111 # Basic use cases and unit test functions
112 # ==============================================================================
114 def TEST_GenericDialog():
116 from PyQt4.QtGui import QApplication
117 from PyQt4.QtCore import QObject, SIGNAL, SLOT
118 app = QApplication(sys.argv)
119 QObject.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
124 print "OK has been pressed"
126 print "Cancel has been pressed"
128 if __name__ == "__main__":