X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=wizard%2FBModulePage.py;h=19d0c3a50862715d2c608330f9b2cc3571f6d134;hb=695e044f1387440a718abf42a79800e785f71c7f;hp=7fcfbcc13d4e954b344b780355f42fbdd6ca73d2;hpb=b05e3d59cc7c086e656a1afd136c68b559ae8c1a;p=bertos.git diff --git a/wizard/BModulePage.py b/wizard/BModulePage.py index 7fcfbcc1..19d0c3a5 100644 --- a/wizard/BModulePage.py +++ b/wizard/BModulePage.py @@ -78,8 +78,10 @@ class BModulePage(BWizardPage): comboBox = QComboBox() self.pageContent.propertyTable.setCellWidget(index, 1, comboBox) enum = self._projectInfoRetrieve("LISTS")[configurations[property]["informations"]["value_list"]] - for element in enum: + for index, element in enumerate(enum): comboBox.addItem(element) + if element == configurations[property]["value"]: + comboBox.setCurrentIndex(index) else: ## int, long or undefined type property spinBox = QSpinBox() @@ -98,11 +100,31 @@ class BModulePage(BWizardPage): spinBox.setSuffix("L") spinBox.setValue(int(configurations[property]["value"].replace("L", ""))) + def _saveData(self, previousRow, previousColumn): + module = self._module(previousRow) + moduleConfigurations = self._configurations(module) + for index in range(self.pageContent.propertyTable.rowCount()): + parameter = qvariant_converter.getString(self.pageContent.propertyTable.item(index, 0).data(Qt.UserRole)) + if "type" not in moduleConfigurations[parameter]["informations"].keys() or moduleConfigurations[parameter]["informations"]["type"] == "int": + moduleConfigurations[parameter]["value"] = str(self.pageContent.propertyTable.cellWidget(index, 1).value()) + elif moduleConfigurations[parameter]["informations"]["type"] == "enum": + moduleConfigurations[parameter]["value"] = unicode(self.pageContent.propertyTable.cellWidget(index, 1).currentText()) + elif moduleConfigurations[parameter]["informations"]["type"] == "boolean": + if self.pageContent.propertyTable.cellWidget(index, 1).isChecked(): + moduleConfigurations[parameter]["value"] = "1" + else: + moduleConfigurations[parameter]["value"] = "0" + + def _pageChanged(self, row, column, previousRow, previousColumn): + if previousRow != -1 and previousColumn != -1: + self._saveData(previousRow, previousColumn) + self._fillPropertyTable() + def _currentModule(self): return unicode(self.pageContent.moduleTable.item(self.pageContent.moduleTable.currentRow(), 1).text()) def _currentModuleConfigurations(self): - return self._projectInfoRetrieve("MODULES")[self._currentModule()]["configuration"] + return self._configurations(self._currentModule()) def _currentProperty(self): return qvariant_converter.getString(self.pageContent.propertyTable.item(self.pageContent.propertyTable.currentRow(), 0).data(Qt.UserRole)) @@ -110,6 +132,13 @@ class BModulePage(BWizardPage): def _currentPropertyItem(self): return self.pageContent.propertyTable.item(self.pageContent.propertyTable.currentRow(), 0) + def _module(self, row): + return unicode(self.pageContent.moduleTable.item(row, 1).text()) + + def _configurations(self, module): + configuration = self._projectInfoRetrieve("MODULES")[module]["configuration"] + return self._projectInfoRetrieve("CONFIGURATIONS")[configuration] + def _resetPropertyDescription(self): for index in range(self.pageContent.propertyTable.rowCount()): propertyName = qvariant_converter.getString(self.pageContent.propertyTable.item(index, 0).data(Qt.UserRole)) @@ -117,9 +146,11 @@ class BModulePage(BWizardPage): def _showPropertyDescription(self): self._resetPropertyDescription() - description = self._projectInfoRetrieve("CONFIGURATIONS")[self._currentModuleConfigurations()][self._currentProperty()]["description"] - name = self._currentProperty() - self._currentPropertyItem().setText(name + "\n" + description) + configurations = self._currentModuleConfigurations() + if self._currentProperty() in configurations.keys(): + description = configurations[self._currentProperty()]["description"] + name = self._currentProperty() + self._currentPropertyItem().setText(name + "\n" + description) def _setupUi(self): self.pageContent.moduleTable.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents) @@ -137,7 +168,7 @@ class BModulePage(BWizardPage): self.pageContent.propertyTable.setRowCount(0) def _connectSignals(self): - self.connect(self.pageContent.moduleTable, SIGNAL("itemSelectionChanged()"), self._fillPropertyTable) + self.connect(self.pageContent.moduleTable, SIGNAL("currentCellChanged(int, int, int, int)"), self._pageChanged) self.connect(self.pageContent.propertyTable, SIGNAL("itemSelectionChanged()"), self._showPropertyDescription) def _moduleSelectionChanged(self, index): @@ -152,46 +183,53 @@ class BModulePage(BWizardPage): modules[selectedModule]["enabled"] = True self._projectInfoStore("MODULES", modules) depends = self._projectInfoRetrieve("MODULES")[selectedModule]["depends"] - unsatisfied = [] - for element in depends: - if not self._projectInfoRetrieve("MODULES")[element]["enabled"]: - unsatisfied.append(element) + unsatisfied = self.selectDependencyCheck(selectedModule) if len(unsatisfied) > 0: - self._selectionDependencyFail(selectedModule, unsatisfied) - - def _selectionDependencyFail(self, selectedModule, unsatisfiedModules): - messageString = "The module " + selectedModule + " need the following modules:\n" + \ - ", ".join(unsatisfiedModules) + ".\nDo you want to resolve autmatically the prolem?" - messageBox = QMessageBox() - messageBox.setIcon(QMessageBox.Warning) - messageBox.setText(self.tr("Dependency fail")) - messageBox.setInformativeText(self.tr(messageString)) - resolveButton = QPushButton("Resolve") - nothingButton = QPushButton("Do nothing") - messageBox.addButton(resolveButton, QMessageBox.YesRole) - messageBox.addButton(nothingButton, QMessageBox.NoRole) - messageBox.exec_() + message = self.tr("The module %1 needs the following modules:\n%2.\n\nDo you want to resolve automatically the problem?") + message = message.arg(selectedModule).arg(", ".join(unsatisfied)) + choice = QMessageBox.warning(self, self.tr("Dependency error"), message, QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) + if choice == QMessageBox.Yes: + for module in unsatisfied: + modules = self._projectInfoRetrieve("MODULES") + modules[module]["enabled"] = True + for index in range(self.pageContent.moduleTable.rowCount()): + if unicode(self.pageContent.moduleTable.item(index, 1).text()) in unsatisfied: + self._buttonGroup.button(index).setChecked(True) def _moduleUnselected(self, unselectedModule): modules = self._projectInfoRetrieve("MODULES") modules[unselectedModule]["enabled"] = False self._projectInfoStore("MODULES", modules) - unsatisfied = [] - for module, infos in self._projectInfoRetrieve("MODULES").items(): - if unselectedModule in infos["depends"] and infos["enabled"]: - unsatisfied.append(module) + unsatisfied = self.unselectDependencyCheck(unselectedModule) if len(unsatisfied) > 0: - self._unselectionDependencyFail(unselectedModule, unsatisfied) - - def _unselectionDependencyFail(self, unselectedModule, unsatisfiedModules): - messageString = "The module " + unselectedModule + " is needed by the following modules:\n" + \ - ", ".join(unsatisfiedModules) + ".\nDo you want to resolve autmatically the prolem?" - messageBox = QMessageBox() - messageBox.setIcon(QMessageBox.Warning) - messageBox.setText(self.tr("Dependency fail")) - messageBox.setInformativeText(self.tr(messageString)) - resolveButton = QPushButton("Resolve") - nothingButton = QPushButton("Do nothing") - messageBox.addButton(resolveButton, QMessageBox.YesRole) - messageBox.addButton(nothingButton, QMessageBox.NoRole) - messageBox.exec_() \ No newline at end of file + message = self.tr("The module %1 is needed by the following modules:\n%2.\n\nDo you want to resolve automatically the problem?") + message = message.arg(unselectedModule).arg(", ".join(unsatisfied)) + choice = QMessageBox.warning(self, self.tr("Dependency error"), message, QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) + if choice == QMessageBox.Yes: + for module in unsatisfied: + modules = self._projectInfoRetrieve("MODULES") + modules[module]["enabled"] = False + for index in range(self.pageContent.moduleTable.rowCount()): + if unicode(self.pageContent.moduleTable.item(index, 1).text()) in unsatisfied: + self._buttonGroup.button(index).setChecked(False) + + + def selectDependencyCheck(self, module): + unsatisfied = set() + modules = self._projectInfoRetrieve("MODULES") + for dependency in modules[module]["depends"]: + if not modules[dependency]["enabled"]: + unsatisfied |= set([dependency]) + if dependency not in unsatisfied: + unsatisfied |= self.selectDependencyCheck(dependency) + return unsatisfied + + def unselectDependencyCheck(self, dependency): + unsatisfied = set() + modules = self._projectInfoRetrieve("MODULES") + for module, informations in modules.items(): + if dependency in informations["depends"] and informations["enabled"]: + unsatisfied |= set([module]) + if dependency not in unsatisfied: + unsatisfied |= self.unselectDependencyCheck(module) + return unsatisfied \ No newline at end of file