Remove the QVariant -> python type conversion from the application
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 8 Jan 2009 14:21:05 +0000 (14:21 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 8 Jan 2009 14:21:05 +0000 (14:21 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2141 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/BCpuPage.py
wizard/BToolchainPage.py
wizard/BToolchainSearch.py
wizard/BVersionPage.py

index f35790b8bb7257cda82110546f671fe6db921bed..0787bc344b545bbbfe8db2771adcf40fce579508 100644 (file)
@@ -12,6 +12,7 @@
 
 from BWizardPage import *
 import bertos_utils
+import qvariant_converter
 
 class BCpuPage(BWizardPage):
     
@@ -54,17 +55,14 @@ class BCpuPage(BWizardPage):
     
     def isComplete(self):
         if self.pageContent.cpuList.currentRow() != -1:
-            self._projectInfoStore("CPU_INFOS", self.pageContent.cpuList.currentItem().data(Qt.UserRole).toMap())
+            self._projectInfoStore("CPU_INFOS", qvariant_converter.getStringDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole)))
             return True
         else:
             return False
         
     def rowChanged(self):
-        description = self.pageContent.cpuList.currentItem().data(Qt.UserRole).toMap()
-        # I don't like to use QString as key in the dict, but the QVariant.toMap() return a dict<QString,QVariant>
-        description =  description[QString("CPU_DESC")].toStringList()
-        # We need to convert the list of QString in a list of unicode
-        description = [unicode(line) for line in description]
+        description = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole))["CPU_DESC"]
+        description = qvariant_converter.getStringList(description)
         self.pageContent.descriptionLabel.setText("<br>".join(description))
         self.pageContent.descriptionLabel.setVisible(True)
         self.emit(SIGNAL("completeChanged()"))
index 567fbcee11e0f3b2607b1a7ce1ef4651d66efc2e..346eb6480051c346ac31e966ff03b6e2a259c64b 100644 (file)
@@ -14,6 +14,7 @@ import os
 from BWizardPage import *
 import BToolchainSearch
 import bertos_utils
+import qvariant_converter
 
 class BToolchainPage(BWizardPage):
     
@@ -35,10 +36,10 @@ class BToolchainPage(BWizardPage):
             self.pageContent.doSearchButton.setEnabled(False)
     
     def _populateToolchainList(self):
-        toolchains = self._settingsRetrieve("toolchains").toList()
+        toolchains = qvariant_converter.getStringList(self._settingsRetrieve("toolchains"))
         for element in toolchains:
-            item = QListWidgetItem(element.toString())
-            item.setData(Qt.UserRole, element)
+            item = QListWidgetItem(element)
+            item.setData(Qt.UserRole, QVariant(element))
             self.pageContent.toolchainList.addItem(item)
             
     def _clearList(self):
@@ -48,13 +49,12 @@ class BToolchainPage(BWizardPage):
         self.emit(SIGNAL("completeChanged()"))
     
     def _search(self):
-        dirList = [unicode(element.toString()) for element in self._settingsRetrieve("search_dir_list").toList()]
-        if(self._settingsRetrieve("path_search").toBool()):
+        dirList = qvariant_converter.getStringList(self._settingsRetrieve("search_dir_list"))
+        if(qvariant_converter.getBool(self._settingsRetrieve("path_search"))):
             dirList += [element for element in bertos_utils.getSystemPath()]
         toolchainList = bertos_utils.findToolchains(dirList)
-        storedToolchainList = self._settingsRetrieve("toolchains").toList()
-        storedToolchainList = set([unicode(toolchain.toString()) for toolchain in storedToolchainList])
-        toolchainList =set(toolchainList) - set(storedToolchainList)
+        storedToolchainList = qvariant_converter.getStringList(self._settingsRetrieve("toolchains"))
+        toolchainList = set(toolchainList) - set(storedToolchainList)
         for element in toolchainList:
             item = QListWidgetItem(element)
             item.setData(Qt.UserRole, QVariant(element))
@@ -71,7 +71,7 @@ class BToolchainPage(BWizardPage):
     def _validItem(self, index, infos):
         item = self.pageContent.toolchainList.item(index)
         needed = self._projectInfoRetrieve("CPU_INFOS")
