1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2010-2016 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, or (at your option) any later version.
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
21 from qtsalome import QDialog, QMessageBox
22 from salome.gui.genericdialog_ui import Ui_GenericDialog
25 class GenericDialog(QDialog):
27 This is an abstract generic dialog box for implementing default and
28 generic behaviour of dialog windows.
29 Note that this class can be instantiated but can't be used because the
30 OK behaviour is a default one indicating that the checkData function should
31 be implemented in a derived class. The general interface that should be
32 implemented in derived class is the MVC pattern:
34 - setData(<a_data_model_object>):
35 to initiate the values of the dialog windows from a given data model.
37 - boolean checkData():
38 to verify that the data are valid and notify user if not.
40 - <a_data_model_object> getData():
41 to get the valid data model from values read in the dialog window.
47 def __init__(self,parent = None,name = None,modal = 0,fl = 0):
48 QDialog.__init__(self,parent)
49 # Set up the user interface from Designer.
50 self.__ui = Ui_GenericDialog()
51 self.__ui.setupUi(self)
55 This returns the central panel where to draw the custom dialog
58 return self.__ui.myCenterPanel
60 def getButtonBox(self):
61 return self.__ui.buttonBox
65 Slot function connected to the button OK
67 if not self.checkData():
68 QMessageBox.warning( self, "Alerte", self.checkDataMessage)
73 def displayAndWait(self):
75 This function can be used to display the dialog in the case
76 where the dialog is modal and does not need interactivity with
77 parent windows and other part of the application. When called,
78 the dialog is raised visible and keep waiting until the button
79 OK or the button CANCEL is pressed. Then the flow can go on
80 (see an example of implementation in the tests functions at
81 the end of this file).
82 In the general case, in particular if you need interaction
83 with the graphical framework (clic on widgets embedded in
84 other dialogs), you should used instead the show() command
85 (for a non modal dialog) or the open() command (for a window
86 modal dialog, i.e. a dialog that can not interact with its
87 direct parent but can interact with the other parts).
94 Return True if the button OK was pressed to close the dialog windows.
100 This function should be implemented in a derived class. It should return
101 True in the case where the data are estimated to be valid data.
103 self.checkDataMessage = "The checkData() function is not implemented yet"
107 # ==============================================================================
108 # Basic use cases and unit test functions
109 # ==============================================================================
111 def TEST_GenericDialog():
113 from qtsalome import QApplication
114 app = QApplication(sys.argv)
115 app.lastWindowClosed.connect(app.quit)
120 print("OK has been pressed")
122 print("Cancel has been pressed")
124 if __name__ == "__main__":