From: duplo Date: Tue, 31 Mar 2009 16:27:53 +0000 (+0000) Subject: Group methods in classes in topics X-Git-Tag: 2.1.0~229 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=97903dc626136396587334b1d78f7623c91e9934;p=bertos.git Group methods in classes in topics git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2453 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/wizard/BCpuPage.py b/wizard/BCpuPage.py index 702248a8..b00c624c 100644 --- a/wizard/BCpuPage.py +++ b/wizard/BCpuPage.py @@ -24,74 +24,62 @@ class BCpuPage(BWizardPage): def __init__(self): BWizardPage.__init__(self, UI_LOCATION + "/cpu_select.ui") self.setTitle(self.tr("Select the CPU")) - self._connectSignals() - self._setupUi() - def _populateCpuList(self): - """ - Fills the cpu list. - """ - self.pageContent.cpuList.clear() - self.pageContent.cpuList.setCurrentItem(None) - infos = bertos_utils.loadCpuInfos(self._project()) - for cpu in infos: - item = QListWidgetItem(cpu["CPU_NAME"]) - item.setData(Qt.UserRole, qvariant_converter.convertDict(cpu)) - self.pageContent.cpuList.addItem(item) - - def _connectSignals(self): + ## Overloaded QWizardPage methods ## + + def isComplete(self): """ - Connects the signals with the related slots. + Overload of the QWizardPage isComplete method. """ - self.connect(self.pageContent.cpuList, SIGNAL("itemSelectionChanged()"), self.rowChanged) + if self.pageContent.cpuList.currentRow() != -1: + infos = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole)) + for key, value in infos.items(): + if type(CPU_DEF[key]) == list: + infos[key] = qvariant_converter.getStringList(value) + if type(CPU_DEF[key]) == str or type(CPU_DEF) == unicode: + infos[key] = qvariant_converter.getString(value) + self.setProjectInfo("CPU_INFOS", infos) + self.setProjectInfo("CPU_NAME", unicode(self.pageContent.cpuList.currentItem().text())) + return True + else: + return False - def _selectItem(self, cpu): - """ - Selects the given cpu from the list. - """ - elements = self.pageContent.cpuList.findItems(cpu, Qt.MatchCaseSensitive) - if len(elements) == 1: - self.pageContent.cpuList.setCurrentItem(elements[0]) + #### - def _setupUi(self): + ## Overloaded BWizardPage methods ## + + def setupUi(self): """ - Sets up the user interface. + Overload of the BWizardPage setupUi method. """ self.pageContent.cpuList.setSortingEnabled(True) self.pageContent.descriptionLabel.setVisible(False) self.pageContent.descriptionLabel.setText("") - + + def connectSignals(self): + """ + Overload of the BWizardPage connectSignals method. + """ + self.connect(self.pageContent.cpuList, SIGNAL("itemSelectionChanged()"), self.rowChanged) + def reloadData(self): """ Overload of the BWizardPage reloadData method. """ QApplication.instance().setOverrideCursor(Qt.WaitCursor) - bertos_utils.loadSourceTree(self._project()) - self._populateCpuList() - cpu_name = self._projectInfoRetrieve("CPU_NAME") - self._setupUi() + bertos_utils.loadSourceTree(self.project()) + self.populateCpuList() + cpu_name = self.projectInfo("CPU_NAME") + self.setupUi() if not cpu_name is None: - self._selectItem(cpu_name) + self.selectItem(cpu_name) QApplication.instance().restoreOverrideCursor() self.emit(SIGNAL("completeChanged()")) + + #### - def isComplete(self): - """ - Overload of the QWizardPage isComplete method. - """ - if self.pageContent.cpuList.currentRow() != -1: - infos = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole)) - for key, value in infos.items(): - if type(CPU_DEF[key]) == list: - infos[key] = qvariant_converter.getStringList(value) - if type(CPU_DEF[key]) == str or type(CPU_DEF) == unicode: - infos[key] = qvariant_converter.getString(value) - self._projectInfoStore("CPU_INFOS", infos) - self._projectInfoStore("CPU_NAME", unicode(self.pageContent.cpuList.currentItem().text())) - return True - else: - return False - + ## Slots ## + def rowChanged(self): """ Slot called when the user select an entry from the cpu list. @@ -101,3 +89,25 @@ class BCpuPage(BWizardPage): self.pageContent.descriptionLabel.setText("
".join(description)) self.pageContent.descriptionLabel.setVisible(True) self.emit(SIGNAL("completeChanged()")) + + #### + + def populateCpuList(self): + """ + Fills the cpu list. + """ + self.pageContent.cpuList.clear() + self.pageContent.cpuList.setCurrentItem(None) + infos = bertos_utils.loadCpuInfos(self.project()) + for cpu in infos: + item = QListWidgetItem(cpu["CPU_NAME"]) + item.setData(Qt.UserRole, qvariant_converter.convertDict(cpu)) + self.pageContent.cpuList.addItem(item) + + def selectItem(self, cpu): + """ + Selects the given cpu from the list. + """ + elements = self.pageContent.cpuList.findItems(cpu, Qt.MatchCaseSensitive) + if len(elements) == 1: + self.pageContent.cpuList.setCurrentItem(elements[0]) \ No newline at end of file diff --git a/wizard/BCreationPage.py b/wizard/BCreationPage.py index 8b2158f3..e865a2cc 100644 --- a/wizard/BCreationPage.py +++ b/wizard/BCreationPage.py @@ -23,32 +23,33 @@ class BCreationPage(BWizardPage): def __init__(self): BWizardPage.__init__(self, UI_LOCATION + "/project_creation.ui") self.setTitle(self.tr("Create the BeRTOS project")) - self._setupUi() self._completed = False - self.setButtonText(QWizard.NextButton, self.tr("Create")) + + ## Overloaded BWizardPage methods ## - def _setupUi(self): + def setupUi(self): summary = self.pageContent.summaryTree summary.setHeaderHidden(True) summary.setColumnCount(1) + self.setButtonText(QWizard.NextButton, self.tr("Create")) def reloadData(self): - self._setupUi() + self.setupUi() self.pageContent.summaryTree.clear() top_level = [] folder_title = QTreeWidgetItem(QStringList([self.tr("Project folder")])) - folder_item = QTreeWidgetItem(folder_title, QStringList([os.path.normpath(self._projectInfoRetrieve("PROJECT_PATH"))])) + folder_item = QTreeWidgetItem(folder_title, QStringList([os.path.normpath(self.projectInfo("PROJECT_PATH"))])) top_level.append(folder_title) version_title = QTreeWidgetItem(QStringList([self.tr("BeRTOS version")])) - sources_path = self._projectInfoRetrieve("SOURCES_PATH") + sources_path = self.projectInfo("SOURCES_PATH") version = QTreeWidgetItem(version_title, QStringList([self.tr("version: ") + bertos_utils.bertosVersion(sources_path)])) source_path = QTreeWidgetItem(version_title, QStringList([self.tr("path: ") + os.path.normpath(sources_path)])) top_level.append(version_title) cpu_title = QTreeWidgetItem(QStringList([self.tr("CPU")])) - cpu_name = QTreeWidgetItem(cpu_title, QStringList([self.tr("cpu name: ") + self._projectInfoRetrieve("CPU_NAME")])) + cpu_name = QTreeWidgetItem(cpu_title, QStringList([self.tr("cpu name: ") + self.projectInfo("CPU_NAME")])) top_level.append(cpu_title) toolchain_title = QTreeWidgetItem(QStringList([self.tr("Toolchain")])) - toolchain_info = self._projectInfoRetrieve("TOOLCHAIN") + toolchain_info = self.projectInfo("TOOLCHAIN") if "target" in toolchain_info.keys(): toolchain_target = QTreeWidgetItem(toolchain_title, QStringList([self.tr("target: " + toolchain_info["target"])])) if "version" in toolchain_info.keys(): @@ -56,9 +57,9 @@ class BCreationPage(BWizardPage): toolchain_path = QTreeWidgetItem(toolchain_title, QStringList([self.tr("path: " + os.path.normpath(toolchain_info["path"]))])) top_level.append(toolchain_title) module_title = QTreeWidgetItem(QStringList([self.tr("Modules")])) - configurations = self._projectInfoRetrieve("CONFIGURATIONS") + configurations = self.projectInfo("CONFIGURATIONS") module_categories = {} - for module, information in self._projectInfoRetrieve("MODULES").items(): + for module, information in self.projectInfo("MODULES").items(): if information["enabled"]: if information["category"] not in module_categories.keys(): module_categories[information["category"]] = [] @@ -76,4 +77,5 @@ class BCreationPage(BWizardPage): category_item.addChildren(value) top_level.append(module_title) self.pageContent.summaryTree.insertTopLevelItems(0, top_level) - + + #### \ No newline at end of file diff --git a/wizard/BFinalPage.py b/wizard/BFinalPage.py index af690eeb..7eda6f57 100644 --- a/wizard/BFinalPage.py +++ b/wizard/BFinalPage.py @@ -26,6 +26,8 @@ class BFinalPage(BWizardPage): def __init__(self): BWizardPage.__init__(self, UI_LOCATION + "/final_page.ui") self.setTitle(self.tr("Project created successfully")) + + ## Overloaded BWizardPage methods ## def reloadData(self): """ @@ -33,4 +35,6 @@ class BFinalPage(BWizardPage): """ QApplication.instance().setOverrideCursor(Qt.WaitCursor) bertos_utils.createBertosProject(self.wizard().project()) - QApplication.instance().restoreOverrideCursor() \ No newline at end of file + QApplication.instance().restoreOverrideCursor() + + #### \ No newline at end of file diff --git a/wizard/BFolderPage.py b/wizard/BFolderPage.py index a6fdc7a1..2628aa66 100644 --- a/wizard/BFolderPage.py +++ b/wizard/BFolderPage.py @@ -26,47 +26,75 @@ class BFolderPage(BWizardPage): def __init__(self): BWizardPage.__init__(self, UI_LOCATION + "/dir_select.ui") self.setTitle(self.tr("Select the project name")) - self._initializeAttributes() - self._setupUi() - self._connectSignals() + self.initializeAttributes() + + ## Overloaded QWizardPage methods ## - def _setupUi(self): + def isComplete(self): """ - Sets up the user interface. + Overload of the QWizardPage isComplete method. """ - self.pageContent.warningLabel.setVisible(False) + if self.pageContent.projectPath.text() != "None": + self.setProjectInfo("PROJECT_PATH", unicode(self.pageContent.projectPath.text())) + return True + else: + return False - def _initializeAttributes(self): + #### + + ## Overloaded BWizardPage methods ## + + def setupUi(self): """ - Initializes the page attributes to the default values. + Overload of the BWizardPage setupUi method. """ - self._project_name = "" - self._destination_folder = os.path.expanduser("~") - self.pageContent.directoryEdit.setText(self._destination_folder) + self.pageContent.warningLabel.setVisible(False) - def _connectSignals(self): + def connectSignals(self): """ - Connects the signals to the related slots. + Overload of the BWizardPage connectSignals method. """ - self.connect(self.pageContent.nameEdit, SIGNAL("textChanged(const QString)"), self._nameChanged) - self.connect(self.pageContent.directoryEdit, SIGNAL("textChanged(const QString)"), self._directoryChanged) - self.connect(self.pageContent.directoryButton, SIGNAL("clicked()"), self._selectDirectory) + self.connect(self.pageContent.nameEdit, SIGNAL("textChanged(const QString)"), self.nameChanged) + self.connect(self.pageContent.directoryEdit, SIGNAL("textChanged(const QString)"), self.directoryChanged) + self.connect(self.pageContent.directoryButton, SIGNAL("clicked()"), self.selectDirectory) + + #### + + ## Slots ## - def _nameChanged(self, name): + def nameChanged(self, name): """ Slot called when the project name is changed manually by the user. """ self._project_name = str(name).replace(" ", "_") - self._setProjectPath() + self.setProjectPath() - def _directoryChanged(self, directory): + def directoryChanged(self, directory): """ Slot called when the project folder is changed manually by the user. """ self._destination_folder = str(QDir.toNativeSeparators(directory)) - self._setProjectPath() + self.setProjectPath() + + def selectDirectory(self): + """ + Slot called when the project folder is changed using the file dialog. + """ + directory = unicode(QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), "", QFileDialog.ShowDirsOnly)) + if len(directory) > 0: + self.pageContent.directoryEdit.setText(directory) + + #### + + def initializeAttributes(self): + """ + Initializes the page attributes to the default values. + """ + self._project_name = "" + self._destination_folder = os.path.expanduser("~") + self.pageContent.directoryEdit.setText(self._destination_folder) - def _setProjectPath(self): + def setProjectPath(self): """ Analyzes the page attributes and generates the path string. """ @@ -85,22 +113,4 @@ class BFolderPage(BWizardPage): self.pageContent.projectPath.setText("None") self.pageContent.warningLabel.setVisible(False) self.pageContent.warningLabel.setText("") - self.emit(SIGNAL("completeChanged()")) - - def _selectDirectory(self): - """ - Slot called when the project folder is changed using the file dialog. - """ - directory = unicode(QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), "", QFileDialog.ShowDirsOnly)) - if len(directory) > 0: - self.pageContent.directoryEdit.setText(directory) - - def isComplete(self): - """ - Overload of the QWizardPage isComplete method. - """ - if self.pageContent.projectPath.text() != "None": - self._projectInfoStore("PROJECT_PATH", unicode(self.pageContent.projectPath.text())) - return True - else: - return False \ No newline at end of file + self.emit(SIGNAL("completeChanged()")) \ No newline at end of file diff --git a/wizard/BModulePage.py b/wizard/BModulePage.py index 2a5e0a42..4c681f85 100644 --- a/wizard/BModulePage.py +++ b/wizard/BModulePage.py @@ -27,85 +27,64 @@ class BModulePage(BWizardPage): BWizardPage.__init__(self, UI_LOCATION + "/module_select.ui") self.setTitle(self.tr("Configure the BeRTOS modules")) self._control_group = QControlGroup() - self._connectSignals() + ## special connection needed for the QControlGroup + self.connect(self._control_group, SIGNAL("stateChanged"), self.saveValue) - def reloadData(self): + ## Overloaded BWizardPage methods ## + + def setupUi(self): """ - Overload of the BWizardPage reloadData method. + Overload of BWizardPage setupUi method. """ - QApplication.instance().setOverrideCursor(Qt.WaitCursor) - self._setupUi() - self._loadModuleData() - self._fillModuleTree() - QApplication.instance().restoreOverrideCursor() + self.pageContent.moduleTree.clear() + self.pageContent.moduleTree.setHeaderHidden(True) + self.pageContent.propertyTable.horizontalHeader().setResizeMode(QHeaderView.Stretch) + self.pageContent.propertyTable.horizontalHeader().setVisible(False) + self.pageContent.propertyTable.verticalHeader().setResizeMode(QHeaderView.ResizeToContents) + self.pageContent.propertyTable.verticalHeader().setVisible(False) + self.pageContent.propertyTable.setColumnCount(2) + self.pageContent.propertyTable.setRowCount(0) + self.pageContent.moduleLabel.setVisible(False) - def _setupButtonGroup(self): + def connectSignals(self): """ - Sets up the button group. + Overload of the BWizardPage connectSignals method. """ - self._button_group = QButtonGroup() - self._button_group.setExclusive(False) - self.connect(self._button_group, SIGNAL("buttonClicked(int)"), self._moduleSelectionChanged) - - def _loadModuleData(self): + self.connect(self.pageContent.moduleTree, SIGNAL("itemPressed(QTreeWidgetItem*, int)"), self.fillPropertyTable) + self.connect(self.pageContent.moduleTree, SIGNAL("itemChanged(QTreeWidgetItem*, int)"), self.dependencyCheck) + self.connect(self.pageContent.propertyTable, SIGNAL("itemSelectionChanged()"), self.showPropertyDescription) + + def reloadData(self): """ - Loads the module data. + Overload of the BWizardPage reloadData method. """ - ## Load the module data only if it isn't already loaded - if self._projectInfoRetrieve("MODULES") == None \ - and self._projectInfoRetrieve("LISTS") == None \ - and self._projectInfoRetrieve("CONFIGURATIONS") == None: - try: - bertos_utils.loadModuleData(self._project()) - except ModuleDefineException, e: - self._exceptionOccurred(self.tr("Error parsing line '%2' in file %1").arg(e.path).arg(e.line)) - except EnumDefineException, e: - self._exceptionOccurred(self.tr("Error parsing line '%2' in file %1").arg(e.path).arg(e.line)) - except ConfigurationDefineException, e: - self._exceptionOccurred(self.tr("Error parsing line '%2' in file %1").arg(e.path).arg(e.line)) + QApplication.instance().setOverrideCursor(Qt.WaitCursor) + self.setupUi() + self.loadModuleData() + self.fillModuleTree() + QApplication.instance().restoreOverrideCursor() - def _fillModuleTree(self): - """ - Fills the module tree with the module entries separated in categories. - """ - modules = self._projectInfoRetrieve("MODULES") - if modules is None: - return - categories = {} - for module, information in modules.items(): - if information["category"] not in categories.keys(): - categories[information["category"]] = [] - categories[information["category"]].append(module) - for category, module_list in categories.items(): - item = QTreeWidgetItem(QStringList([category])) - for module in module_list: - enabled = modules[module]["enabled"] - module_item = QTreeWidgetItem(item, QStringList([module])) - if enabled: - module_item.setCheckState(0, Qt.Checked) - else: - module_item.setCheckState(0, Qt.Unchecked) - self.pageContent.moduleTree.addTopLevelItem(item) - self.pageContent.moduleTree.sortItems(0, Qt.AscendingOrder) - + #### - def _fillPropertyTable(self): + ## Slots ## + + def fillPropertyTable(self): """ Slot called when the user selects a module from the module tree. Fills the property table using the configuration parameters defined in the source tree. """ - module = self._currentModule() + module = self.currentModule() if module is not None: self._control_group.clear() - configuration = self._projectInfoRetrieve("MODULES")[module]["configuration"] - module_description = self._projectInfoRetrieve("MODULES")[module]["description"] + configuration = self.projectInfo("MODULES")[module]["configuration"] + module_description = self.projectInfo("MODULES")[module]["description"] self.pageContent.moduleLabel.setText(module_description) self.pageContent.moduleLabel.setVisible(True) self.pageContent.propertyTable.clear() self.pageContent.propertyTable.setRowCount(0) if configuration != "": - configurations = self._projectInfoRetrieve("CONFIGURATIONS")[configuration] + configurations = self.projectInfo("CONFIGURATIONS")[configuration] param_list = sorted(configurations["paramlist"]) index = 0 for i, property in param_list: @@ -119,11 +98,11 @@ class BModulePage(BWizardPage): item.setData(Qt.UserRole, qvariant_converter.convertString(property)) self.pageContent.propertyTable.setItem(index, 0, item) if "type" in configurations[property]["informations"].keys() and configurations[property]["informations"]["type"] == "boolean": - self._insertCheckBox(index, configurations[property]["value"]) + self.insertCheckBox(index, configurations[property]["value"]) elif "type" in configurations[property]["informations"].keys() and configurations[property]["informations"]["type"] == "enum": - self._insertComboBox(index, configurations[property]["value"], configurations[property]["informations"]["value_list"]) + self.insertComboBox(index, configurations[property]["value"], configurations[property]["informations"]["value_list"]) elif "type" in configurations[property]["informations"] and configurations[property]["informations"]["type"] == "int": - self._insertSpinBox(index, configurations[property]["value"], configurations[property]["informations"]) + self.insertSpinBox(index, configurations[property]["value"], configurations[property]["informations"]) else: # Not defined type, rendered as a text field self.pageContent.propertyTable.setItem(index, 1, QTableWidgetItem(configurations[property]["value"])) @@ -132,8 +111,93 @@ class BModulePage(BWizardPage): module_label = self.pageContent.moduleLabel.text() module_label += "\n\nNo configuration needed." self.pageContent.moduleLabel.setText(module_label) + + def dependencyCheck(self, item): + """ + Checks the dependencies of the module associated with the given item. + """ + checked = False + module = unicode(item.text(0)) + if item.checkState(0) == Qt.Checked: + self.moduleSelected(module) + else: + self.moduleUnselected(module) + self.removeFileDependencies(module) + + def showPropertyDescription(self): + """ + Slot called when the property selection changes. Shows the description + of the selected property. + """ + self.resetPropertyDescription() + configurations = self.currentModuleConfigurations() + if self.currentProperty() in configurations.keys(): + description = configurations[self.currentProperty()]["brief"] + name = self.currentProperty() + self.currentPropertyItem().setText(description + "\n" + name) + + def saveValue(self, index): + """ + Slot called when the user modifies one of the configuration parameters. + It stores the new value.""" + property = qvariant_converter.getString(self.pageContent.propertyTable.item(index, 0).data(Qt.UserRole)) + configuration = self.projectInfo("MODULES")[self.currentModule()]["configuration"] + configurations = self.projectInfo("CONFIGURATIONS") + if "type" not in configurations[configuration][property]["informations"].keys() or configurations[configuration][property]["informations"]["type"] == "int": + configurations[configuration][property]["value"] = str(int(self.pageContent.propertyTable.cellWidget(index, 1).value())) + elif configurations[configuration][property]["informations"]["type"] == "enum": + configurations[configuration][property]["value"] = unicode(self.pageContent.propertyTable.cellWidget(index, 1).currentText()) + elif configurations[configuration][property]["informations"]["type"] == "boolean": + if self.pageContent.propertyTable.cellWidget(index, 1).isChecked(): + configurations[configuration][property]["value"] = "1" + else: + configurations[configuration][property]["value"] = "0" + self.setProjectInfo("CONFIGURATIONS", configurations) + + #### - def _insertCheckBox(self, index, value): + def loadModuleData(self): + """ + Loads the module data. + """ + ## Load the module data only if it isn't already loaded + if self.projectInfo("MODULES") == None \ + and self.projectInfo("LISTS") == None \ + and self.projectInfo("CONFIGURATIONS") == None: + try: + bertos_utils.loadModuleData(self.project()) + except ModuleDefineException, e: + self.exceptionOccurred(self.tr("Error parsing line '%2' in file %1").arg(e.path).arg(e.line)) + except EnumDefineException, e: + self.exceptionOccurred(self.tr("Error parsing line '%2' in file %1").arg(e.path).arg(e.line)) + except ConfigurationDefineException, e: + self.exceptionOccurred(self.tr("Error parsing line '%2' in file %1").arg(e.path).arg(e.line)) + + def fillModuleTree(self): + """ + Fills the module tree with the module entries separated in categories. + """ + modules = self.projectInfo("MODULES") + if modules is None: + return + categories = {} + for module, information in modules.items(): + if information["category"] not in categories.keys(): + categories[information["category"]] = [] + categories[information["category"]].append(module) + for category, module_list in categories.items(): + item = QTreeWidgetItem(QStringList([category])) + for module in module_list: + enabled = modules[module]["enabled"] + module_item = QTreeWidgetItem(item, QStringList([module])) + if enabled: + module_item.setCheckState(0, Qt.Checked) + else: + module_item.setCheckState(0, Qt.Unchecked) + self.pageContent.moduleTree.addTopLevelItem(item) + self.pageContent.moduleTree.sortItems(0, Qt.AscendingOrder) + + def insertCheckBox(self, index, value): """ Inserts in the table at index a checkbox for a boolean property setted to value. @@ -146,13 +210,13 @@ class BModulePage(BWizardPage): check_box.setChecked(False) self._control_group.addControl(index, check_box) - def _insertComboBox(self, index, value, value_list): + def insertComboBox(self, index, value, value_list): """ Inserts in the table at index a combobox for an enum property setted to value. """ try: - enum = self._projectInfoRetrieve("LISTS")[value_list] + enum = self.projectInfo("LISTS")[value_list] combo_box = QComboBox() self.pageContent.propertyTable.setCellWidget(index, 1, combo_box) for i, element in enumerate(enum): @@ -161,10 +225,10 @@ class BModulePage(BWizardPage): combo_box.setCurrentIndex(i) self._control_group.addControl(index, combo_box) except KeyError: - self._exceptionOccurred(self.tr("Define list \"%1\" not found. Check definition files.").arg(value_list)) + self.exceptionOccurred(self.tr("Define list \"%1\" not found. Check definition files.").arg(value_list)) self.pageContent.propertyTable.setItem(index, 1, QTableWidgetItem(value)) - def _insertSpinBox(self, index, value, informations): + def insertSpinBox(self, index, value, informations): """ Inserts in the table at index a spinbox for an int, a long or an unsigned long property setted to value. @@ -202,7 +266,7 @@ class BModulePage(BWizardPage): self._control_group.addControl(index, spin_box) - def _currentModule(self): + def currentModule(self): """ Retuns the current module name. """ @@ -213,135 +277,59 @@ class BModulePage(BWizardPage): else: return None - def _currentModuleConfigurations(self): + def currentModuleConfigurations(self): """ Returns the current module configuration. """ - return self._configurations(self._currentModule()) + return self.configurations(self.currentModule()) - def _currentProperty(self): + def currentProperty(self): """ Rerturns the current property from the property table. """ return qvariant_converter.getString(self.pageContent.propertyTable.item(self.pageContent.propertyTable.currentRow(), 0).data(Qt.UserRole)) - def _currentPropertyItem(self): + def currentPropertyItem(self): """ Returns the QTableWidgetItem of the current property. """ return self.pageContent.propertyTable.item(self.pageContent.propertyTable.currentRow(), 0) - def _configurations(self, module): + def configurations(self, module): """ Returns the configuration for the selected module. """ - configuration = self._projectInfoRetrieve("MODULES")[module]["configuration"] + configuration = self.projectInfo("MODULES")[module]["configuration"] if len(configuration) > 0: - return self._projectInfoRetrieve("CONFIGURATIONS")[configuration] + return self.projectInfo("CONFIGURATIONS")[configuration] else: return {} - def _resetPropertyDescription(self): + def resetPropertyDescription(self): """ Resets the label for each property table entry. """ for index in range(self.pageContent.propertyTable.rowCount()): property_name = qvariant_converter.getString(self.pageContent.propertyTable.item(index, 0).data(Qt.UserRole)) # Awful solution! Needed because if the user change the module, the selection changed... - if property_name not in self._currentModuleConfigurations().keys(): + if property_name not in self.currentModuleConfigurations().keys(): break - self.pageContent.propertyTable.item(index, 0).setText(self._currentModuleConfigurations()[property_name]['brief']) - - def _showPropertyDescription(self): - """ - Slot called when the property selection changes. Shows the description - of the selected property. - """ - self._resetPropertyDescription() - configurations = self._currentModuleConfigurations() - if self._currentProperty() in configurations.keys(): - description = configurations[self._currentProperty()]["brief"] - name = self._currentProperty() - self._currentPropertyItem().setText(description + "\n" + name) - - def _setupUi(self): - """ - Set up the user interface. - """ - self.pageContent.moduleTree.clear() - self.pageContent.moduleTree.setHeaderHidden(True) - self.pageContent.propertyTable.horizontalHeader().setResizeMode(QHeaderView.Stretch) - self.pageContent.propertyTable.horizontalHeader().setVisible(False) - self.pageContent.propertyTable.verticalHeader().setResizeMode(QHeaderView.ResizeToContents) - self.pageContent.propertyTable.verticalHeader().setVisible(False) - self.pageContent.propertyTable.setColumnCount(2) - self.pageContent.propertyTable.setRowCount(0) - self.pageContent.moduleLabel.setVisible(False) - - def _connectSignals(self): - """ - Connect the signals with the related slots. - """ - self.connect(self.pageContent.moduleTree, SIGNAL("itemPressed(QTreeWidgetItem*, int)"), self._fillPropertyTable) - self.connect(self.pageContent.moduleTree, SIGNAL("itemChanged(QTreeWidgetItem*, int)"), self._dependencyCheck) - self.connect(self.pageContent.propertyTable, SIGNAL("itemSelectionChanged()"), self._showPropertyDescription) - self.connect(self._control_group, SIGNAL("stateChanged"), self._saveValue) - - def _saveValue(self, index): - """ - Slot called when the user modifies one of the configuration parameters. - It stores the new value.""" - property = qvariant_converter.getString(self.pageContent.propertyTable.item(index, 0).data(Qt.UserRole)) - configuration = self._projectInfoRetrieve("MODULES")[self._currentModule()]["configuration"] - configurations = self._projectInfoRetrieve("CONFIGURATIONS") - if "type" not in configurations[configuration][property]["informations"].keys() or configurations[configuration][property]["informations"]["type"] == "int": - configurations[configuration][property]["value"] = str(int(self.pageContent.propertyTable.cellWidget(index, 1).value())) - elif configurations[configuration][property]["informations"]["type"] == "enum": - configurations[configuration][property]["value"] = unicode(self.pageContent.propertyTable.cellWidget(index, 1).currentText()) - elif configurations[configuration][property]["informations"]["type"] == "boolean": - if self.pageContent.propertyTable.cellWidget(index, 1).isChecked(): - configurations[configuration][property]["value"] = "1" - else: - configurations[configuration][property]["value"] = "0" - self._projectInfoStore("CONFIGURATIONS", configurations) - - def _moduleSelectionChanged(self, index): - """ - Slot called when the user selects or unselects a module from the module - tree. - """ - module = unicode(self.pageContent.moduleTable.item(index, 1).text()) - if self._button_group.button(index).isChecked(): - self._moduleSelected(module) - else: - self._moduleUnselected(module) - - def _dependencyCheck(self, item): - """ - Checks the dependencies of the module associated with the given item. - """ - checked = False - module = unicode(item.text(0)) - if item.checkState(0) == Qt.Checked: - self._moduleSelected(module) - else: - self._moduleUnselected(module) - self.removeFileDependencies(module) + self.pageContent.propertyTable.item(index, 0).setText(self.currentModuleConfigurations()[property_name]['brief']) - def _moduleSelected(self, selectedModule): + def moduleSelected(self, selectedModule): """ Resolves the selection dependencies. """ - modules = self._projectInfoRetrieve("MODULES") + modules = self.projectInfo("MODULES") modules[selectedModule]["enabled"] = True - self._projectInfoStore("MODULES", modules) - depends = self._projectInfoRetrieve("MODULES")[selectedModule]["depends"] + 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._projectInfoRetrieve("MODULES") + modules = self.projectInfo("MODULES") modules[module]["enabled"] = True for category in range(self.pageContent.moduleTree.topLevelItemCount()): item = self.pageContent.moduleTree.topLevelItem(category) @@ -349,13 +337,13 @@ class BModulePage(BWizardPage): if unicode(item.child(child).text(0)) in unsatisfied: item.child(child).setCheckState(0, Qt.Checked) - def _moduleUnselected(self, unselectedModule): + def moduleUnselected(self, unselectedModule): """ Resolves the unselection dependencies. """ - modules = self._projectInfoRetrieve("MODULES") + modules = self.projectInfo("MODULES") modules[unselectedModule]["enabled"] = False - self._projectInfoStore("MODULES", modules) + self.setProjectInfo("MODULES", modules) unsatisfied = [] if self.pageContent.automaticFix.isChecked(): unsatisfied = self.unselectDependencyCheck(unselectedModule) @@ -365,7 +353,7 @@ class BModulePage(BWizardPage): 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 = self.projectInfo("MODULES") modules[module]["enabled"] = False for category in range(self.pageContent.moduleTree.topLevelItemCount()): item = self.pageContent.moduleTree.topLevelItem(category) @@ -378,8 +366,8 @@ class BModulePage(BWizardPage): Returns the list of unsatisfied dependencies after a selection. """ unsatisfied = set() - modules = self._projectInfoRetrieve("MODULES") - files = self._projectInfoRetrieve("FILES") + modules = self.projectInfo("MODULES") + files = self.projectInfo("FILES") for dependency in modules[module]["depends"]: if dependency in modules and not modules[dependency]["enabled"]: unsatisfied |= set([dependency]) @@ -390,7 +378,7 @@ class BModulePage(BWizardPage): files[dependency] += 1 else: files[dependency] = 1 - self._projectInfoStore("FILES", files) + self.setProjectInfo("FILES", files) return unsatisfied def unselectDependencyCheck(self, dependency): @@ -398,7 +386,7 @@ class BModulePage(BWizardPage): Returns the list of unsatisfied dependencies after an unselection. """ unsatisfied = set() - modules = self._projectInfoRetrieve("MODULES") + modules = self.projectInfo("MODULES") for module, informations in modules.items(): if dependency in informations["depends"] and informations["enabled"]: unsatisfied |= set([module]) @@ -410,15 +398,15 @@ class BModulePage(BWizardPage): """ Removes the files dependencies of the given module. """ - modules = self._projectInfoRetrieve("MODULES") - files = self._projectInfoRetrieve("FILES") + 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._projectInfoStore("FILES", files) + self.setProjectInfo("FILES", files) class QControlGroup(QObject): """ @@ -437,13 +425,13 @@ class QControlGroup(QObject): """ self._controls[id] = control if type(control) == QCheckBox: - self.connect(control, SIGNAL("stateChanged(int)"), lambda: self._stateChanged(id)) + self.connect(control, SIGNAL("stateChanged(int)"), lambda: self.stateChanged(id)) elif type(control) == QSpinBox: - self.connect(control, SIGNAL("valueChanged(int)"), lambda: self._stateChanged(id)) + self.connect(control, SIGNAL("valueChanged(int)"), lambda: self.stateChanged(id)) elif type(control) == QComboBox: - self.connect(control, SIGNAL("currentIndexChanged(int)"), lambda: self._stateChanged(id)) + self.connect(control, SIGNAL("currentIndexChanged(int)"), lambda: self.stateChanged(id)) elif type(control) == QDoubleSpinBox: - self.connect(control, SIGNAL("valueChanged(double)"), lambda: self._stateChanged(id)) + self.connect(control, SIGNAL("valueChanged(double)"), lambda: self.stateChanged(id)) def clear(self): """ @@ -451,7 +439,7 @@ class QControlGroup(QObject): """ self._controls = {} - def _stateChanged(self, id): + def stateChanged(self, id): """ Slot called when the value of one of the stored widget changes. It emits another signal. diff --git a/wizard/BOutputPage.py b/wizard/BOutputPage.py index fb7eaade..aea68aaf 100644 --- a/wizard/BOutputPage.py +++ b/wizard/BOutputPage.py @@ -25,25 +25,32 @@ class BOutputPage(BWizardPage): def __init__(self): BWizardPage.__init__(self, UI_LOCATION + "/output_select.ui") self.setTitle(self.tr("Choose the project output")) - self._connectSignals() - self._projectInfoStore("OUTPUT", []) + self.connectSignals() + self.setProjectInfo("OUTPUT", []) - def _connectSignals(self): + ## Overloaded BWizardPage connectSignals method. ## + + def connectSignals(self): """ Connects the signals with the related slots. """ - self.connect(self.pageContent.eclipseCheckBox, SIGNAL("stateChanged(int)"), lambda checked: self._modeChecked(checked, "eclipse")) - self.connect(self.pageContent.xcodeCheckBox, SIGNAL("stateChanged(int)"), lambda checked: self._modeChecked(checked, "xcode")) - self.connect(self.pageContent.codeliteCheckBox, SIGNAL("stateChanged(int)"), lambda checked: self._modeChecked(checked, "codelite")) + self.connect(self.pageContent.eclipseCheckBox, SIGNAL("stateChanged(int)"), lambda checked: self.modeChecked(checked, "eclipse")) + self.connect(self.pageContent.xcodeCheckBox, SIGNAL("stateChanged(int)"), lambda checked: self.modeChecked(checked, "xcode")) + self.connect(self.pageContent.codeliteCheckBox, SIGNAL("stateChanged(int)"), lambda checked: self.modeChecked(checked, "codelite")) + + #### - def _modeChecked(self, checked, value): + ## Slots ## + + def modeChecked(self, checked, value): """ Slot called when one of the mode checkbox is checked. It stores it. """ - output_list = self._projectInfoRetrieve("OUTPUT") + output_list = self.projectInfo("OUTPUT") if checked == Qt.Checked: output_list.append(value) else: output_list.remove(value) - self._projectInfoStore("OUTPUT", output_list) - \ No newline at end of file + self.setProjectInfo("OUTPUT", output_list) + + #### \ No newline at end of file diff --git a/wizard/BToolchainPage.py b/wizard/BToolchainPage.py index 0736a99a..1820768a 100644 --- a/wizard/BToolchainPage.py +++ b/wizard/BToolchainPage.py @@ -29,22 +29,114 @@ class BToolchainPage(BWizardPage): BWizardPage.__init__(self, UI_LOCATION + "/toolchain_select.ui") self.setTitle(self.tr("Select toolchain")) self._validation_process = None - self._setupUi() - #self._populateToolchainList() - self._connectSignals() + + ## Overloaded QWizardPage methods. ## + + def isComplete(self): + """ + Overload of the QWizard isComplete method. + """ + if self.pageContent.toolchainList.currentRow() != -1: + self.setProjectInfo("TOOLCHAIN", + qvariant_converter.getStringDict(self.pageContent.toolchainList.currentItem().data(Qt.UserRole))) + return True + else: + return False - def _setupUi(self): + #### + + ## Overloaded BWizardPage methods. ## + + def setupUi(self): """ Sets up the user interface. """ self.pageContent.infoLabel.setVisible(False) + def connectSignals(self): + """ + Connects the signals with the related slots. + """ + self.connect(self.pageContent.toolchainList, SIGNAL("itemSelectionChanged()"), self.selectionChanged) + self.connect(self.pageContent.addButton, SIGNAL("clicked()"), self.addToolchain) + self.connect(self.pageContent.removeButton, SIGNAL("clicked()"), self.removeToolchain) + self.connect(self.pageContent.searchButton, SIGNAL("clicked()"), self.searchToolchain) + self.connect(self.pageContent.checkButton, SIGNAL("clicked()"), self.validateAllToolchains) + + def reloadData(self): + """ + Overload of the BWizard reloadData method. + """ + self._clearList() + self.setupUi() + self._populateToolchainList() + + #### + + ## Slots ## + + def selectionChanged(self): + """ + Slot called when the user click on an entry of the toolchain list. + """ + if self.pageContent.toolchainList.currentRow() != -1: + infos = collections.defaultdict(lambda: unicode("not defined")) + infos.update(qvariant_converter.getStringDict(self.pageContent.toolchainList.currentItem().data(Qt.UserRole))) + self.pageContent.infoLabel.setText("GCC " + infos["version"] + " (" + infos["build"] + ")\nTarget: " + infos["target"] + "\nPath: " + os.path.normpath(infos["path"])) + self.pageContent.infoLabel.setVisible(True) + self.emit(SIGNAL("completeChanged()")) + + def addToolchain(self): + """ + Slot called when the user adds manually a toolchain. + """ + sel_toolchain = QFileDialog.getOpenFileName(self, self.tr("Choose the toolchain"), "") + if not sel_toolchain.isEmpty(): + item = QListWidgetItem(sel_toolchain) + item.setData(Qt.UserRole, qvariant_converter.convertString({"path": sel_toolchain})) + self.pageContent.toolchainList.addItem(item) + toolchains = self.toolchains() + toolchains[sel_toolchain] = False + self.setToolchains(toolchains) + + def removeToolchain(self): + """ + Slot called when the user removes manually a toolchain. + """ + if self.pageContent.toolchainList.currentRow() != -1: + item = self.pageContent.toolchainList.takeItem(self.pageContent.toolchainList.currentRow()) + toolchain = qvariant_converter.getStringDict(item.data(Qt.UserRole))["path"] + toolchains = self.toolchains() + del toolchains[toolchain] + self.setToolchains(toolchains) + + def searchToolchain(self): + """ + Slot called when the user clicks on the 'search' button. It opens the + toolchain search dialog. + """ + search = BToolchainSearch.BToolchainSearch() + self.connect(search, SIGNAL("accepted()"), self._search) + search.exec_() + + def validateAllToolchains(self): + """ + Slot called when the user clicks on the validate button. It starts the + toolchain validation procedure for all the toolchains. + """ + QApplication.instance().setOverrideCursor(Qt.WaitCursor) + for i in range(self.pageContent.toolchainList.count()): + self.validateToolchain(i) + QApplication.instance().restoreOverrideCursor() + + #### + def _populateToolchainList(self): """ Fills the toolchain list with the toolchains stored in the QSettings. """ toolchains = self.toolchains() - sel_toolchain = self._projectInfoRetrieve("TOOLCHAIN") + sel_toolchain = self.projectInfo("TOOLCHAIN") for key, value in toolchains.items(): item = QListWidgetItem(key) item.setData(Qt.UserRole, qvariant_converter.convertStringDict({"path": key})) @@ -60,17 +152,6 @@ class BToolchainPage(BWizardPage): """ self.pageContent.toolchainList.clear() - def _selectionChanged(self): - """ - Slot called when the user click on an entry of the toolchain list. - """ - if self.pageContent.toolchainList.currentRow() != -1: - infos = collections.defaultdict(lambda: unicode("not defined")) - infos.update(qvariant_converter.getStringDict(self.pageContent.toolchainList.currentItem().data(Qt.UserRole))) - self.pageContent.infoLabel.setText("GCC " + infos["version"] + " (" + infos["build"] + ")\nTarget: " + infos["target"] + "\nPath: " + os.path.normpath(infos["path"])) - self.pageContent.infoLabel.setVisible(True) - self.emit(SIGNAL("completeChanged()")) - def _search(self): """ Searches for toolchains in the stored directories, and stores them in the @@ -89,16 +170,6 @@ class BToolchainPage(BWizardPage): stored_toolchains[element] = False self.setToolchains(stored_toolchains) - def _connectSignals(self): - """ - Connects the signals with the related slots. - """ - self.connect(self.pageContent.toolchainList, SIGNAL("itemSelectionChanged()"), self._selectionChanged) - self.connect(self.pageContent.addButton, SIGNAL("clicked()"), self.addToolchain) - self.connect(self.pageContent.removeButton, SIGNAL("clicked()"), self.removeToolchain) - self.connect(self.pageContent.searchButton, SIGNAL("clicked()"), self.searchToolchain) - self.connect(self.pageContent.checkButton, SIGNAL("clicked()"), self.validateAllToolchains) - def _validItem(self, index, infos): """ Sets the item at index as a valid item and associates the given info to it. @@ -107,7 +178,7 @@ class BToolchainPage(BWizardPage): new_data = qvariant_converter.getStringDict(self.pageContent.toolchainList.item(index).data(Qt.UserRole)) new_data.update(infos) item.setData(Qt.UserRole, qvariant_converter.convertStringDict(new_data)) - needed = self._projectInfoRetrieve("CPU_INFOS") + needed = self.projectInfo("CPU_INFOS") if "target" in infos.keys() and infos["target"].find(needed["TOOLCHAIN"]) != -1: item.setIcon(QIcon(":/images/ok.png")) else: @@ -121,50 +192,7 @@ class BToolchainPage(BWizardPage): """ item = self.pageContent.toolchainList.item(index) item.setIcon(QIcon(":/images/error.png")) - - def addToolchain(self): - """ - Slot called when the user adds manually a toolchain. - """ - sel_toolchain = QFileDialog.getOpenFileName(self, self.tr("Choose the toolchain"), "") - if not sel_toolchain.isEmpty(): - item = QListWidgetItem(sel_toolchain) - item.setData(Qt.UserRole, qvariant_converter.convertString({"path": sel_toolchain})) - self.pageContent.toolchainList.addItem(item) - toolchains = self.toolchains() - toolchains[sel_toolchain] = False - self.setToolchains(toolchains) - - def removeToolchain(self): - """ - Slot called when the user removes manually a toolchain. - """ - if self.pageContent.toolchainList.currentRow() != -1: - item = self.pageContent.toolchainList.takeItem(self.pageContent.toolchainList.currentRow()) - toolchain = qvariant_converter.getStringDict(item.data(Qt.UserRole))["path"] - toolchains = self.toolchains() - del toolchains[toolchain] - self.setToolchains(toolchains) - - def searchToolchain(self): - """ - Slot called when the user clicks on the 'search' button. It opens the - toolchain search dialog. - """ - search = BToolchainSearch.BToolchainSearch() - self.connect(search, SIGNAL("accepted()"), self._search) - search.exec_() - - def validateAllToolchains(self): - """ - Slot called when the user clicks on the validate button. It starts the - toolchain validation procedure for all the toolchains. - """ - QApplication.instance().setOverrideCursor(Qt.WaitCursor) - for i in range(self.pageContent.toolchainList.count()): - self.validateToolchain(i) - QApplication.instance().restoreOverrideCursor() - + def validateToolchain(self, i): """ Toolchain validation procedure. @@ -198,23 +226,4 @@ class BToolchainPage(BWizardPage): self._invalidItem(i) toolchains = self.toolchains() toolchains[filename] = True - self.setToolchains(toolchains) - - def isComplete(self): - """ - Overload of the QWizard isComplete method. - """ - if self.pageContent.toolchainList.currentRow() != -1: - self._projectInfoStore("TOOLCHAIN", - qvariant_converter.getStringDict(self.pageContent.toolchainList.currentItem().data(Qt.UserRole))) - return True - else: - return False - - def reloadData(self): - """ - Overload of the BWizard reloadData method. - """ - self._clearList() - self._setupUi() - self._populateToolchainList() \ No newline at end of file + self.setToolchains(toolchains) \ No newline at end of file diff --git a/wizard/BVersionPage.py b/wizard/BVersionPage.py index d9097a32..73e98614 100644 --- a/wizard/BVersionPage.py +++ b/wizard/BVersionPage.py @@ -26,14 +26,38 @@ class BVersionPage(BWizardPage): def __init__(self): BWizardPage.__init__(self, UI_LOCATION + "/bertos_versions.ui") - self._connectSignals() - self._fillVersionList() - self._setupUi() self.setTitle(self.tr("Select the BeRTOS version needed")) + + ## Overloaded QWizardPage methods ## + + def isComplete(self): + """ + Overload of the QWizardPage isComplete method. + """ + if self.pageContent.versionList.currentRow() != -1: + # Remove trailing slash + sources_path = qvariant_converter.getString(self.pageContent.versionList.currentItem().data(Qt.UserRole)) + if sources_path.endswith(os.sep): + sources_path = sources_path[:-1] + self.setProjectInfo("SOURCES_PATH", sources_path) + return True + else: + return False - def _connectSignals(self): + #### + + ## Overloaded BWizardPage methods ## + + def setupUi(self): """ - Connects the signals to the related slots. + Overload of the BWizardPage setupUi method. + """ + self.fillVersionList() + self.pageContent.versionList.setCurrentRow(-1) + + def connectSignals(self): + """ + Overload of the BWizardPage connectSignals method. """ self.connect(self.pageContent.versionList, SIGNAL("itemSelectionChanged()"), self.rowChanged) self.connect(self.pageContent.addButton, SIGNAL("clicked()"), self.addVersion) @@ -41,13 +65,45 @@ class BVersionPage(BWizardPage): # Fake signal connection for the update button self.connect(self.pageContent.updateButton, SIGNAL("clicked()"), self.updateClicked) - def _setupUi(self): + #### + + ## Slots ## + + def addVersion(self): """ - Sets up the user interface. + Slot called when the user add a BeRTOS version. """ - self.pageContent.versionList.setCurrentRow(-1) + directory = QFileDialog.getExistingDirectory(self, self.tr("Choose a directory"), "", QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks) + if not directory.isEmpty(): + self.storeVersion(unicode(directory)) + self.pageContent.versionList.clear() + self.fillVersionList() + self.emit(SIGNAL("completeChanged()")) - def _storeVersion(self, directory): + def removeVersion(self): + """ + Slot called when the user remove a BeRTOS version. + """ + item = self.pageContent.versionList.takeItem(self.pageContent.versionList.currentRow()) + self.deleteVersion(qvariant_converter.getString(item.data(Qt.UserRole))) + self.emit(SIGNAL("completeChanged()")) + + def rowChanged(self): + """ + Slot called when the user select an entry from the version list. + """ + self.emit(SIGNAL("completeChanged()")) + + def updateClicked(self): + """ + Slot called when the user clicks on the 'update' button. It checks for + update (TO BE IMPLEMENTED). + """ + pass + + #### + + def storeVersion(self, directory): """ Stores the directory selected by the user in the QSettings. """ @@ -55,7 +111,7 @@ class BVersionPage(BWizardPage): versions = set(versions + [directory]) self.setVersions(list(versions)) - def _deleteVersion(self, directory): + def deleteVersion(self, directory): """ Removes the given directory from the QSettings. """ @@ -63,7 +119,7 @@ class BVersionPage(BWizardPage): versions.remove(directory) self.setVersions(versions) - def _insertListElement(self, directory): + def insertListElement(self, directory): """ Inserts the given directory in the version list. """ @@ -76,55 +132,10 @@ class BVersionPage(BWizardPage): item.setData(Qt.UserRole, qvariant_converter.convertString(directory)) self.pageContent.versionList.addItem(item) - def _fillVersionList(self): + def fillVersionList(self): """ Fills the version list with all the BeRTOS versions founded in the QSettings. """ versions = self.versions() for directory in versions: - self._insertListElement(directory) - - def isComplete(self): - """ - Overload of the QWizardPage isComplete method. - """ - if self.pageContent.versionList.currentRow() != -1: - # Remove trailing slash - sources_path = qvariant_converter.getString(self.pageContent.versionList.currentItem().data(Qt.UserRole)) - if sources_path.endswith(os.sep): - sources_path = sources_path[:-1] - self._projectInfoStore("SOURCES_PATH", sources_path) - return True - else: - return False - - def addVersion(self): - """ - Slot called when the user add a BeRTOS version. - """ - directory = QFileDialog.getExistingDirectory(self, self.tr("Choose a directory"), "", QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks) - if not directory.isEmpty(): - self._storeVersion(unicode(directory)) - self.pageContent.versionList.clear() - self._fillVersionList() - self.emit(SIGNAL("completeChanged()")) - - def removeVersion(self): - """ - Slot called when the user remove a BeRTOS version. - """ - item = self.pageContent.versionList.takeItem(self.pageContent.versionList.currentRow()) - self._deleteVersion(qvariant_converter.getString(item.data(Qt.UserRole))) - self.emit(SIGNAL("completeChanged()")) - - def updateClicked(self): - """ - Checks for update (TO BE IMPLEMENTED). - """ - pass - - def rowChanged(self): - """ - Slot called when the user select an entry from the version list. - """ - self.emit(SIGNAL("completeChanged()")) \ No newline at end of file + self.insertListElement(directory) \ No newline at end of file diff --git a/wizard/BWizardPage.py b/wizard/BWizardPage.py index e1a815d1..d5346955 100644 --- a/wizard/BWizardPage.py +++ b/wizard/BWizardPage.py @@ -27,92 +27,104 @@ class BWizardPage(QWizardPage): layout = QVBoxLayout() layout.addWidget(self.pageContent) self.setLayout(layout) + self.setupUi() + self.connectSignals() - def _exceptionOccurred(self, message): + def exceptionOccurred(self, message): """ Simple message box showing method. """ QMessageBox.critical(self, self.tr("Error occurred"), message, QMessageBox.Ok, QMessageBox.NoButton) + + ## BProject interaction methods ## - def _settingsStore(self, key, value): - """ - Stores the given value in the QSettings associated with the given key. - """ - QApplication.instance().settings.setValue(QString(key), value) - - def _settingsRetrieve(self, key): - """ - Retrieves the value associated to key in the QSettings. Note that this - Value is a QVariant and neet to be converted in a standard type. - """ - return QApplication.instance().settings.value(QString(key), QVariant()) - - def _projectInfoStore(self, key, value): + def setProjectInfo(self, key, value): """ Stores the given value in the BProject class associating it with the given key. """ QApplication.instance().project.setInfo(key, value) - def _projectInfoRetrieve(self, key): + def projectInfo(self, key): """ Retrieves the information associated with the given key. """ return QApplication.instance().project.info(key) - def _project(self): + def project(self): """ Returns the BProject instance. """ return QApplication.instance().project + + #### + + ## QSettings interaction methods ## + def settingsStore(self, key, value): + """ + Stores the given value in the QSettings associated with the given key. + """ + QApplication.instance().settings.setValue(QString(key), value) + + def settingsRetrieve(self, key): + """ + Retrieves the value associated to key in the QSettings. Note that this + Value is a QVariant and neet to be converted in a standard type. + """ + return QApplication.instance().settings.value(QString(key), QVariant()) + def versions(self): """ Returns the version list from the QSettings. """ - return qvariant_converter.getStringList(self._settingsRetrieve("versions")) + return qvariant_converter.getStringList(self.settingsRetrieve("versions")) def setVersions(self, versions): """ Stores the given versions in the QSettings. """ - self._settingsStore("versions", qvariant_converter.convertStringList(versions)) + self.settingsStore("versions", qvariant_converter.convertStringList(versions)) def searchDirList(self): """ Returns the search dir list from the QSettings. """ - return qvariant_converter.getStringList(self._settingsRetrieve("search_dir_list")) + return qvariant_converter.getStringList(self.settingsRetrieve("search_dir_list")) def setSearchDirList(self, search_dir_list): """ Stores the search dir list in the QSettings. """ - self._settingsStore("search_dir_list", qvariant_converter.convertStringList(search_dir_list)) + self.settingsStore("search_dir_list", qvariant_converter.convertStringList(search_dir_list)) def pathSearch(self): """ Returns the value of path search from the QSettings. """ - return qvariant_converter.getBool(self._settingsRetrieve("path_search")) + return qvariant_converter.getBool(self.settingsRetrieve("path_search")) def setPathSearch(self, path_search): """ Stores the path search value in the QSettings. """ - self._settingsStore("path_search", qvariant_converter.convertBool(path_search)) + self.settingsStore("path_search", qvariant_converter.convertBool(path_search)) def toolchains(self): """ Returns the toolchains stored in the QSettings. """ - return qvariant_converter.getBoolDict(self._settingsRetrieve("toolchains")) + return qvariant_converter.getBoolDict(self.settingsRetrieve("toolchains")) def setToolchains(self, toolchains): """ Stores the toolchains in the QSettings. """ - self._settingsStore("toolchains", qvariant_converter.convertBoolDict(toolchains)) + self.settingsStore("toolchains", qvariant_converter.convertBoolDict(toolchains)) + + #### + + ## Methodo to be implemented in child classes when needed ## def reloadData(self): """ @@ -120,3 +132,21 @@ class BWizardPage(QWizardPage): method have to implement it. """ pass + + def setupUi(self): + """ + Method called automatically during the initialization of the wizard page. + It set up the interface. Pages that need to use this method have to + implement it. + """ + pass + + def connectSignals(self): + """ + Method called automatically during the initialization of the wizard page. + It connects the signals and the slots. The pages that need to use this + method have to implement it. + """ + pass + + #### \ No newline at end of file diff --git a/wizard/test/testModulePage.py b/wizard/test/testModulePage.py index f91a27e6..0724669d 100644 --- a/wizard/test/testModulePage.py +++ b/wizard/test/testModulePage.py @@ -28,9 +28,9 @@ def main(): app = QApplication([]) app.project = BProject.BProject() page = BModulePage.BModulePage() - page._projectInfoStore("SOURCES_PATH", "../../") - page._projectInfoStore("CPU_INFOS", {"TOOLCHAIN": "avr", "CPU_TAGS": []}) - bertos_utils.loadSourceTree(page._project()) + page.setProjectInfo("SOURCES_PATH", "../../") + page.setProjectInfo("CPU_INFOS", {"TOOLCHAIN": "avr", "CPU_TAGS": []}) + bertos_utils.loadSourceTree(page.project()) page.reloadData() page.show() app.exec_()