Salome HOME
add the template command
[tools/sat.git] / data / templates / PythonComponent / src / Dialog / Dialog.py
1 from PyQt4.QtGui import *
2 from PyQt4.QtCore import *
3
4 class Dialog( QDialog ) :
5
6    def __init__( self, helpFile, controller, widgetDialogBox ) :
7        """Constructor"""
8
9        # Initializing parent widget
10        QDialog.__init__( self )
11
12        # Setting attributes
13        self.setObjectName( "Dialog" )
14        self.setWindowTitle( "Dialog data" )
15        self._helpFile = helpFile
16        self._controller = controller
17        self._widgetDialogBox = widgetDialogBox
18
19        # Setting layouts
20        self.mainLayout = QVBoxLayout( self )
21        self.h1 = QHBoxLayout( self )
22        self.h2 = QHBoxLayout( self )
23        self.mainLayout.addLayout( self.h1 )
24        self.mainLayout.addLayout( self.h2 )
25        self.v11 = QVBoxLayout( self)
26        self.v12 = QVBoxLayout( self )
27        self.h1.addLayout( self.v11 )
28        self.h1.addLayout( self.v12 )
29
30        # Filling layouts with standard widgets( common to all childre )
31        self.fillStandardWidgets()
32        # Adding special widgets to layouts( special to each child )
33        self.addSpecialWidgets()
34
35        # Connecting widgets to slots
36        self.connectSlots()
37        pass
38
39    def getController( self ) :
40        return self._controller
41
42    def fillStandardWidgets( self ) :
43
44        lName = QLabel( "Name", self )
45        self.v11.addWidget( lName )
46
47        self.entryName = QLineEdit( self )
48        self.v12.addWidget( self.entryName )
49
50        #Setting buttons
51        self.bApply = QPushButton( "Apply", self )
52        self.h2.addWidget( self.bApply )
53        self.bClose = QPushButton( "Close", self )
54        self.h2.addWidget( self.bClose )
55        self.bHelp = QPushButton( "Help", self )
56        self.h2.addWidget( self.bHelp )
57        pass
58
59    def addSpecialWidgets( self ) :
60        print 'Virtual method'
61        pass
62
63    def connectSlots( self ) :
64        self.connect( self.bApply, SIGNAL( 'clicked()' ), self.apply )
65        self.connect( self.bHelp, SIGNAL( 'clicked()' ), self.help )
66        self.connect( self.bClose, SIGNAL( 'clicked()' ), self.close )
67        pass
68
69    def apply( self ) :
70
71        self.retrieveUserEntries()
72        if not self.checkUserEntries() :
73           QMessageBox.warning( self, 'information faillure', self.errMessage )
74           return
75        self.execApply()
76        return
77
78    def retrieveUserEntries( self ) :
79        self.name = str( self.entryName.text() )
80        pass
81
82    def checkUserEntries( self ) :
83        if self.name == "" :
84           self.errMessage = 'All attributes must be filled'
85           return False
86        return True
87
88    def execApply( self ) :
89        print 'Virtual method'
90        pass
91
92    def reInitializeDialog( self ) :
93        print 'Virtual method'
94        pass
95
96    def help( self ) :
97        import os
98        os.system( 'firefox ' + self._helpFile + '&' )
99        pass
100
101    def close( self ) :
102        self._widgetDialogBox.close()
103        pass
104
105 pass