- def _moduleSelectionChanged(self, index):
- module = unicode(self.pageContent.moduleTable.item(index, 1).text())
- if self._buttonGroup.button(index).isChecked():
- self._moduleSelected(module)
- else:
- self._moduleUnselected(module)
-
- def _moduleSelected(self, selectedModule):
- modules = self._projectInfoRetrieve("MODULES")
- 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)
- 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_()
-
- 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)
- 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
+ def isBold(self, item):
+ return item.font(0).bold()
+
+ def moduleSelected(self, selectedModule):
+ """
+ Resolves the selection dependencies.
+ """
+ try:
+ qApp.setOverrideCursor(Qt.WaitCursor)
+ modules = self.projectInfo("MODULES")
+ modules[selectedModule]["enabled"] = True
+ self.setProjectInfo("MODULES", modules)
+ depends = self.projectInfo("MODULES")[selectedModule]["depends"]
+ unsatisfied = []
+ if self.pageContent.automaticFix.isChecked():
+ unsatisfied = self.selectDependencyCheck(selectedModule)
+ if len(unsatisfied) > 0:
+ for module in unsatisfied:
+ modules = self.projectInfo("MODULES")
+ modules[module]["enabled"] = True
+ for category in range(self.pageContent.moduleTree.topLevelItemCount()):
+ item = self.pageContent.moduleTree.topLevelItem(category)
+ for child in range(item.childCount()):
+ if unicode(item.child(child).text(0)) in unsatisfied:
+ self.setBold(item.child(child), True)
+ self.setBold(item, True)
+ item.child(child).setCheckState(0, Qt.Checked)
+ finally:
+ qApp.restoreOverrideCursor()
+
+ def moduleUnselected(self, unselectedModule):
+ """
+ Resolves the unselection dependencies.
+ """
+ try:
+ qApp.setOverrideCursor(Qt.WaitCursor)
+ modules = self.projectInfo("MODULES")
+ modules[unselectedModule]["enabled"] = False
+ self.setProjectInfo("MODULES", modules)
+ unsatisfied = []
+ unsatisfied_params = []
+ if self.pageContent.automaticFix.isChecked():
+ unsatisfied, unsatisfied_params = self.unselectDependencyCheck(unselectedModule)
+ if len(unsatisfied) > 0 or len(unsatisfied_params) > 0:
+ message = []
+ heading = self.tr("The module %1 is needed by").arg(unselectedModule)
+ message.append(heading)
+ module_list = ", ".join(unsatisfied)
+ param_list = ", ".join(["%s (%s)" %(param_name, module) for module, param_name in unsatisfied_params])
+ if module_list:
+ message.append(QString(module_list))
+ if module_list and param_list:
+ message.append(self.tr("and by"))
+ if param_list:
+ message.append(QString(param_list))
+ message_str = QStringList(message).join(" ")
+ message_str.append(self.tr("\n\nDo you want to automatically fix these conflicts?"))
+ qApp.restoreOverrideCursor()
+ choice = QMessageBox.warning(self, self.tr("Dependency error"), message_str, QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
+ qApp.setOverrideCursor(Qt.WaitCursor)
+ if choice == QMessageBox.Yes:
+ for module in unsatisfied:
+ modules = self.projectInfo("MODULES")
+ modules[module]["enabled"] = False
+ for category in range(self.pageContent.moduleTree.topLevelItemCount()):
+ item = self.pageContent.moduleTree.topLevelItem(category)
+ self.setBold(item, False)
+ for child in range(item.childCount()):
+ if unicode(item.child(child).text(0)) in unsatisfied:
+ self.setBold(item.child(child), False)
+ item.child(child).setCheckState(0, Qt.Unchecked)
+ else:
+ if self.isBold(item.child(child)):
+ self.setBold(item, True)
+ for module, param in unsatisfied_params:
+ configuration_file = self.projectInfo("MODULES")[module]["configuration"]
+ configurations = self.projectInfo("CONFIGURATIONS")
+ configurations[configuration_file][param]["value"] = "0"
+ self.setProjectInfo("CONFIGURATIONS", configurations)
+ finally:
+ qApp.restoreOverrideCursor()
+
+ def selectDependencyCheck(self, module):
+ """
+ Returns the list of unsatisfied dependencies after a selection.
+ """
+ unsatisfied = set()
+ modules = self.projectInfo("MODULES")
+ files = self.projectInfo("FILES")
+ configurations = self.projectInfo("CONFIGURATIONS").get(modules[module]["configuration"], {"paramlist": ()})
+ conditional_deps = ()
+ for i, param_name in configurations["paramlist"]:
+ information = configurations[param_name]
+ if information["informations"]["type"] == "boolean" and \
+ information["value"] != "0" and \
+ "conditional_deps" in information["informations"]:
+
+ conditional_deps += information["informations"]["conditional_deps"]
+
+ for dependency in modules[module]["depends"] + conditional_deps:
+ if dependency in modules and not modules[dependency]["enabled"]:
+ unsatisfied |= set([dependency])
+ if dependency not in unsatisfied:
+ unsatisfied |= self.selectDependencyCheck(dependency)
+ if dependency not in modules:
+ if dependency in files:
+ files[dependency] += 1
+ else:
+ files[dependency] = 1
+ self.setProjectInfo("FILES", files)
+ return unsatisfied
+
+ def unselectDependencyCheck(self, dependency):
+ """
+ Returns the list of unsatisfied dependencies after an unselection.
+ """
+ unsatisfied = set()
+ unsatisfied_params = set()
+ modules = self.projectInfo("MODULES")
+ for module, informations in modules.items():
+ configurations = self.projectInfo("CONFIGURATIONS").get(informations["configuration"], {"paramlist": ()})
+ conditional_deps = {}
+ for i, param_name in configurations["paramlist"]:
+ information = configurations[param_name]
+ if information["informations"]["type"] == "boolean" and information["value"] != "0" and "conditional_deps" in information["informations"]:
+ for dep in information["informations"]["conditional_deps"]:
+ if not dep in conditional_deps:
+ conditional_deps[dep] = []
+ conditional_deps[dep].append((module, param_name))
+ if dependency in informations["depends"] and informations["enabled"]:
+ unsatisfied |= set([module])
+ if dependency not in unsatisfied:
+ tmp = self.unselectDependencyCheck(module)
+ unsatisfied |= tmp[0]
+ unsatisfied_params |= tmp[1]
+ if dependency in conditional_deps:
+ unsatisfied_params |= set(conditional_deps[dependency])
+ return unsatisfied, unsatisfied_params
+
+ def removeFileDependencies(self, module):
+ """
+ Removes the files dependencies of the given module.
+ """
+ modules = self.projectInfo("MODULES")
+ files = self.projectInfo("FILES")
+ dependencies = modules[module]["depends"]
+ for dependency in dependencies:
+ if dependency in files:
+ files[dependency] -= 1
+ if files[dependency] == 0:
+ del files[dependency]
+ self.setProjectInfo("FILES", files)
+
+class QControlGroup(QObject):
+ """
+ Simple class that permit to connect different signals of different widgets
+ with a slot that emit a signal. Permits to group widget and to understand which of
+ them has sent the signal.
+ """
+
+ def __init__(self):
+ QObject.__init__(self)
+ self._controls = {}
+
+ def addControl(self, id, control):
+ """
+ Add a control.
+ """
+ self._controls[id] = control
+ if type(control) == QCheckBox:
+ self.connect(control, SIGNAL("stateChanged(int)"), lambda: self.stateChanged(id))
+ elif type(control) == QSpinBox:
+ self.connect(control, SIGNAL("valueChanged(int)"), lambda: self.stateChanged(id))
+ elif type(control) == QComboBox:
+ self.connect(control, SIGNAL("currentIndexChanged(int)"), lambda: self.stateChanged(id))
+ elif type(control) == QDoubleSpinBox:
+ self.connect(control, SIGNAL("valueChanged(double)"), lambda: self.stateChanged(id))
+ elif type(control) == QLineEdit:
+ self.connect(control, SIGNAL("textChanged(QString)"), lambda: self.stateChanged(id))
+
+ def clear(self):
+ """
+ Remove all the controls.
+ """
+ self._controls = {}
+
+ def stateChanged(self, id):
+ """
+ Slot called when the value of one of the stored widget changes. It emits
+ another signal.
+ """
+ self.emit(SIGNAL("stateChanged"), id)