4 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
9 # Author: Lorenzo Berni <duplo@develer.com>
14 from BWizardPage import *
15 import BToolchainSearch
17 if PYQT_VERSION_STR > "4.4.3":
18 import qvariant_converter_new as qvariant_converter
20 import qvariant_converter_old as qvariant_converter
22 class BToolchainPage(BWizardPage):
25 BWizardPage.__init__(self, "toolchain_select.ui")
26 self.setTitle(self.tr("Select toolchain"))
27 self._validationProcess = None
28 #self._populateToolchainList()
29 self._connectSignals()
32 if self.pageContent.customDirBox.isChecked():
33 self._enableCustomDir()
35 self._disableCustomDir()
36 if self.pageContent.pathBox.isChecked() or (self.pageContent.customDirBox.isChecked() and self.pageContent.customDirList.count() != 0):
37 self.pageContent.doSearchButton.setEnabled(True)
39 self.pageContent.doSearchButton.setEnabled(False)
41 def _populateToolchainList(self):
42 toolchains = self.toolchains()
43 for key, value in toolchains.items():
44 item = QListWidgetItem(key)
45 item.setData(Qt.UserRole, qvariant_converter.convertString(key))
46 self.pageContent.toolchainList.addItem(item)
48 self.validateToolchain(self.pageContent.toolchainList.row(item))
51 self.pageContent.toolchainList.clear()
53 def _selectionChanged(self):
54 self.emit(SIGNAL("completeChanged()"))
57 dirList = self.searchDirList()
58 if(self.pathSearch()):
59 dirList += [element for element in bertos_utils.getSystemPath()]
60 toolchainList = bertos_utils.findToolchains(dirList)
61 storedToolchains = self.toolchains()
62 for element in toolchainList:
63 if not element in storedToolchains.keys():
64 item = QListWidgetItem(element)
65 item.setData(Qt.UserRole, qvariant_converter.convertString(element))
66 self.pageContent.toolchainList.addItem(item)
67 storedToolchains[element] = False
68 self.setToolchains(storedToolchains)
70 def _connectSignals(self):
71 self.connect(self.pageContent.toolchainList, SIGNAL("itemSelectionChanged()"), self._selectionChanged)
72 self.connect(self.pageContent.addButton, SIGNAL("clicked()"), self.addToolchain)
73 self.connect(self.pageContent.removeButton, SIGNAL("clicked()"), self.removeToolchain)
74 self.connect(self.pageContent.searchButton, SIGNAL("clicked()"), self.searchToolchain)
75 self.connect(self.pageContent.checkButton, SIGNAL("clicked()"), self.validateAllToolchains)
77 def _validItem(self, index, infos):
78 item = self.pageContent.toolchainList.item(index)
79 needed = self._projectInfoRetrieve("CPU_INFOS")
80 if infos["target"].find(needed["TOOLCHAIN"]) != -1:
81 item.setIcon(QIcon(":/images/ok.png"))
83 item.setIcon(QIcon(":/images/warning.png"))
84 item.setText("GCC " + infos["version"] + " - " + infos["target"])
86 def _invalidItem(self, index):
87 item = self.pageContent.toolchainList.item(index)
88 item.setIcon(QIcon(":/images/error.png"))
90 def addToolchain(self):
91 sel_toolchain = QFileDialog.getOpenFileName(self, self.tr("Choose the toolchain"), "")
92 if not sel_toolchain.isEmpty():
93 item = QListWidgetItem(sel_toolchain)
94 item.setData(Qt.UserRole, qvariant_converter.convertString(sel_toolchain))
95 self.pageContent.toolchainList.addItem(item)
96 toolchains = self.toolchains()
97 toolchains[sel_toolchain] = False
98 self.setToolchains(toolchains)
100 def removeToolchain(self):
101 if self.pageContent.toolchainList.currentRow() != -1:
102 item = self.pageContent.toolchainList.takeItem(self.pageContent.toolchainList.currentRow())
103 toolchain = qvariant_converter.getString(item.data(Qt.UserRole))
104 toolchains = self.toolchains()
105 del toolchains[toolchain]
106 self.setToolchains(toolchains)
108 def searchToolchain(self):
109 search = BToolchainSearch.BToolchainSearch()
110 self.connect(search, SIGNAL("accepted()"), self._search)
113 def validateAllToolchains(self):
114 for i in range(self.pageContent.toolchainList.count()):
115 self.validateToolchain(i)
117 def validateToolchain(self, i):
118 filename = qvariant_converter.getString(self.pageContent.toolchainList.item(i).data(Qt.UserRole))
119 self._validationProcess = QProcess()
120 self._validationProcess.start(filename, ["-v"])
121 self._validationProcess.waitForStarted(1000)
122 if self._validationProcess.waitForFinished(200):
123 description = str(self._validationProcess.readAllStandardError())
124 infos = bertos_utils.getToolchainInfo(description)
125 if len(infos.keys()) >= 4:
126 self._validItem(i, infos)
130 self._validationProcess.kill()
132 toolchains = self.toolchains()
133 toolchains[filename] = True
134 self.setToolchains(toolchains)
136 def isComplete(self):
137 if self.pageContent.toolchainList.currentRow() != -1:
138 self._projectInfoStore("TOOLCHAIN",
139 qvariant_converter.getString(self.pageContent.toolchainList.item(self.pageContent.toolchainList.currentRow()).data(Qt.UserRole)))
144 def reloadData(self):
146 self._populateToolchainList()