-        if infos["target"].find(unicode(needed[QString("TOOLCHAIN")].toString())) != -1:
+        if infos["target"].find(needed["TOOLCHAIN"]) != -1:
             item.setIcon(QIcon(":/images/ok.png"))
         else:
             item.setIcon(QIcon(":/images/warning.png"))
@@ -87,17 +87,16 @@ class BToolchainPage(BWizardPage):
             item = QListWidgetItem(sel_toolchain)
             item.setData(Qt.UserRole, QVariant(sel_toolchain))
             self.pageContent.toolchainList.addItem(item)
-            toolchains = self._settingsRetrieve("toolchains").toList()
-            toolchains = set([toolchain.toString() for toolchain in toolchains] + [sel_toolchain])
+            toolchains = qvariant_convert.getStringList(self._settingsRetrieve("toolchains"))
+            toolchains = set(toolchains + [sel_toolchain])
             self._settingsStore("toolchains", list(toolchains))
     
     def removeToolchain(self):
         if self.pageContent.toolchainList.currentRow() != -1:
             item = self.pageContent.toolchainList.takeItem(self.pageContent.toolchainList.currentRow())
-            item = item.data(Qt.UserRole).toString()
-            toolchains = self._settingsRetrieve("toolchains").toList()
-            toolchains = [unicode(toolchain.toString()) for toolchain in toolchains]
-            toolchains.remove(unicode(item))
+            toolchain = qvariant_converter.getString(item.data(Qt.UserRole))
+            toolchains = qvariant_converter.getStringList(self._settingsRetrieve("toolchains"))
+            toolchains.remove(toolchain)
             self._settingsStore("toolchains", toolchains)
     
     def searchToolchain(self):
@@ -107,7 +106,7 @@ class BToolchainPage(BWizardPage):
     
     def validateToolchains(self):
         for i in range(self.pageContent.toolchainList.count()):
-            filename = unicode(self.pageContent.toolchainList.item(i).data(Qt.UserRole).toString())
+            filename = qvariant_converter.getString(self.pageContent.toolchainList.item(i).data(Qt.UserRole))
             self._validationProcess = QProcess()
             self._validationProcess.start(filename, ["-v"])
             self._validationProcess.waitForStarted(1000)
@@ -124,7 +123,8 @@ class BToolchainPage(BWizardPage):
     
     def isComplete(self):
         if self.pageContent.toolchainList.currentRow() != -1:
-            self._projectInfoStore("TOOLCHAIN", self.pageContent.toolchainList.item(self.pageContent.toolchainList.currentRow()).data(Qt.UserRole).toString())
+            self._projectInfoStore("TOOLCHAIN", 
+                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
index 614eddff682fb725e05677acc13dd246f77b36be..b568dea235766e8be89fab9d2a4e89ff0381bd29 100644 (file)
@@ -13,6 +13,8 @@ from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 import PyQt4.uic as uic
 
+import qvariant_converter
+
 class BToolchainSearch(QDialog):
     
     def __init__(self):
@@ -42,13 +44,13 @@ class BToolchainSearch(QDialog):
         self.content.searchButton.setEnabled(self.content.pathBox.isChecked() or self.content.customDirList.count() != 0)
     
     def _populateDirList(self):
-        search_dir_list = QApplication.instance().settings.value(QString("search_dir_list")).toList()
+        search_dir_list = qvariant_converter.getStringList(QApplication.instance().settings.value("search_dir_list"))
         for element in search_dir_list:
-            item = QListWidgetItem(unicode(element.toString()))
+            item = QListWidgetItem(element)
             self.content.customDirList.addItem(item)
     
     def _setPathSearch(self):
-        pathSearch = QApplication.instance().settings.value(QString("path_search")).toBool()
+        pathSearch = qvariant_converter.getBool(QApplication.instance().settings.value(QString("path_search")))
         self.content.pathBox.setChecked(pathSearch)
     
     def _stateChanged(self, state):
@@ -58,18 +60,19 @@ class BToolchainSearch(QDialog):
     def _addDir(self):
         directory = QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), "", QFileDialog.ShowDirsOnly)
         if not directory.isEmpty():
