From b1ba8881d40708e05b49ae5e42661a53c149c26c Mon Sep 17 00:00:00 2001 From: duplo Date: Fri, 9 Jan 2009 15:49:48 +0000 Subject: [PATCH] Hide QVariant from the ui implementation, and make a refactoring of the validation process git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2152 38d2e660-2303-0410-9eaa-f027e97ec537 --- wizard/BToolchainPage.py | 73 +++++++++++++++++++++--------------- wizard/BToolchainSearch.py | 8 ++-- wizard/BWizardPage.py | 4 +- wizard/bertos_utils.py | 4 +- wizard/qvariant_converter.py | 12 ++++++ 5 files changed, 64 insertions(+), 37 deletions(-) diff --git a/wizard/BToolchainPage.py b/wizard/BToolchainPage.py index d9ea7687..2383c393 100644 --- a/wizard/BToolchainPage.py +++ b/wizard/BToolchainPage.py @@ -22,7 +22,7 @@ class BToolchainPage(BWizardPage): BWizardPage.__init__(self, "toolchain_select.ui") self.setTitle(self.tr("Select toolchain")) self._validationProcess = None - self._populateToolchainList() + #self._populateToolchainList() self._connectSignals() def _updateUi(self): @@ -37,11 +37,13 @@ class BToolchainPage(BWizardPage): def _populateToolchainList(self): toolchains = self.toolchains() - for element in toolchains: - item = QListWidgetItem(element) - item.setData(Qt.UserRole, qvariant_converter.convertString(element)) + for key, value in toolchains.items(): + item = QListWidgetItem(key) + item.setData(Qt.UserRole, qvariant_converter.convertString(key)) self.pageContent.toolchainList.addItem(item) - + if value: + self.validateToolchain(self.pageContent.toolchainList.row(item)) + def _clearList(self): self.pageContent.toolchainList.clear() @@ -53,20 +55,21 @@ class BToolchainPage(BWizardPage): if(self.pathSearch()): dirList += [element for element in bertos_utils.getSystemPath()] toolchainList = bertos_utils.findToolchains(dirList) - storedToolchainList = self.toolchains() - toolchainList = set(toolchainList) - set(storedToolchainList) + storedToolchains = self.toolchains() for element in toolchainList: - item = QListWidgetItem(element) - item.setData(Qt.UserRole, qvariant_converter.convertString(element)) - self.pageContent.toolchainList.addItem(item) - self.setToolchains(list(toolchainList.union(storedToolchainList))) + if not element in storedToolchains.keys(): + item = QListWidgetItem(element) + item.setData(Qt.UserRole, qvariant_converter.convertString(element)) + self.pageContent.toolchainList.addItem(item) + storedToolchains[element] = False + self.setToolchains(storedToolchains) def _connectSignals(self): 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.validateToolchains) + self.connect(self.pageContent.checkButton, SIGNAL("clicked()"), self.validateAllToolchains) def _validItem(self, index, infos): item = self.pageContent.toolchainList.item(index) @@ -75,7 +78,7 @@ class BToolchainPage(BWizardPage): item.setIcon(QIcon(":/images/ok.png")) else: item.setIcon(QIcon(":/images/warning.png")) - item.setText("GCC " + infos["version"] + " " + infos["target"]) + item.setText("GCC " + infos["version"] + " - " + infos["target"]) def _invalidItem(self, index): item = self.pageContent.toolchainList.item(index) @@ -88,15 +91,15 @@ class BToolchainPage(BWizardPage): item.setData(Qt.UserRole, qvariant_converter.convertString(sel_toolchain)) self.pageContent.toolchainList.addItem(item) toolchains = self.toolchains() - toolchains = set(toolchains + [sel_toolchain]) - self.setToolchains(list(toolchains)) + toolchains[sel_toolchain] = False + self.setToolchains(toolchains) def removeToolchain(self): if self.pageContent.toolchainList.currentRow() != -1: item = self.pageContent.toolchainList.takeItem(self.pageContent.toolchainList.currentRow()) toolchain = qvariant_converter.getString(item.data(Qt.UserRole)) toolchains = self.toolchains() - toolchains.remove(toolchain) + del toolchains[toolchain] self.setToolchains(toolchains) def searchToolchain(self): @@ -104,22 +107,28 @@ class BToolchainPage(BWizardPage): self.connect(search, SIGNAL("accepted()"), self._search) search.exec_() - def validateToolchains(self): + def validateAllToolchains(self): for i in range(self.pageContent.toolchainList.count()): - filename = qvariant_converter.getString(self.pageContent.toolchainList.item(i).data(Qt.UserRole)) - self._validationProcess = QProcess() - self._validationProcess.start(filename, ["-v"]) - self._validationProcess.waitForStarted(1000) - if self._validationProcess.waitForFinished(200): - description = str(self._validationProcess.readAllStandardError()) - infos = bertos_utils.getToolchainInfo(description) - if len(infos.keys()) >= 4: - self._validItem(i, infos) - else: - self._invalidItem(i) + self.validateToolchain(i) + + def validateToolchain(self, i): + filename = qvariant_converter.getString(self.pageContent.toolchainList.item(i).data(Qt.UserRole)) + self._validationProcess = QProcess() + self._validationProcess.start(filename, ["-v"]) + self._validationProcess.waitForStarted(1000) + if self._validationProcess.waitForFinished(200): + description = str(self._validationProcess.readAllStandardError()) + infos = bertos_utils.getToolchainInfo(description) + if len(infos.keys()) >= 4: + self._validItem(i, infos) else: - self._validationProcess.kill() self._invalidItem(i) + else: + self._validationProcess.kill() + self._invalidItem(i) + toolchains = self.toolchains() + toolchains[filename] = True + self.setToolchains(toolchains) def isComplete(self): if self.pageContent.toolchainList.currentRow() != -1: @@ -127,4 +136,8 @@ class BToolchainPage(BWizardPage): qvariant_converter.getString(self.pageContent.toolchainList.item(self.pageContent.toolchainList.currentRow()).data(Qt.UserRole))) return True else: - return False \ No newline at end of file + return False + + def reloadData(self): + self._clearList() + self._populateToolchainList() \ No newline at end of file diff --git a/wizard/BToolchainSearch.py b/wizard/BToolchainSearch.py index b568dea2..c2f57e34 100644 --- a/wizard/BToolchainSearch.py +++ b/wizard/BToolchainSearch.py @@ -63,9 +63,9 @@ class BToolchainSearch(QDialog): directory = unicode(directory) item = QListWidgetItem(directory) self.content.customDirList.addItem(item) - search_dir_list = qvariant_conveter.getStringList(QApplication.instance().settings.value("search_dir_list")) + search_dir_list = qvariant_converter.getStringList(QApplication.instance().settings.value("search_dir_list")) search_dir_list = set(search_dir_list + [directory]) - QApplication.instance().settings.setValue(QString("search_dir_list"), QVariant(list(search_dir_list))) + QApplication.instance().settings.setValue(QString("search_dir_list"), convertStringList(list(search_dir_list))) self._setSearchButton() def _removeDir(self): @@ -73,7 +73,7 @@ class BToolchainSearch(QDialog): item = self.content.customDirList.takeItem(self.content.customDirList.currentRow()) search_dir_list = qvariant_converter.getStringList(QApplication.instance().settings.value(QString("search_dir_list"))) search_dir_list = set(search_dir_list) - search_dir_list.remove(item.text()) - QApplication.instance().settings.setValue(QString("search_dir_list"), QVariant(list(search_dir_list))) + search_dir_list.remove(unicode(item.text())) + QApplication.instance().settings.setValue(QString("search_dir_list"), qvariant_converter.convertStringList(list(search_dir_list))) self._setSearchButton() \ No newline at end of file diff --git a/wizard/BWizardPage.py b/wizard/BWizardPage.py index 5e5569ab..b4fc6217 100644 --- a/wizard/BWizardPage.py +++ b/wizard/BWizardPage.py @@ -55,10 +55,10 @@ class BWizardPage(QWizardPage): self._settingsStore("path_search", qvariant_converter.convertBool(path_search)) def toolchains(self): - return qvariant_converter.getStringList(self._settingsRetrieve("toolchains")) + return qvariant_converter.getBoolDict(self._settingsRetrieve("toolchains")) def setToolchains(self, toolchains): - self._settingsStore("toolchains", qvariant_converter.convertStringList(toolchains)) + self._settingsStore("toolchains", qvariant_converter.convertBoolDict(toolchains)) def reloadData(self): pass \ No newline at end of file diff --git a/wizard/bertos_utils.py b/wizard/bertos_utils.py index 3af061ef..89998949 100644 --- a/wizard/bertos_utils.py +++ b/wizard/bertos_utils.py @@ -38,7 +38,9 @@ def getSystemPath(): def findToolchains(pathList): toolchains = [] for element in pathList: - toolchains += glob.glob(element+ "/" + const.GCC_NAME) + for toolchain in glob.glob(element+ "/" + const.GCC_NAME): + if not os.path.islink(toolchain): + toolchains.append(toolchain) return toolchains def getToolchainInfo(output): diff --git a/wizard/qvariant_converter.py b/wizard/qvariant_converter.py index c0c5431e..9e3b3ed8 100644 --- a/wizard/qvariant_converter.py +++ b/wizard/qvariant_converter.py @@ -43,6 +43,18 @@ def getBool(qvariant): def convertBool(boolean): return QVariant(boolean) +def getBoolDict(qvariant): + dict_str_bool = {} + for key, value in qvariant.toMap().items(): + dict_str_bool[unicode(key)] = value.toBool() + return dict_str_bool + +def convertBoolDict(dict_str_bool): + result_dict = {} + for key, value in dict_str_bool.items(): + result_dict[QString(key)] = value + return QVariant(result_dict) + def getDict(qvariant): dict_str_variant = {} for key, value in qvariant.toMap().items(): -- 2.25.1