From 2be5d4598fdfee024f3929a110f5f93c751c355c Mon Sep 17 00:00:00 2001 From: duplo Date: Tue, 30 Mar 2010 15:02:45 +0000 Subject: [PATCH] Add try/finally for every setOverrideCursor/restoreOverrideCursor. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3334 38d2e660-2303-0410-9eaa-f027e97ec537 --- wizard/BCpuPage.py | 26 ++++---- wizard/BEditingDialog.py | 48 ++++++++------- wizard/BFinalPage.py | 8 ++- wizard/BModulePage.py | 130 ++++++++++++++++++++------------------- wizard/BToolchainPage.py | 10 +-- 5 files changed, 119 insertions(+), 103 deletions(-) diff --git a/wizard/BCpuPage.py b/wizard/BCpuPage.py index 085b06e7..e9052e67 100644 --- a/wizard/BCpuPage.py +++ b/wizard/BCpuPage.py @@ -107,18 +107,20 @@ class BCpuPage(BWizardPage): """ Overload of the BWizardPage reloadData method. """ - QApplication.instance().setOverrideCursor(Qt.WaitCursor) - self.project().loadSourceTree() - self.populateCpuList() - cpu_name = self.projectInfo("CPU_NAME") - selected_freq = self.projectInfo("SELECTED_FREQ") - self.setupUi() - if cpu_name: - self.selectItem(cpu_name) - if selected_freq: - self.setFrequency(selected_freq) - self.freq_modified = True - QApplication.instance().restoreOverrideCursor() + try: + QApplication.instance().setOverrideCursor(Qt.WaitCursor) + self.project().loadSourceTree() + self.populateCpuList() + cpu_name = self.projectInfo("CPU_NAME") + selected_freq = self.projectInfo("SELECTED_FREQ") + self.setupUi() + if cpu_name: + self.selectItem(cpu_name) + if selected_freq: + self.setFrequency(selected_freq) + self.freq_modified = True + finally: + QApplication.instance().restoreOverrideCursor() self.emit(SIGNAL("completeChanged()")) #### diff --git a/wizard/BEditingDialog.py b/wizard/BEditingDialog.py index 825fb1c6..cc8a80aa 100644 --- a/wizard/BEditingDialog.py +++ b/wizard/BEditingDialog.py @@ -125,33 +125,37 @@ class BEditingDialog(QDialog): self.tr("Changing the BeRTOS version will destroy all the modification done on the BeRTOS sources"), QMessageBox.Ok | QMessageBox.Cancel ) == QMessageBox.Ok: - qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) - dialog.version_page.setProjectInfo("SOURCES_PATH", version) - dialog.version_page.setProjectInfo("OLD_SOURCES_PATH", current_version) - enabled_modules = bertos_utils.enabledModules(dialog.version_page.project()) - old_configuration = dialog.version_page.projectInfo("CONFIGURATIONS") - dialog.version_page.project().loadSourceTree() - bertos_utils.loadModuleData(dialog.version_page.project()) - new_configuration = dialog.version_page.projectInfo("CONFIGURATIONS") - merged_configuration = {} - for conf in new_configuration: - if conf in old_configuration: - configuration = bertos_utils.updateConfigurationValues(new_configuration[conf], old_configuration[conf]) - else: - configuration = new_configuration[conf] - merged_configuration[conf] = configuration - dialog.version_page.setProjectInfo("CONFIGURATIONS", merged_configuration) - bertos_utils.setEnabledModules(dialog.version_page.project(), enabled_modules) - self.module_page.fillModuleTree() - qApp.restoreOverrideCursor() + try: + qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) + dialog.version_page.setProjectInfo("SOURCES_PATH", version) + dialog.version_page.setProjectInfo("OLD_SOURCES_PATH", current_version) + enabled_modules = bertos_utils.enabledModules(dialog.version_page.project()) + old_configuration = dialog.version_page.projectInfo("CONFIGURATIONS") + dialog.version_page.project().loadSourceTree() + bertos_utils.loadModuleData(dialog.version_page.project()) + new_configuration = dialog.version_page.projectInfo("CONFIGURATIONS") + merged_configuration = {} + for conf in new_configuration: + if conf in old_configuration: + configuration = bertos_utils.updateConfigurationValues(new_configuration[conf], old_configuration[conf]) + else: + configuration = new_configuration[conf] + merged_configuration[conf] = configuration + dialog.version_page.setProjectInfo("CONFIGURATIONS", merged_configuration) + bertos_utils.setEnabledModules(dialog.version_page.project(), enabled_modules) + self.module_page.fillModuleTree() + finally: + qApp.restoreOverrideCursor() else: # Rollback version to the previous selected one. dialog.version_page.setProjectInfo("SOURCES_PATH", current_version) def apply(self): - qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) - createBertosProject(self.module_page.project(), edit=True) - qApp.restoreOverrideCursor() + try: + qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) + createBertosProject(self.module_page.project(), edit=True) + finally: + qApp.restoreOverrideCursor() self.accept() def toolchains(self): diff --git a/wizard/BFinalPage.py b/wizard/BFinalPage.py index 3f1a9e02..f5d353ed 100644 --- a/wizard/BFinalPage.py +++ b/wizard/BFinalPage.py @@ -57,9 +57,11 @@ class BFinalPage(BWizardPage): """ Overload of the BWizardPage reloadData method. """ - QApplication.instance().setOverrideCursor(Qt.WaitCursor) - bertos_utils.createBertosProject(self.project()) - QApplication.instance().restoreOverrideCursor() + try: + QApplication.instance().setOverrideCursor(Qt.WaitCursor) + bertos_utils.createBertosProject(self.project()) + finally: + QApplication.instance().restoreOverrideCursor() self._plugin_dict = {} if os.name == "nt": output = self.projectInfo("OUTPUT") diff --git a/wizard/BModulePage.py b/wizard/BModulePage.py index 4eb9a55e..3d7fa2fc 100644 --- a/wizard/BModulePage.py +++ b/wizard/BModulePage.py @@ -86,11 +86,13 @@ class BModulePage(BWizardPage): """ Overload of the BWizardPage reloadData method. """ - QApplication.instance().setOverrideCursor(Qt.WaitCursor) - self.setupUi() - self.loadModuleData() - self.fillModuleTree() - QApplication.instance().restoreOverrideCursor() + try: + QApplication.instance().setOverrideCursor(Qt.WaitCursor) + self.setupUi() + self.loadModuleData() + self.fillModuleTree() + finally: + QApplication.instance().restoreOverrideCursor() #### @@ -402,70 +404,74 @@ class BModulePage(BWizardPage): """ Resolves the selection dependencies. """ - 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) - qApp.restoreOverrideCursor() - - def moduleUnselected(self, unselectedModule): - """ - Resolves the unselection dependencies. - """ - 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) + try: qApp.setOverrideCursor(Qt.WaitCursor) - if choice == QMessageBox.Yes: + 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"] = False + 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: - item.child(child).setCheckState(0, Qt.Unchecked) - 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) + 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) + for child in range(item.childCount()): + if unicode(item.child(child).text(0)) in unsatisfied: + item.child(child).setCheckState(0, Qt.Unchecked) + 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): diff --git a/wizard/BToolchainPage.py b/wizard/BToolchainPage.py index 6239a1d9..88be219e 100644 --- a/wizard/BToolchainPage.py +++ b/wizard/BToolchainPage.py @@ -155,10 +155,12 @@ class BToolchainPage(BWizardPage): 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() + try: + QApplication.instance().setOverrideCursor(Qt.WaitCursor) + for i in range(self.pageContent.toolchainList.count()): + self.validateToolchain(i) + finally: + QApplication.instance().restoreOverrideCursor() #### -- 2.25.1