4 # Copyright 2009 Develer S.r.l. (http://www.develer.com/)
9 # Author: Lorenzo Berni <duplo@develer.com>
14 from PyQt4.QtGui import *
15 from BWizardPage import *
19 class BModulePage(BWizardPage):
22 BWizardPage.__init__(self, "module_select.ui")
23 self.setTitle(self.tr("Configure the BeRTOS modules"))
25 self._connectSignals()
28 self._setupButtonGroup()
29 self._loadModuleData()
30 self._fillModuleTable()
32 def _setupButtonGroup(self):
33 self._buttonGroup = QButtonGroup()
34 self._buttonGroup.setExclusive(False)
36 def _loadModuleData(self):
37 modules = bertos_utils.loadModuleInfosDict(self._projectInfoRetrieve("SOURCES_PATH"))
38 lists = bertos_utils.loadDefineListsDict(self._projectInfoRetrieve("SOURCES_PATH"))
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)
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)
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":
66 checkBox = QCheckBox()
67 self.pageContent.propertyTable.setCellWidget(index, 1, checkBox)
68 if configurations[parameter]["value"] == "1":
69 checkBox.setChecked(True)
71 checkBox.setChecked(False)
72 elif "type" in configurations[parameter]["informations"].keys() and configurations[parameter]["informations"]["type"] == "enum":
74 comboBox = QComboBox()
75 self.pageContent.propertyTable.setCellWidget(index, 1, comboBox)
76 enum = self._projectInfoRetrieve("LISTS")[configurations[parameter]["informations"]["value_list"]]
78 comboBox.addItem(element)
80 ## int, long or undefined type parameter
82 self.pageContent.propertyTable.setCellWidget(index, 1, spinBox)
83 if "min" in configurations[parameter]["informations"].keys():
84 minimum = int(configurations[parameter]["informations"]["min"])
87 spinBox.setMinimum(minimum)
88 if "max" in configurations[parameter]["informations"].keys():
89 maximum = int(configurations[parameter]["infomations"]["max"])
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", "")))
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)
112 def _connectSignals(self):
113 self.connect(self.pageContent.moduleTable, SIGNAL("itemSelectionChanged()"), self._fillPropertyTable)