Rewrite the BModulePage class
[bertos.git] / wizard / BModulePage.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # Copyright 2009 Develer S.r.l. (http://www.develer.com/)
5 # All rights reserved.
6 #
7 # $Id:$
8 #
9 # Author: Lorenzo Berni <duplo@develer.com>
10 #
11
12 import os
13
14 from PyQt4.QtGui import *
15 from BWizardPage import *
16 import bertos_utils
17
18
19 class BModulePage(BWizardPage):
20     
21     def __init__(self):
22         BWizardPage.__init__(self, "module_select.ui")
23         self.setTitle(self.tr("Configure the BeRTOS modules"))
24         self._setupUi()
25         self._connectSignals()
26     
27     def reloadData(self):
28         self._setupButtonGroup()
29         self._loadModuleData()
30         self._fillModuleTable()
31     
32     def _setupButtonGroup(self):
33         self._buttonGroup = QButtonGroup()
34         self._buttonGroup.setExclusive(False)
35     
36     def _loadModuleData(self):
37         modules = bertos_utils.loadModuleInfosDict(self._projectInfoRetrieve("SOURCES_PATH"))
38         lists = bertos_utils.loadDefineListsDict(self._projectInfoRetrieve("SOURCES_PATH"))
39         configurations = {}
40         for module, informations in modules.items():
41             configurations[informations["configuration"]] = bertos_utils.loadConfigurationInfos(self._projectInfoRetrieve("SOURCES_PATH") +
42                                                                                                 "/" + informations["configuration"])
43         self._projectInfoStore("MODULES", modules)
44         self._projectInfoStore("LISTS", lists)
45         self._projectInfoStore("CONFIGURATIONS", configurations)
46     
47     def _fillModuleTable(self):
48         modules = self._projectInfoRetrieve("MODULES")
49         self.pageContent.moduleTable.setRowCount(len(modules))
50         for index, module in enumerate(modules):
51             self.pageContent.moduleTable.setItem(index, 1, QTableWidgetItem(module))
52             checkBox = QCheckBox()
53             self._buttonGroup.addButton(checkBox, index)
54             self.pageContent.moduleTable.setCellWidget(index, 0, checkBox)
55     
56     def _fillPropertyTable(self):
57         module = unicode(self.pageContent.moduleTable.item(self.pageContent.moduleTable.currentRow(), 1).text())
58         configuration = self._projectInfoRetrieve("MODULES")[module]["configuration"]
59         configurations = self._projectInfoRetrieve("CONFIGURATIONS")[configuration]
60         self.pageContent.propertyTable.clear()
61         self.pageContent.propertyTable.setRowCount(len(configurations))
62         for index, parameter in enumerate(configurations):
63             self.pageContent.propertyTable.setItem(index, 0, QTableWidgetItem(parameter))
64             if "type" in configurations[parameter]["informations"].keys() and configurations[parameter]["informations"]["type"] == "boolean":
65                 ## boolean parameter
66                 checkBox = QCheckBox()
67                 self.pageContent.propertyTable.setCellWidget(index, 1, checkBox)
68                 if configurations[parameter]["value"] == "1":
69                     checkBox.setChecked(True)
70                 else:
71                     checkBox.setChecked(False)
72             elif "type" in configurations[parameter]["informations"].keys() and configurations[parameter]["informations"]["type"] == "enum":
73                 ## enum parameter
74                 comboBox = QComboBox()
75                 self.pageContent.propertyTable.setCellWidget(index, 1, comboBox)
76                 enum = self._projectInfoRetrieve("LISTS")[configurations[parameter]["informations"]["value_list"]]
77                 for element in enum:
78                     comboBox.addItem(element)
79             else:
80                 ## int, long or undefined type parameter
81                 spinBox = QSpinBox()
82                 self.pageContent.propertyTable.setCellWidget(index, 1, spinBox)
83                 if "min" in configurations[parameter]["informations"].keys():
84                     minimum = int(configurations[parameter]["informations"]["min"])
85                 else:
86                     minimum = -32768
87                 spinBox.setMinimum(minimum)
88                 if "max" in configurations[parameter]["informations"].keys():
89                     maximum = int(configurations[parameter]["infomations"]["max"])
90                 else:
91                     maximum = 32767
92                 spinBox.setMaximum(maximum)
93                 if "long" in configurations[parameter]["informations"].keys() and configurations[parameter]["informations"]["long"] == "True":
94                     spinBox.setSuffix("L")
95                 spinBox.setValue(int(configurations[parameter]["value"].replace("L", "")))
96     
97     def _setupUi(self):
98         self.pageContent.moduleTable.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
99         self.pageContent.moduleTable.horizontalHeader().setStretchLastSection(True)
100         self.pageContent.moduleTable.horizontalHeader().setVisible(False)
101         self.pageContent.moduleTable.verticalHeader().setResizeMode(QHeaderView.ResizeToContents)
102         self.pageContent.moduleTable.verticalHeader().setVisible(False)
103         self.pageContent.moduleTable.setColumnCount(2)
104         self.pageContent.moduleTable.setRowCount(0)
105         self.pageContent.propertyTable.horizontalHeader().setResizeMode(QHeaderView.Stretch)
106         self.pageContent.propertyTable.horizontalHeader().setVisible(False)
107         self.pageContent.propertyTable.verticalHeader().setResizeMode(QHeaderView.ResizeToContents)
108         self.pageContent.propertyTable.verticalHeader().setVisible(False)
109         self.pageContent.propertyTable.setColumnCount(2)
110         self.pageContent.propertyTable.setRowCount(0)
111     
112     def _connectSignals(self):
113         self.connect(self.pageContent.moduleTable, SIGNAL("itemSelectionChanged()"), self._fillPropertyTable)