+            directory = unicode(directory)
             item = QListWidgetItem(directory)
             self.content.customDirList.addItem(item)
-            search_dir_list = QApplication.instance().settings.value(QString("search_dir_list")).toList()
-            search_dir_list = set([d.toString() for d in search_dir_list] + [directory])
+            search_dir_list = qvariant_conveter.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)))
             self._setSearchButton()
     
     def _removeDir(self):
         if self.content.customDirList.currentRow() != -1:
             item = self.content.customDirList.takeItem(self.content.customDirList.currentRow())
-            search_dir_list = QApplication.instance().settings.value(QString("search_dir_list")).toList()
-            search_dir_list = set([d.toString() for d in search_dir_list])
+            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)))
             self._setSearchButton()
index c9212332de0a3cb0c8026690c1afab748834e4f6..129a5bf1dd8e71764405d20453a96df348c3d083 100644 (file)
@@ -12,6 +12,7 @@
 from PyQt4.QtGui import *
 from BWizardPage import *
 import bertos_utils
+import qvariant_converter
 
 class BVersionPage(BWizardPage):
     
@@ -33,13 +34,12 @@ class BVersionPage(BWizardPage):
         self.pageContent.versionList.setCurrentRow(-1)
     
     def _storeVersion(self, directory):
-        versions = self._settingsRetrieve("versions").toList()
-        versions = set([x.toString() for x in versions] + [directory])
+        versions = qvariant_converter.getStringList(self._settingsRetrieve("versions"))
+        versions = set(versions + [directory])
         self._settingsStore("versions", list(versions))
     
     def _deleteVersion(self, directory):
-        versions = self._settingsRetrieve(QString("versions")).toList()
-        versions = [x.toString() for x in versions]
+        versions = qvariant_converter.getStringList(self._settingsRetrieve("versions"))
         versions.remove(directory)
         self._settingsStore("versions", versions)
         
@@ -48,19 +48,19 @@ class BVersionPage(BWizardPage):
             item = QListWidgetItem(QIcon(":/images/ok.png"), bertos_utils.bertosVersion(directory) + " (\"" + directory + "\")")
             item.setData(Qt.UserRole, QVariant(directory))
             self.pageContent.versionList.addItem(item)
-        elif not directory.isEmpty():
+        elif len(directory) > 0:
             item = QListWidgetItem(QIcon(":/images/warning.png"), "UNKNOWN" + " (\"" + directory + "\")")
             item.setData(Qt.UserRole, QVariant(directory))
             self.pageContent.versionList.addItem(item)
     
     def _fillVersionList(self):
-        versions = self._settingsRetrieve("versions").toList()
+        versions = qvariant_converter.getStringList(self._settingsRetrieve("versions"))
         for directory in versions:
-            self._insertListElement(directory.toString())
+            self._insertListElement(directory)
 
     def isComplete(self):
         if self.pageContent.versionList.currentRow() != -1:
-            self._projectInfoStore("SOURCES_PATH", unicode(self.pageContent.versionList.currentItem().data(Qt.UserRole).toString()))
+            self._projectInfoStore("SOURCES_PATH", qvariant_converter.getString(self.pageContent.versionList.currentItem().data(Qt.UserRole)))
             return True
         else:
             return False
@@ -68,14 +68,14 @@ class BVersionPage(BWizardPage):
     def addVersion(self):
         directory = QFileDialog.getExistingDirectory(self, self.tr("Choose a directory"), "", QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks)
         if not directory.isEmpty():
-            self._storeVersion(directory)
+            self._storeVersion(unicode(directory))
             self.pageContent.versionList.clear()
             self._fillVersionList()
             self.emit(SIGNAL("completeChanged()"))
     
     def removeVersion(self):
         item = self.pageContent.versionList.takeItem(self.pageContent.versionList.currentRow())
-        self._deleteVersion(item.data(Qt.UserRole).toString())
+        self._deleteVersion(qvariant_converter.getString(item.data(Qt.UserRole)))
         self.emit(SIGNAL("completeChanged()"))
     
     def updateClicked(self):