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
33 #self._populateToolchainList()
34 self._connectSignals()
38 Sets up the user interface.
40 self.pageContent.infoLabel.setVisible(False)
42 def _populateToolchainList(self):
44 Fills the toolchain list with the toolchains stored in the QSettings.
46 toolchains = self.toolchains()
47 sel_toolchain = self._projectInfoRetrieve("TOOLCHAIN")
48 for key, value in toolchains.items():
49 item = QListWidgetItem(key)
50 item.setData(Qt.UserRole, qvariant_converter.convertStringDict({"path": key}))
51 self.pageContent.toolchainList.addItem(item)
52 if sel_toolchain is not None and sel_toolchain["path"] == key:
53 self.pageContent.toolchainList.setCurrentItem(item)
55 self.validateToolchain(self.pageContent.toolchainList.row(item))
59 Removes all the toolchain from the list.
61 self.pageContent.toolchainList.clear()
63 def _selectionChanged(self):
65 Slot called when the user click on an entry of the toolchain list.
67 if self.pageContent.toolchainList.currentRow() != -1:
68 infos = collections.defaultdict(lambda: unicode("not defined"))
69 infos.update(qvariant_converter.getStringDict(self.pageContent.toolchainList.currentItem().data(Qt.UserRole)))
70 self.pageContent.infoLabel.setText("GCC " + infos["version"] + " (" + infos["build"] + ")\nTarget: " + infos["target"] + "\nPath: " + os.path.normpath(infos["path"]))
71 self.pageContent.infoLabel.setVisible(True)
72 self.emit(SIGNAL("completeChanged()"))
76 Searches for toolchains in the stored directories, and stores them in the
79 dir_list = self.searchDirList()
81 dir_list += [element for element in bertos_utils.getSystemPath()]
82 toolchain_list = bertos_utils.findToolchains(dir_list)
83 stored_toolchains = self.toolchains()
84 for element in toolchain_list:
85 if not element in stored_toolchains.keys():
86 item = QListWidgetItem(element)
87 item.setData(Qt.UserRole, qvariant_converter.convertStringDict({"path": element}))
88 self.pageContent.toolchainList.addItem(item)
89 stored_toolchains[element] = False
90 self.setToolchains(stored_toolchains)
92 def _connectSignals(self):
94 Connects the signals with the related slots.
96 self.connect(self.pageContent.toolchainList, SIGNAL("itemSelectionChanged()"), self._selectionChanged)
97 self.connect(self.pageContent.addButton, SIGNAL("clicked()"), self.addToolchain)
98 self.connect(self.pageContent.removeButton, SIGNAL("clicked()"), self.removeToolchain)
99 self.connect(self.pageContent.searchButton, SIGNAL("clicked()"), self.searchToolchain)
100 self.connect(self.pageContent.checkButton, SIGNAL("clicked()"), self.validateAllToolchains)
102 def _validItem(self, index, infos):
104 Sets the item at index as a valid item and associates the given info to it.
106 item = self.pageContent.toolchainList.item(index)
107 new_data = qvariant_converter.getStringDict(self.pageContent.toolchainList.item(index).data(Qt.UserRole))
108 new_data.update(infos)
109 item.setData(Qt.UserRole, qvariant_converter.convertStringDict(new_data))
110 needed = self._projectInfoRetrieve("CPU_INFOS")
111 if "target" in infos.keys() and infos["target"].find(needed["TOOLCHAIN"]) != -1:
112 item.setIcon(QIcon(":/images/ok.png"))
114 item.setIcon(QIcon(":/images/warning.png"))
115 if "version" in infos.keys() and "target" in infos.keys():
116 item.setText("GCC " + infos["version"] + " - " + infos["target"])
118 def _invalidItem(self, index):
120 Sets the item at index as an invalid item.
122 item = self.pageContent.toolchainList.item(index)
123 item.setIcon(QIcon(":/images/error.png"))
125 def addToolchain(self):
127 Slot called when the user adds manually a toolchain.
129 sel_toolchain = QFileDialog.getOpenFileName(self, self.tr("Choose the toolchain"), "")
130 if not sel_toolchain.isEmpty():
131 item = QListWidgetItem(sel_toolchain)
132 item.setData(Qt.UserRole, qvariant_converter.convertString({"path": sel_toolchain}))
133 self.pageContent.toolchainList.addItem(item)
134 toolchains = self.toolchains()
135 toolchains[sel_toolchain] = False
136 self.setToolchains(toolchains)
138 def removeToolchain(self):
140 Slot called when the user removes manually a toolchain.
142 if self.pageContent.toolchainList.currentRow() != -1:
143 item = self.pageContent.toolchainList.takeItem(self.pageContent.toolchainList.currentRow())
144 toolchain = qvariant_converter.getStringDict(item.data(Qt.UserRole))["path"]
145 toolchains = self.toolchains()
146 del toolchains[toolchain]
147 self.setToolchains(toolchains)
149 def searchToolchain(self):
151 Slot called when the user clicks on the 'search' button. It opens the
152 toolchain search dialog.
154 search = BToolchainSearch.BToolchainSearch()
155 self.connect(search, SIGNAL("accepted()"), self._search)
158 def validateAllToolchains(self):
160 Slot called when the user clicks on the validate button. It starts the
161 toolchain validation procedure for all the toolchains.
163 QApplication.instance().setOverrideCursor(Qt.WaitCursor)
164 for i in range(self.pageContent.toolchainList.count()):
165 self.validateToolchain(i)
166 QApplication.instance().restoreOverrideCursor()
168 def validateToolchain(self, i):
170 Toolchain validation procedure.
172 filename = qvariant_converter.getStringDict(self.pageContent.toolchainList.item(i).data(Qt.UserRole))["path"]
175 ## Check for the other tools of the toolchain
176 for tool in TOOLCHAIN_ITEMS:
177 if os.path.exists(filename.replace("gcc", tool)):
182 ## Try to retrieve the informations about the toolchain only for the valid toolchains
184 self._validation_process = QProcess()
185 self._validation_process.start(filename, ["-v"])
186 self._validation_process.waitForStarted(1000)
187 if self._validation_process.waitForFinished(200):
188 description = str(self._validation_process.readAllStandardError())
189 info = bertos_utils.getToolchainInfo(description)
190 if len(info.keys()) >= 4:
193 self._validation_process.kill()
194 ## Add the item in the list with the appropriate associate data.
196 self._validItem(i, info)
199 toolchains = self.toolchains()
200 toolchains[filename] = True
201 self.setToolchains(toolchains)
203 def isComplete(self):
205 Overload of the QWizard isComplete method.
207 if self.pageContent.toolchainList.currentRow() != -1:
208 self._projectInfoStore("TOOLCHAIN",
209 qvariant_converter.getStringDict(self.pageContent.toolchainList.currentItem().data(Qt.UserRole)))
214 def reloadData(self):
216 Overload of the BWizard reloadData method.
220 self._populateToolchainList()