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)
35 self.connect(self._buttonGroup, SIGNAL("buttonClicked(int)"), self._moduleSelectionChanged)
37 def _loadModuleData(self):
38 modules = bertos_utils.loadModuleInfosDict(self._projectInfoRetrieve("SOURCES_PATH"))
39 lists = bertos_utils.loadDefineListsDict(self._projectInfoRetrieve("SOURCES_PATH"))
41 for module, informations in modules.items():
42 configurations[informations["configuration"]] = bertos_utils.loadConfigurationInfos(self._projectInfoRetrieve("SOURCES_PATH") +
43 "/" + informations["configuration"])
44 self._projectInfoStore("MODULES", modules)
45 self._projectInfoStore("LISTS", lists)
46 self._projectInfoStore("CONFIGURATIONS", configurations)
48 def _fillModuleTable(self):
49 modules = self._projectInfoRetrieve("MODULES")
50 self.pageContent.moduleTable.setRowCount(len(modules))
51 for index, module in enumerate(modules):
52 self.pageContent.moduleTable.setItem(index, 1, QTableWidgetItem(module))
53 checkBox = QCheckBox()
54 self._buttonGroup.addButton(checkBox, index)
55 self.pageContent.moduleTable.setCellWidget(index, 0, checkBox)
56 checkBox.setChecked(modules[module]["enabled"])
58 def _fillPropertyTable(self):
60 module = self._currentModule()
61 configuration = self._projectInfoRetrieve("MODULES")[module]["configuration"]
62 configurations = self._projectInfoRetrieve("CONFIGURATIONS")[configuration]
63 self.pageContent.propertyTable.clear()
64 self.pageContent.propertyTable.setRowCount(len(configurations))
65 for index, property in enumerate(configurations):
66 item = QTableWidgetItem(property)
67 item.setData(Qt.UserRole, qvariant_converter.convertString(property))
68 self.pageContent.propertyTable.setItem(index, 0, item)
69 if "type" in configurations[property]["informations"].keys() and configurations[property]["informations"]["type"] == "boolean":
71 checkBox = QCheckBox()
72 self.pageContent.propertyTable.setCellWidget(index, 1, checkBox)
73 if configurations[property]["value"] == "1":
74 checkBox.setChecked(True)
76 checkBox.setChecked(False)
77 elif "type" in configurations[property]["informations"].keys() and configurations[property]["informations"]["type"] == "enum":
79 comboBox = QComboBox()
80 self.pageContent.propertyTable.setCellWidget(index, 1, comboBox)
81 enum = self._projectInfoRetrieve("LISTS")[configurations[property]["informations"]["value_list"]]
83 comboBox.addItem(element)
85 ## int, long or undefined type property
87 self.pageContent.propertyTable.setCellWidget(index, 1, spinBox)
88 if "min" in configurations[property]["informations"].keys():
89 minimum = int(configurations[property]["informations"]["min"])
92 spinBox.setMinimum(minimum)
93 if "max" in configurations[property]["informations"].keys():
94 maximum = int(configurations[property]["informations"]["max"])
97 spinBox.setMaximum(maximum)
98 if "long" in configurations[property]["informations"].keys() and configurations[property]["informations"]["long"] == "True":
99 spinBox.setSuffix("L")
100 spinBox.setValue(int(configurations[property]["value"].replace("L", "")))
102 def _currentModule(self):
103 return unicode(self.pageContent.moduleTable.item(self.pageContent.moduleTable.currentRow(), 1).text())
105 def _currentModuleConfigurations(self):
106 return self._projectInfoRetrieve("MODULES")[self._currentModule()]["configuration"]
108 def _currentProperty(self):
109 return qvariant_converter.getString(self.pageContent.propertyTable.item(self.pageContent.propertyTable.currentRow(), 0).data(Qt.UserRole))
111 def _currentPropertyItem(self):
112 return self.pageContent.propertyTable.item(self.pageContent.propertyTable.currentRow(), 0)
114 def _resetPropertyDescription(self):
115 for index in range(self.pageContent.propertyTable.rowCount()):
116 propertyName = qvariant_converter.getString(self.pageContent.propertyTable.item(index, 0).data(Qt.UserRole))
117 self.pageContent.propertyTable.item(index, 0).setText(propertyName)
119 def _showPropertyDescription(self):
120 self._resetPropertyDescription()
121 configurations = self._projectInfoRetrieve("CONFIGURATIONS")[self._currentModuleConfigurations()]
122 if self._currentProperty() in configurations.keys():
123 description = configurations[self._currentProperty()]["description"]
124 name = self._currentProperty()
125 self._currentPropertyItem().setText(name + "\n" + description)
128 self.pageContent.moduleTable.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
129 self.pageContent.moduleTable.horizontalHeader().setStretchLastSection(True)
130 self.pageContent.moduleTable.horizontalHeader().setVisible(False)
131 self.pageContent.moduleTable.verticalHeader().setResizeMode(QHeaderView.ResizeToContents)
132 self.pageContent.moduleTable.verticalHeader().setVisible(False)
133 self.pageContent.moduleTable.setColumnCount(2)
134 self.pageContent.moduleTable.setRowCount(0)
135 self.pageContent.propertyTable.horizontalHeader().setResizeMode(QHeaderView.Stretch)
136 self.pageContent.propertyTable.horizontalHeader().setVisible(False)
137 self.pageContent.propertyTable.verticalHeader().setResizeMode(QHeaderView.ResizeToContents)
138 self.pageContent.propertyTable.verticalHeader().setVisible(False)
139 self.pageContent.propertyTable.setColumnCount(2)
140 self.pageContent.propertyTable.setRowCount(0)
142 def _connectSignals(self):
143 self.connect(self.pageContent.moduleTable, SIGNAL("itemSelectionChanged()"), self._fillPropertyTable)
144 self.connect(self.pageContent.propertyTable, SIGNAL("itemSelectionChanged()"), self._showPropertyDescription)
146 def _moduleSelectionChanged(self, index):
147 module = unicode(self.pageContent.moduleTable.item(index, 1).text())
148 if self._buttonGroup.button(index).isChecked():
149 self._moduleSelected(module)
151 self._moduleUnselected(module)
153 def _moduleSelected(self, selectedModule):
154 modules = self._projectInfoRetrieve("MODULES")
155 modules[selectedModule]["enabled"] = True
156 self._projectInfoStore("MODULES", modules)
157 depends = self._projectInfoRetrieve("MODULES")[selectedModule]["depends"]
158 unsatisfied = self.selectDependencyCheck(selectedModule)
159 if len(unsatisfied) > 0:
160 message = self.tr("The module %1 needs the following modules:\n%2.\n\nDo you want to resolve automatically the problem?")
161 message = message.arg(selectedModule).arg(", ".join(unsatisfied))
162 choice = QMessageBox.warning(self, self.tr("Dependency error"), message, QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
163 if choice == QMessageBox.Yes:
164 for module in unsatisfied:
165 modules = self._projectInfoRetrieve("MODULES")
166 modules[module]["enabled"] = True
167 for index in range(self.pageContent.moduleTable.rowCount()):
168 if unicode(self.pageContent.moduleTable.item(index, 1).text()) in unsatisfied:
169 self._buttonGroup.button(index).setChecked(True)
171 def _moduleUnselected(self, unselectedModule):
172 modules = self._projectInfoRetrieve("MODULES")
173 modules[unselectedModule]["enabled"] = False
174 self._projectInfoStore("MODULES", modules)
175 unsatisfied = self.unselectDependencyCheck(unselectedModule)
176 if len(unsatisfied) > 0:
177 message = self.tr("The module %1 is needed by the following modules:\n%2.\n\nDo you want to resolve automatically the problem?")
178 message = message.arg(unselectedModule).arg(", ".join(unsatisfied))
179 choice = QMessageBox.warning(self, self.tr("Dependency error"), message, QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
180 if choice == QMessageBox.Yes:
181 for module in unsatisfied:
182 modules = self._projectInfoRetrieve("MODULES")
183 modules[module]["enabled"] = False
184 for index in range(self.pageContent.moduleTable.rowCount()):
185 if unicode(self.pageContent.moduleTable.item(index, 1).text()) in unsatisfied:
186 self._buttonGroup.button(index).setChecked(False)
189 def selectDependencyCheck(self, module):
191 modules = self._projectInfoRetrieve("MODULES")
192 for dependency in modules[module]["depends"]:
193 if not modules[dependency]["enabled"]:
194 unsatisfied |= set([dependency])
195 if dependency not in unsatisfied:
196 unsatisfied |= self.selectDependencyCheck(dependency)
199 def unselectDependencyCheck(self, dependency):
201 modules = self._projectInfoRetrieve("MODULES")
202 for module, informations in modules.items():
203 if dependency in informations["depends"] and informations["enabled"]:
204 unsatisfied |= set([module])
205 if dependency not in unsatisfied:
206 unsatisfied |= self.unselectDependencyCheck(module)
210 for index in range(self.pageContent.propertyTable.rowCount()):
211 print qvariant_converter.getString(self.pageContent.propertyTable.item(index, 0).data(Qt.UserRole))