f1eaad6794f0fe54b54859d1df5816a3785d1f32
[bertos.git] / wizard / BModulePage.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # This file is part of BeRTOS.
5 #
6 # Bertos is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 #
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction.  Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License.  This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
28 #
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
30 #
31 #
32 # Author: Lorenzo Berni <duplo@develer.com>
33 #
34
35 import os
36
37 from PyQt4.QtCore import *
38 from PyQt4.QtGui import *
39 from BWizardPage import *
40 import bertos_utils
41
42 from bertos_utils import SupportedException
43 from DefineException import *
44 from const import *
45
46 class BModulePage(BWizardPage):
47     """
48     Page of the wizard that permits to select and configurate the BeRTOS modules.
49     """
50     
51     def __init__(self):
52         BWizardPage.__init__(self, UI_LOCATION + "/module_select.ui")
53         self.setTitle(self.tr("Configure the BeRTOS modules"))
54         self._control_group = QControlGroup()
55         ## special connection needed for the QControlGroup
56         self.connect(self._control_group, SIGNAL("stateChanged"), self.saveValue)
57     
58     ## Overloaded BWizardPage methods ##
59
60     def setupUi(self):
61         """
62         Overload of BWizardPage setupUi method.
63         """
64         self.pageContent.moduleTree.clear()
65         self.pageContent.moduleTree.setHeaderHidden(True)
66         self.pageContent.propertyTable.horizontalHeader().setResizeMode(QHeaderView.Stretch)
67         self.pageContent.propertyTable.horizontalHeader().setVisible(False)
68         self.pageContent.propertyTable.verticalHeader().setResizeMode(QHeaderView.ResizeToContents)
69         self.pageContent.propertyTable.verticalHeader().setVisible(False)
70         self.pageContent.propertyTable.setColumnCount(2)
71         self.pageContent.propertyTable.setRowCount(0)
72         self.pageContent.moduleLabel.setVisible(False)
73         self.pageContent.warningLabel.setVisible(False)
74     
75     def connectSignals(self):
76         """
77         Overload of the BWizardPage connectSignals method.
78         """
79         self.connect(self.pageContent.moduleTree, SIGNAL("itemPressed(QTreeWidgetItem*, int)"), self.fillPropertyTable)
80         self.connect(self.pageContent.moduleTree, SIGNAL("itemPressed(QTreeWidgetItem*, int)"), self.moduleClicked)
81         self.connect(self.pageContent.moduleTree, SIGNAL("itemChanged(QTreeWidgetItem*, int)"), self.dependencyCheck)
82
83     def reloadData(self, previous_id=None):
84         """
85         Overload of the BWizardPage reloadData method.
86         """
87         # Check if the user are approaching this page from the previous or the
88         # next one.
89         if previous_id is None or previous_id < self.wizard().currentId():
90             try:
91                 QApplication.instance().setOverrideCursor(Qt.WaitCursor)
92                 self.setupUi()
93                 self.loadModuleData()
94                 self.fillModuleTree()
95             finally:
96                 QApplication.instance().restoreOverrideCursor()
97     
98     ####
99     
100     ## Slots ##
101
102     def moduleClicked(self, item, column):
103         self.setBold(item, False)
104
105     def fillPropertyTable(self):
106         """
107         Slot called when the user selects a module from the module tree.
108         Fills the property table using the configuration parameters defined in
109         the source tree.
110         """
111         module = self.currentModule()
112         if module:
113             try:
114                 supported = bertos_utils.isSupported(self.project, module=module)
115             except SupportedException, e:
116                 self.exceptionOccurred(self.tr("Error evaluating \"%1\" for module %2").arg(e.support_string).arg(module))
117                 supported = True
118             self._control_group.clear()
119             configuration = self.projectInfo("MODULES")[module]["configuration"]
120             module_description = self.projectInfo("MODULES")[module]["description"]
121             self.pageContent.moduleLabel.setText(module_description)
122             self.pageContent.moduleLabel.setVisible(True)
123             if not supported:
124                 self.pageContent.warningLabel.setVisible(True)
125                 selected_cpu = self.projectInfo("CPU_NAME")
126                 self.pageContent.warningLabel.setText(self.tr("<font color='#FF0000'>Warning: the selected module, \
127                     is not completely supported by the %1.</font>").arg(selected_cpu))
128             else:
129                 self.pageContent.warningLabel.setVisible(False)
130             self.pageContent.propertyTable.clear()
131             self.pageContent.propertyTable.setRowCount(0)
132             if configuration != "":
133                 configurations = self.projectInfo("CONFIGURATIONS")[configuration]
134                 param_list = sorted(configurations["paramlist"])
135                 index = 0
136                 for i, property in param_list:
137                     if "type" in configurations[property]["informations"] and configurations[property]["informations"]["type"] == "autoenabled":
138                         # Doesn't show the hidden fields
139                         continue
140                     try:
141                         param_supported = bertos_utils.isSupported(self.project, property_id=(configuration, property))
142                     except SupportedException, e:
143                         self.exceptionOccurred(self.tr("Error evaluating \"%1\" for parameter %2").arg(e.support_string).arg(property))
144                         param_supported = True
145                     if not param_supported:
146                         # Doesn't show the unsupported parameters
147                         continue
148                     # Set the row count to the current index + 1
149                     self.pageContent.propertyTable.setRowCount(index + 1)
150                     item = QTableWidgetItem(configurations[property]["brief"])
151                     item.setFlags(item.flags() & ~Qt.ItemIsSelectable)
152                     tooltip = property
153                     description = configurations[property].get("description", None)
154                     if description:
155                         tooltip = tooltip + ": " + description
156                     item.setToolTip(tooltip)
157                     item.setData(Qt.UserRole, qvariant_converter.convertString(property))
158                     self.pageContent.propertyTable.setItem(index, 0, item)
159                     if "type" in configurations[property]["informations"] and configurations[property]["informations"]["type"] == "boolean":
160                         self.insertCheckBox(index, configurations[property]["value"])
161                     elif "type" in configurations[property]["informations"] and configurations[property]["informations"]["type"] == "enum":
162                         self.insertComboBox(index, configurations[property]["value"], configurations[property]["informations"]["value_list"])
163                     elif "type" in configurations[property]["informations"] and configurations[property]["informations"]["type"] == "int":
164                         self.insertSpinBox(index, configurations[property]["value"], configurations[property]["informations"])
165                     elif "type" in configurations[property]["informations"] and configurations[property]["informations"]["type"] == "hex":
166                         self.insertLineEdit(index, configurations[property]["value"], configurations[property]["informations"])
167                     else:
168                         # Not defined type, rendered as a text field
169                         self.pageContent.propertyTable.setItem(index, 1, QTableWidgetItem(configurations[property]["value"]))
170                     index += 1
171             if self.pageContent.propertyTable.rowCount() == 0:
172                 module_label = self.pageContent.moduleLabel.text()
173                 module_label += "\n\nNo configuration needed."
174                 self.pageContent.moduleLabel.setText(module_label) 
175         else:
176             self.pageContent.moduleLabel.setText("")
177             self.pageContent.moduleLabel.setVisible(False)
178             self.pageContent.propertyTable.clear()
179             self.pageContent.propertyTable.setRowCount(0)
180
181     def dependencyCheck(self, item):
182         """
183         Checks the dependencies of the module associated with the given item.
184         """
185         checked = False
186         module = unicode(item.text(0))
187         if item.checkState(0) == Qt.Checked:
188             self.moduleSelected(module)
189         else:
190             self.moduleUnselected(module)
191             self.removeFileDependencies(module)
192
193     def showPropertyDescription(self):
194         """
195         Slot called when the property selection changes. Shows the description
196         of the selected property.
197         """
198         self.resetPropertyDescription()
199         configurations = self.currentModuleConfigurations()
200         if self.currentProperty() in configurations:
201             description = configurations[self.currentProperty()]["brief"]
202             name = self.currentProperty()
203             self.currentPropertyItem().setText(description + "\n" + name)
204
205     def saveValue(self, index):
206         """
207         Slot called when the user modifies one of the configuration parameters.
208         It stores the new value."""
209         property = qvariant_converter.getString(self.pageContent.propertyTable.item(index, 0).data(Qt.UserRole))
210         configuration = self.projectInfo("MODULES")[self.currentModule()]["configuration"]
211         configurations = self.projectInfo("CONFIGURATIONS")
212         if "type" not in configurations[configuration][property]["informations"] or configurations[configuration][property]["informations"]["type"] == "int":
213             configurations[configuration][property]["value"] = unicode(int(self.pageContent.propertyTable.cellWidget(index, 1).value()))
214         elif configurations[configuration][property]["informations"]["type"] == "enum":
215             configurations[configuration][property]["value"] = unicode(self.pageContent.propertyTable.cellWidget(index, 1).currentText())
216         elif configurations[configuration][property]["informations"]["type"] == "boolean":
217             if self.pageContent.propertyTable.cellWidget(index, 1).isChecked():
218                 configurations[configuration][property]["value"] = "1"
219             else:
220                 configurations[configuration][property]["value"] = "0"
221         self.setProjectInfo("CONFIGURATIONS", configurations)
222         if self.moduleItem(self.currentModule()).checkState(0) == Qt.Checked:
223             self.dependencyCheck(self.moduleItem(self.currentModule()))
224
225     ####
226     
227     def loadModuleData(self):
228         """
229         Loads the module data.
230         """
231         # Do not load the module data again when the Wizard is in editing mode
232         # or when it's working on a preset.
233         if not self.project.edit and not self.project.from_preset:
234             # Load the module data every time so that if the user changed the cpu
235             # the right configurations are picked up.
236             try:
237                 self.project.loadModuleData()
238             except ModuleDefineException, e:
239                 self.exceptionOccurred(self.tr("Error parsing line '%2' in file %1").arg(e.path).arg(e.line))
240             except EnumDefineException, e:
241                 self.exceptionOccurred(self.tr("Error parsing line '%2' in file %1").arg(e.path).arg(e.line))
242             except ConfigurationDefineException, e:
243                 self.exceptionOccurred(self.tr("Error parsing line '%2' in file %1").arg(e.path).arg(e.line))
244     
245     def fillModuleTree(self):
246         """
247         Fills the module tree with the module entries separated in categories.
248         """
249         self.pageContent.moduleTree.clear()
250         modules = self.projectInfo("MODULES")
251         if not modules:
252             return
253         categories = {}
254         for module, information in modules.items():
255             if information["category"] not in categories:
256                 categories[information["category"]] = []
257             categories[information["category"]].append(module)
258         for category, module_list in categories.items():
259             item = QTreeWidgetItem(QStringList([category]))
260             for module in module_list:
261                 enabled = modules[module]["enabled"]
262                 module_item = QTreeWidgetItem(item, QStringList([module]))
263                 try:
264                     supported = bertos_utils.isSupported(self.project, module=module)
265                 except SupportedException, e:
266                     self.exceptionOccurred(self.tr("Error evaluating \"%1\" for module %2").arg(e.support_string).arg(module))
267                     supported = True
268                 if not supported:
269                     module_item.setForeground(0, QBrush(QColor(Qt.red)))
270                 if enabled:
271                     module_item.setCheckState(0, Qt.Checked)
272                 else:
273                     module_item.setCheckState(0, Qt.Unchecked)
274             self.pageContent.moduleTree.addTopLevelItem(item)
275         self.pageContent.moduleTree.sortItems(0, Qt.AscendingOrder)
276         self.fillPropertyTable()
277             
278     def insertCheckBox(self, index, value):
279         """
280         Inserts in the table at index a checkbox for a boolean property setted
281         to value.
282         """
283         check_box = QCheckBox()
284         self.pageContent.propertyTable.setCellWidget(index, 1, check_box)
285         if value == "1":
286             check_box.setChecked(True)
287         else:
288             check_box.setChecked(False)
289         self._control_group.addControl(index, check_box)
290     
291     def insertComboBox(self, index, value, value_list):
292         """
293         Inserts in the table at index a combobox for an enum property setted
294         to value.
295         """
296         try:
297             enum = self.projectInfo("LISTS")[value_list]
298             combo_box = QComboBox()
299             self.pageContent.propertyTable.setCellWidget(index, 1, combo_box)
300             for i, element in enumerate(enum):
301                 combo_box.addItem(element)
302                 if element == value:
303                     combo_box.setCurrentIndex(i)
304             self._control_group.addControl(index, combo_box)
305         except KeyError:
306             self.exceptionOccurred(self.tr("Define list \"%1\" not found. Check definition files.").arg(value_list))
307             self.pageContent.propertyTable.setItem(index, 1, QTableWidgetItem(value))
308     
309     def insertSpinBox(self, index, value, informations):
310         """
311         Inserts in the table at index a spinbox for an int, a long or an unsigned
312         long property setted to value.
313         """
314         # int, long or undefined type property
315         spin_box = None
316         if bertos_utils.isLong(informations) or bertos_utils.isUnsignedLong(informations):
317             spin_box = QDoubleSpinBox()
318             spin_box.setDecimals(0)
319         else:
320             spin_box = QSpinBox()
321         self.pageContent.propertyTable.setCellWidget(index, 1, spin_box)
322         minimum = -32768
323         maximum = 32767
324         suff = ""
325         if bertos_utils.isLong(informations):
326             minimum = -2147483648
327             maximum = 2147483647
328             suff = "L"
329         elif bertos_utils.isUnsigned(informations):
330             minimum = 0
331             maximum = 65535
332             suff = "U"
333         elif bertos_utils.isUnsignedLong(informations):
334             minimum = 0
335             maximum = 4294967295
336             suff = "UL"
337         if "min" in informations:
338             minimum = int(informations["min"])
339         if "max" in informations:
340             maximum = int(informations["max"])
341         spin_box.setRange(minimum, maximum)
342         spin_box.setSuffix(suff)
343         spin_box.setValue(int(value.replace("L", "").replace("U", ""), 0))
344         self._control_group.addControl(index, spin_box)
345         
346     
347     def insertLineEdit(self, index, value, informations):
348         """
349         Inserts in the table at index a line edit for hexadecimal property
350         setted to value.
351         """
352         edit_box = QLineEdit()
353         edit_validator = QRegExpValidator(QRegExp(r"^0x[0-9A-Fa-f]+$"), edit_box)
354         edit_box.setValidator(edit_validator)
355         self.pageContent.propertyTable.setCellWidget(index, 1, edit_box)
356         edit_box.setText(value)
357         self._control_group.addControl(index, edit_box)
358
359     def currentModule(self):
360         """
361         Retuns the current module name.
362         """
363         current_module = self.pageContent.moduleTree.currentItem()
364         # return only the child items
365         if current_module and current_module.parent():
366             return unicode(current_module.text(0))
367         else:
368             return None
369
370     def moduleItem(self, module):
371         for top_level_index in range(self.pageContent.moduleTree.topLevelItemCount()):
372             top_level_item = self.pageContent.moduleTree.topLevelItem(top_level_index)
373             for child_index in range(top_level_item.childCount()):
374                 child_item = top_level_item.child(child_index)
375                 if unicode(child_item.text(0)) == module:
376                     return child_item
377         return None
378     
379     def currentModuleConfigurations(self):
380         """
381         Returns the current module configuration.
382         """
383         return self.configurations(self.currentModule())
384     
385     def currentProperty(self):
386         """
387         Rerturns the current property from the property table.
388         """
389         return qvariant_converter.getString(self.pageContent.propertyTable.item(self.pageContent.propertyTable.currentRow(), 0).data(Qt.UserRole))
390     
391     def currentPropertyItem(self):
392         """
393         Returns the QTableWidgetItem of the current property.
394         """
395         return self.pageContent.propertyTable.item(self.pageContent.propertyTable.currentRow(), 0)
396     
397     def configurations(self, module):
398         """
399         Returns the configuration for the selected module.
400         """
401         configuration = []
402         if module:
403             # On linux platform it seems that the behaviour of the focus
404             # changing is a bit different from the mac one. So if module is
405             # None then no configurations should be returned.
406             configuration = self.projectInfo("MODULES")[module]["configuration"]
407         if len(configuration) > 0:
408             return self.projectInfo("CONFIGURATIONS")[configuration]
409         else:
410             return {}
411     
412     def resetPropertyDescription(self):
413         """
414         Resets the label for each property table entry.
415         """
416         for index in range(self.pageContent.propertyTable.rowCount()):
417             property_name = qvariant_converter.getString(self.pageContent.propertyTable.item(index, 0).data(Qt.UserRole))
418             # Awful solution! Needed because if the user change the module, the selection changed...
419             if property_name not in self.currentModuleConfigurations():
420                 break
421             self.pageContent.propertyTable.item(index, 0).setText(self.currentModuleConfigurations()[property_name]['brief'])
422     
423     def setBold(self, item, bold):
424         self.pageContent.moduleTree.blockSignals(True)
425         font = item.font(0)
426         font.setBold(bold)
427         item.setFont(0, font)
428         self.pageContent.moduleTree.blockSignals(False)
429
430     def isBold(self, item):
431         return item.font(0).bold()
432
433     def moduleSelected(self, selectedModule):
434         """
435         Resolves the selection dependencies.
436         """
437         try:
438             qApp.setOverrideCursor(Qt.WaitCursor)
439             modules = self.projectInfo("MODULES")
440             modules[selectedModule]["enabled"] = True
441             self.setProjectInfo("MODULES", modules)
442             depends = self.projectInfo("MODULES")[selectedModule]["depends"]
443             unsatisfied = []
444             if self.pageContent.automaticFix.isChecked():
445                 unsatisfied = self.selectDependencyCheck(selectedModule)
446             if len(unsatisfied) > 0:
447                 for module in unsatisfied:
448                     modules = self.projectInfo("MODULES")
449                     modules[module]["enabled"] = True
450                 for category in range(self.pageContent.moduleTree.topLevelItemCount()):
451                     item = self.pageContent.moduleTree.topLevelItem(category)
452                     for child in range(item.childCount()):
453                         if unicode(item.child(child).text(0)) in unsatisfied:
454                             self.setBold(item.child(child), True)
455                             self.setBold(item, True)
456                             item.child(child).setCheckState(0, Qt.Checked)
457         finally:
458             qApp.restoreOverrideCursor()
459     
460     def moduleUnselected(self, unselectedModule):
461         """
462         Resolves the unselection dependencies.
463         """
464         try:
465             qApp.setOverrideCursor(Qt.WaitCursor)
466             modules = self.projectInfo("MODULES")
467             modules[unselectedModule]["enabled"] = False
468             self.setProjectInfo("MODULES", modules)
469             unsatisfied = []
470             unsatisfied_params = []
471             if self.pageContent.automaticFix.isChecked():
472                 unsatisfied, unsatisfied_params = self.unselectDependencyCheck(unselectedModule)
473             if len(unsatisfied) > 0 or len(unsatisfied_params) > 0:
474                 message = []
475                 heading = self.tr("The module %1 is needed by").arg(unselectedModule)
476                 message.append(heading)
477                 module_list = ", ".join(unsatisfied)
478                 param_list = ", ".join(["%s (%s)" %(param_name, module) for module, param_name in unsatisfied_params])
479                 if module_list:
480                     message.append(QString(module_list))
481                 if module_list and param_list:
482                     message.append(self.tr("and by"))
483                 if param_list:
484                     message.append(QString(param_list))
485                 message_str = QStringList(message).join(" ")
486                 message_str.append(self.tr("\n\nDo you want to automatically fix these conflicts?"))
487                 qApp.restoreOverrideCursor()
488                 choice = QMessageBox.warning(self, self.tr("Dependency error"), message_str, QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
489                 qApp.setOverrideCursor(Qt.WaitCursor)
490                 if choice == QMessageBox.Yes:
491                     for module in unsatisfied:
492                         modules = self.projectInfo("MODULES")
493                         modules[module]["enabled"] = False
494                     for category in range(self.pageContent.moduleTree.topLevelItemCount()):
495                         item = self.pageContent.moduleTree.topLevelItem(category)
496                         self.setBold(item, False)
497                         for child in range(item.childCount()):
498                             if unicode(item.child(child).text(0)) in unsatisfied:
499                                 self.setBold(item.child(child), False)
500                                 item.child(child).setCheckState(0, Qt.Unchecked)
501                             else:
502                                 if self.isBold(item.child(child)):
503                                     self.setBold(item, True)
504                     for module, param in unsatisfied_params:
505                         configuration_file = self.projectInfo("MODULES")[module]["configuration"]
506                         configurations = self.projectInfo("CONFIGURATIONS")
507                         configurations[configuration_file][param]["value"] = "0"
508                         self.setProjectInfo("CONFIGURATIONS", configurations)
509         finally:
510             qApp.restoreOverrideCursor()
511     
512     def selectDependencyCheck(self, module):
513         """
514         Returns the list of unsatisfied dependencies after a selection.
515         """
516         unsatisfied = set()
517         modules = self.projectInfo("MODULES")
518         files = self.projectInfo("FILES")
519         configurations = self.projectInfo("CONFIGURATIONS").get(modules[module]["configuration"], {"paramlist": ()})
520         conditional_deps = ()
521         for i, param_name in configurations["paramlist"]:
522             information = configurations[param_name]
523             if information["informations"]["type"] == "boolean" and \
524                 information["value"] != "0" and \
525                 "conditional_deps" in information["informations"]:
526
527                 conditional_deps += information["informations"]["conditional_deps"]
528
529         for dependency in modules[module]["depends"] + conditional_deps:
530             if dependency in modules and not modules[dependency]["enabled"]:
531                 unsatisfied |= set([dependency])
532                 if dependency not in unsatisfied:
533                     unsatisfied |= self.selectDependencyCheck(dependency)
534             if dependency not in modules:
535                 if dependency in files:
536                     files[dependency] += 1
537                 else:
538                     files[dependency] = 1
539         self.setProjectInfo("FILES", files)
540         return unsatisfied
541     
542     def unselectDependencyCheck(self, dependency):
543         """
544         Returns the list of unsatisfied dependencies after an unselection.
545         """
546         unsatisfied = set()
547         unsatisfied_params = set()
548         modules = self.projectInfo("MODULES")
549         for module, informations in modules.items():
550             configurations = self.projectInfo("CONFIGURATIONS").get(informations["configuration"], {"paramlist": ()})
551             conditional_deps = {}
552             for i, param_name in configurations["paramlist"]:
553                 information = configurations[param_name]
554                 if information["informations"]["type"] == "boolean" and information["value"] != "0" and "conditional_deps" in information["informations"]:
555                     for dep in information["informations"]["conditional_deps"]:
556                         if not dep in conditional_deps:
557                             conditional_deps[dep] = []
558                         conditional_deps[dep].append((module, param_name))
559             if dependency in informations["depends"] and informations["enabled"]:
560                 unsatisfied |= set([module])
561                 if dependency not in unsatisfied:
562                     tmp = self.unselectDependencyCheck(module)
563                     unsatisfied |= tmp[0]
564                     unsatisfied_params |= tmp[1]
565             if dependency in conditional_deps:
566                 unsatisfied_params |= set(conditional_deps[dependency])
567         return unsatisfied, unsatisfied_params
568     
569     def removeFileDependencies(self, module):
570         """
571         Removes the files dependencies of the given module.
572         """
573         modules = self.projectInfo("MODULES")
574         files = self.projectInfo("FILES")
575         dependencies = modules[module]["depends"]
576         for dependency in dependencies:
577             if dependency in files:
578                 files[dependency] -= 1
579                 if files[dependency] == 0:
580                     del files[dependency]
581         self.setProjectInfo("FILES", files)
582
583 class QControlGroup(QObject):
584     """
585     Simple class that permit to connect different signals of different widgets
586     with a slot that emit a signal. Permits to group widget and to understand which of
587     them has sent the signal.
588     """
589     
590     def __init__(self):
591         QObject.__init__(self)
592         self._controls = {}
593     
594     def addControl(self, id, control):
595         """
596         Add a control.
597         """
598         self._controls[id] = control
599         if type(control) == QCheckBox:
600             self.connect(control, SIGNAL("stateChanged(int)"), lambda: self.stateChanged(id))
601         elif type(control) == QSpinBox:
602             self.connect(control, SIGNAL("valueChanged(int)"), lambda: self.stateChanged(id))
603         elif type(control) == QComboBox:
604             self.connect(control, SIGNAL("currentIndexChanged(int)"), lambda: self.stateChanged(id))
605         elif type(control) == QDoubleSpinBox:
606             self.connect(control, SIGNAL("valueChanged(double)"), lambda: self.stateChanged(id))
607     
608     def clear(self):
609         """
610         Remove all the controls.
611         """
612         self._controls = {}
613     
614     def stateChanged(self, id):
615         """
616         Slot called when the value of one of the stored widget changes. It emits
617         another signal.
618         """
619         self.emit(SIGNAL("stateChanged"), id)