4 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
9 # Author: Lorenzo Berni <duplo@develer.com>
15 from BWizardPage import *
16 import BToolchainSearch
18 import qvariant_converter
22 class BToolchainPage(BWizardPage):
24 Page of the wizard that permits to choose the toolchain to use for the
29 BWizardPage.__init__(self, UI_LOCATION + "/toolchain_select.ui")
30 self.setTitle(self.tr("Select toolchain"))
31 self._validation_process = None
32 self._valid_items = []
34 ## Overloaded QWizardPage methods. ##
38 Overload of the QWizard isComplete method.
40 if self.pageContent.toolchainList.currentRow() != -1:
41 self.setProjectInfo("TOOLCHAIN",
42 qvariant_converter.getStringDict(self.pageContent.toolchainList.currentItem().data(Qt.UserRole)))
49 ## Overloaded BWizardPage methods. ##
53 Sets up the user interface.
55 self.pageContent.infoLabel.setVisible(False)
57 def connectSignals(self):
59 Connects the signals with the related slots.
61 self.connect(self.pageContent.toolchainList, SIGNAL("itemSelectionChanged()"), self.selectionChanged)
62 self.connect(self.pageContent.addButton, SIGNAL("clicked()"), self.addToolchain)
63 self.connect(self.pageContent.removeButton, SIGNAL("clicked()"), self.removeToolchain)
64 self.connect(self.pageContent.searchButton, SIGNAL("clicked()"), self.searchToolchain)
65 self.connect(self.pageContent.checkButton, SIGNAL("clicked()"), self.validateAllToolchains)
69 Overload of the BWizard reloadData method.
73 self._populateToolchainList()
74 if len(self._valid_items) == 1:
75 self.pageContent.toolchainList.setCurrentItem(self._valid_items[0])
81 def selectionChanged(self):
83 Slot called when the user click on an entry of the toolchain list.
85 if self.pageContent.toolchainList.currentRow() != -1:
86 infos = collections.defaultdict(lambda: unicode("not defined"))
87 infos.update(qvariant_converter.getStringDict(self.pageContent.toolchainList.currentItem().data(Qt.UserRole)))
88 self.pageContent.infoLabel.setText("GCC " + infos["version"] + " (" + infos["build"] + ")\nTarget: " + infos["target"] + "\nPath: " + os.path.normpath(infos["path"]))
89 self.pageContent.infoLabel.setVisible(True)
90 if self.isDefaultToolchain(infos):
91 self.disableRemoveButton()
93 self.enableRemoveButton()
94 self.emit(SIGNAL("completeChanged()"))
96 def addToolchain(self):
98 Slot called when the user adds manually a toolchain.
100 sel_toolchain = unicode(QFileDialog.getOpenFileName(self, self.tr("Choose the toolchain"), ""))
101 if sel_toolchain != "":
102 item = QListWidgetItem(sel_toolchain)
103 item.setData(Qt.UserRole, qvariant_converter.convertStringDict({"path": sel_toolchain}))
104 self.pageContent.toolchainList.addItem(item)
105 toolchains = self.toolchains()
106 toolchains[sel_toolchain] = False
107 self.setToolchains(toolchains)
109 def removeToolchain(self):
111 Slot called when the user removes manually a toolchain.
113 if self.pageContent.toolchainList.currentRow() != -1:
114 item = self.pageContent.toolchainList.takeItem(self.pageContent.toolchainList.currentRow())
115 toolchain = qvariant_converter.getStringDict(item.data(Qt.UserRole))["path"]
116 toolchains = self.toolchains()
117 del toolchains[toolchain]
118 self.setToolchains(toolchains)
120 def searchToolchain(self):
122 Slot called when the user clicks on the 'search' button. It opens the
123 toolchain search dialog.
125 search = BToolchainSearch.BToolchainSearch()
126 self.connect(search, SIGNAL("accepted()"), self._search)
129 def validateAllToolchains(self):
131 Slot called when the user clicks on the validate button. It starts the
132 toolchain validation procedure for all the toolchains.
134 QApplication.instance().setOverrideCursor(Qt.WaitCursor)
135 for i in range(self.pageContent.toolchainList.count()):
136 self.validateToolchain(i)
137 QApplication.instance().restoreOverrideCursor()
141 def _populateToolchainList(self):
143 Fills the toolchain list with the toolchains stored in the QSettings.
145 toolchains = self.toolchains()
147 import winreg_importer
148 stored_toolchains = winreg_importer.getBertosToolchains()
149 for toolchain in stored_toolchains:
150 toolchains[toolchain] = True
151 sel_toolchain = self.projectInfo("TOOLCHAIN")
152 for key, value in toolchains.items():
153 item = QListWidgetItem(key)
154 item.setData(Qt.UserRole, qvariant_converter.convertStringDict({"path": key}))
155 self.pageContent.toolchainList.addItem(item)
156 if sel_toolchain and sel_toolchain["path"] == key:
157 self.pageContent.toolchainList.setCurrentItem(item)
159 self.validateToolchain(self.pageContent.toolchainList.row(item))
161 def _clearList(self):
163 Removes all the toolchain from the list.
165 self.pageContent.toolchainList.clear()
169 Searches for toolchains in the stored directories, and stores them in the
172 dir_list = self.searchDirList()
173 if self.pathSearch():
174 dir_list += [element for element in bertos_utils.getSystemPath()]
175 toolchain_list = bertos_utils.findToolchains(dir_list)
176 stored_toolchains = self.toolchains()
177 for element in toolchain_list:
178 if not element in stored_toolchains:
179 item = QListWidgetItem(element)
180 item.setData(Qt.UserRole, qvariant_converter.convertStringDict({"path": element}))
181 self.pageContent.toolchainList.addItem(item)
182 stored_toolchains[element] = False
183 self.setToolchains(stored_toolchains)
184 self.showMessage(self.tr("Toolchain search result."), self.tr("%1 toolchains founded").arg(len(stored_toolchains)))
186 def _validItem(self, index, infos):
188 Sets the item at index as a valid item and associates the given info to it.
190 item = self.pageContent.toolchainList.item(index)
191 new_data = qvariant_converter.getStringDict(self.pageContent.toolchainList.item(index).data(Qt.UserRole))
192 new_data.update(infos)
193 item.setData(Qt.UserRole, qvariant_converter.convertStringDict(new_data))
194 needed = self.projectInfo("CPU_INFOS")
195 if "target" in infos and infos["target"].find(needed["TOOLCHAIN"]) != -1:
196 item.setIcon(QIcon(":/images/ok.png"))
197 self._valid_items.append(item)
199 item.setIcon(QIcon(":/images/warning.png"))
200 if "version" in infos and "target" in infos:
201 item.setText("GCC " + infos["version"] + " - " + infos["target"].strip())
203 def _invalidItem(self, index):
205 Sets the item at index as an invalid item.
207 item = self.pageContent.toolchainList.item(index)
208 item.setIcon(QIcon(":/images/error.png"))
210 def validateToolchain(self, i):
212 Toolchain validation procedure.
214 filename = qvariant_converter.getStringDict(self.pageContent.toolchainList.item(i).data(Qt.UserRole))["path"]
217 # Check for the other tools of the toolchain
218 for tool in TOOLCHAIN_ITEMS:
219 if os.path.exists(filename.replace("gcc", tool)):
224 # Try to retrieve the informations about the toolchain only for the valid toolchains
226 self._validation_process = QProcess()
227 self._validation_process.start(filename, ["-v"])
228 self._validation_process.waitForStarted(1000)
229 if self._validation_process.waitForFinished(200):
230 description = str(self._validation_process.readAllStandardError())
231 info = bertos_utils.getToolchainInfo(description)
235 self._validation_process.kill()
236 # Add the item in the list with the appropriate associate data.
238 self._validItem(i, info)
241 toolchains = self.toolchains()
242 toolchains[filename] = True
243 self.setToolchains(toolchains)
245 def isDefaultToolchain(self, toolchain):
247 Returns True if the given toolchain is one of the default toolchains.
250 import winreg_importer
251 stored_toolchains = winreg_importer.getBertosToolchains()
252 if toolchain["path"] in stored_toolchains:
256 def disableRemoveButton(self):
258 Disable the remove button.
260 self.pageContent.removeButton.setEnabled(False)
262 def enableRemoveButton(self):
264 Enable the remove button.
266 self.pageContent.removeButton.setEnabled(True)