2525
2626from PyQt4 .QtCore import *
2727from PyQt4 .QtGui import *
28- from PyQt4 import QtCore , QtGui
28+
2929from sextante .core .SextanteConfig import SextanteConfig
3030
31+ from sextante .ui .ui_DlgConfig import Ui_DlgConfig
3132
32- class ConfigDialog (QtGui . QDialog ):
33+ class ConfigDialog (QDialog , Ui_DlgConfig ):
3334 def __init__ (self , toolbox ):
34- QtGui .QDialog .__init__ (self )
35+ QDialog .__init__ (self )
36+ self .setupUi (self )
37+
3538 self .toolbox = toolbox
36- self .setupUi ()
3739
38- def setupUi (self ):
39- self .resize (700 , 500 )
40- self .setWindowTitle ("SEXTANTE options" )
41- self .verticalLayout = QtGui .QVBoxLayout ()
42- self .verticalLayout .setSpacing (2 )
43- self .verticalLayout .setMargin (0 )
44- self .searchBox = QtGui .QLineEdit ()
45- self .searchBox .textChanged .connect (self .fillTree )
46- self .verticalLayout .addWidget (self .searchBox )
47- self .groupIcon = QtGui .QIcon ()
48- self .groupIcon .addPixmap (self .style ().standardPixmap (QtGui .QStyle .SP_DirClosedIcon ),
49- QtGui .QIcon .Normal , QtGui .QIcon .Off )
50- self .groupIcon .addPixmap (self .style ().standardPixmap (QtGui .QStyle .SP_DirOpenIcon ),
51- QtGui .QIcon .Normal , QtGui .QIcon .On )
52- self .keyIcon = QtGui .QIcon ()
53- self .keyIcon .addPixmap (self .style ().standardPixmap (QtGui .QStyle .SP_FileIcon ))
54- self .tree = QtGui .QTreeWidget ()
55- self .tree .setHeaderLabels (("Setting" , "Value" ))
56- self .tree .header ().setResizeMode (0 , QtGui .QHeaderView .Stretch )
57- self .tree .header ().setResizeMode (1 , QtGui .QHeaderView .Stretch )
58- self .fillTree ()
59- self .verticalLayout .addWidget (self .tree )
60- self .horizontalLayout = QtGui .QHBoxLayout ()
61- self .horizontalLayout .setSpacing (2 )
62- self .horizontalLayout .setMargin (0 )
63- self .buttonBox = QtGui .QDialogButtonBox ()
64- self .buttonBox .setOrientation (QtCore .Qt .Horizontal )
65- self .buttonBox .setStandardButtons (QtGui .QDialogButtonBox .Cancel | QtGui .QDialogButtonBox .Ok )
66- self .horizontalLayout .addSpacing (100 )
67- self .horizontalLayout .addWidget (self .buttonBox )
68- self .verticalLayout .addLayout (self .horizontalLayout )
69- self .setLayout (self .verticalLayout )
70- QtCore .QObject .connect (self .buttonBox , QtCore .SIGNAL ("accepted()" ), self .okPressed )
71- QtCore .QObject .connect (self .buttonBox , QtCore .SIGNAL ("rejected()" ), self .cancelPressed )
72- QtCore .QMetaObject .connectSlotsByName (self )
40+ self .groupIcon = QIcon ()
41+ self .groupIcon .addPixmap (self .style ().standardPixmap (QStyle .SP_DirClosedIcon ),
42+ QIcon .Normal , QIcon .Off )
43+ self .groupIcon .addPixmap (self .style ().standardPixmap (QStyle .SP_DirOpenIcon ),
44+ QIcon .Normal , QIcon .On )
7345
46+ self .fillTree ()
7447
7548 def fillTree (self ):
7649 self .items = {}
7750 self .tree .clear ()
7851 text = str (self .searchBox .text ())
7952 settings = SextanteConfig .getSettings ()
8053 for group in settings .keys ():
81- groupItem = QtGui . QTreeWidgetItem ()
54+ groupItem = QTreeWidgetItem ()
8255 groupItem .setText (0 ,group )
8356 icon = SextanteConfig .getGroupIcon (group )
8457 groupItem .setIcon (0 , icon )
85- #groupItem.setIcon(0,self.groupIcon)
8658 for setting in settings [group ]:
8759 if setting .hidden :
8860 continue
@@ -93,44 +65,46 @@ def fillTree(self):
9365 self .tree .addTopLevelItem (groupItem )
9466 if text != "" :
9567 groupItem .setExpanded (True )
68+
9669 self .tree .sortItems (0 , Qt .AscendingOrder )
70+ self .tree .resizeColumnToContents (0 )
71+ self .tree .resizeColumnToContents (1 )
9772
98- def okPressed (self ):
73+ def accept (self ):
9974 for setting in self .items .keys ():
10075 if isinstance (setting .value ,bool ):
101- setting .value = (self .items [setting ].checkState (1 ) == QtCore . Qt .Checked )
76+ setting .value = (self .items [setting ].checkState (1 ) == Qt .Checked )
10277 elif isinstance (setting .value , (float ,int , long )):
10378 value = str (self .items [setting ].text (1 ))
10479 try :
10580 value = float (value )
10681 setting .value = value
10782 except ValueError :
108- QtGui .QMessageBox .critical (self , "Wrong value" ,"Wrong parameter value:\n " + value )
83+ QMessageBox .critical (self ,
84+ self .tr ("Wrong value" ),
85+ self .tr ("Wrong parameter value:\n %1" ).arg (value )
86+ )
10987 return
11088 else :
11189 setting .value = str (self .items [setting ].text (1 ))
11290 SextanteConfig .addSetting (setting )
11391 SextanteConfig .saveSettings ()
11492 self .toolbox .updateTree ()
115- self .close ()
116-
117-
118- def cancelPressed (self ):
119- self .close ()
12093
94+ QDialog .accept (self )
12195
122- class TreeSettingItem (QtGui . QTreeWidgetItem ):
96+ class TreeSettingItem (QTreeWidgetItem ):
12397
12498 def __init__ (self , setting , icon ):
12599 QTreeWidgetItem .__init__ (self )
126100 self .setting = setting
127101 self .setText (0 , setting .description )
128- self .setFlags (self .flags () | QtCore . Qt .ItemIsEditable )
102+ self .setFlags (self .flags () | Qt .ItemIsEditable )
129103 if isinstance (setting .value ,bool ):
130104 if setting .value :
131- self .setCheckState (1 , QtCore . Qt .Checked )
105+ self .setCheckState (1 , Qt .Checked )
132106 else :
133- self .setCheckState (1 , QtCore . Qt .Unchecked )
107+ self .setCheckState (1 , Qt .Unchecked )
134108 else :
135109 self .setText (1 , str (setting .value ))
136110 self .setIcon (0 , icon )
0 commit comments