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
18 class BToolchainPage(BWizardPage):
21 BWizardPage.__init__(self, "toolchain_select.ui")
22 self.setTitle(self.tr("Select toolchain"))
23 self._validationProcess = None
24 self._populateToolchainList()
25 self._connectSignals()
28 if self.pageContent.customDirBox.isChecked():
29 self._enableCustomDir()
31 self._disableCustomDir()
32 if self.pageContent.pathBox.isChecked() or (self.pageContent.customDirBox.isChecked() and self.pageContent.customDirList.count() != 0):
33 self.pageContent.doSearchButton.setEnabled(True)
35 self.pageContent.doSearchButton.setEnabled(False)
37 def _populateToolchainList(self):
38 toolchains = self._settingsRetrieve("toolchains").toList()
39 for element in toolchains:
40 item = QListWidgetItem(element.toString())
41 item.setData(Qt.UserRole, element)
42 self.pageContent.toolchainList.addItem(item)
45 self.pageContent.toolchainList.clear()
47 def _selectionChanged(self):
48 self.emit(SIGNAL("completeChanged()"))
51 dirList = [unicode(element.toString()) for element in self._settingsRetrieve("search_dir_list").toList()]
52 if(self._settingsRetrieve("path_search").toBool()):
53 dirList += [element for element in bertos_utils.getSystemPath()]
54 toolchainList = bertos_utils.findToolchains(dirList)
55 storedToolchainList = self._settingsRetrieve("toolchains").toList()
56 storedToolchainList = set([unicode(toolchain.toString()) for toolchain in storedToolchainList])
57 toolchainList =set(toolchainList) - set(storedToolchainList)
58 for element in toolchainList:
59 item = QListWidgetItem(element)
60 item.setData(Qt.UserRole, QVariant(element))
61 self.pageContent.toolchainList.addItem(item)
62 self._settingsStore("toolchains", list(toolchainList.union(storedToolchainList)))
64 def _connectSignals(self):
65 self.connect(self.pageContent.toolchainList, SIGNAL("itemSelectionChanged()"), self._selectionChanged)
66 self.connect(self.pageContent.addButton, SIGNAL("clicked()"), self.addToolchain)
67 self.connect(self.pageContent.removeButton, SIGNAL("clicked()"), self.removeToolchain)
68 self.connect(self.pageContent.searchButton, SIGNAL("clicked()"), self.searchToolchain)
69 self.connect(self.pageContent.checkButton, SIGNAL("clicked()"), self.validateToolchains)
71 def _validItem(self, index, infos):
72 item = self.pageContent.toolchainList.item(index)
73 needed = self._projectInfoRetrieve("CPU_INFOS")
74 if infos["target"].find(unicode(needed[QString("TOOLCHAIN")].toString())) != -1:
75 item.setIcon(QIcon(":/images/ok.png"))
77 item.setIcon(QIcon(":/images/warning.png"))
78 item.setText(infos["version"] + " " + infos["target"])
80 def _invalidItem(self, index):
81 item = self.pageContent.toolchainList.item(index)
82 item.setIcon(QIcon(":/images/error.png"))
84 def addToolchain(self):
85 sel_toolchain = QFileDialog.getOpenFileName(self, self.tr("Choose the toolchain"), "")
86 if not sel_toolchain.isEmpty():
87 item = QListWidgetItem(sel_toolchain)
88 item.setData(Qt.UserRole, QVariant(sel_toolchain))
89 self.pageContent.toolchainList.addItem(item)
90 toolchains = self._settingsRetrieve("toolchains").toList()
91 toolchains = set([toolchain.toString() for toolchain in toolchains] + [sel_toolchain])
92 self._settingsStore("toolchains", list(toolchains))
94 def removeToolchain(self):
95 if self.pageContent.toolchainList.currentRow() != -1:
96 item = self.pageContent.toolchainList.takeItem(self.pageContent.toolchainList.currentRow())
97 item = item.data(Qt.UserRole).toString()
98 toolchains = self._settingsRetrieve("toolchains").toList()
99 toolchains = [unicode(toolchain.toString()) for toolchain in toolchains]
100 toolchains.remove(unicode(item))
101 self._settingsStore("toolchains", toolchains)
103 def searchToolchain(self):
104 search = BToolchainSearch.BToolchainSearch()
105 self.connect(search, SIGNAL("accepted()"), self._search)
108 def validateToolchains(self):
109 for i in range(self.pageContent.toolchainList.count()):
110 filename = unicode(self.pageContent.toolchainList.item(i).data(Qt.UserRole).toString())
111 self._validationProcess = QProcess()
112 self._validationProcess.start(filename, ["-v"])
113 self._validationProcess.waitForStarted(1000)
114 if self._validationProcess.waitForFinished(200):
115 description = str(self._validationProcess.readAllStandardError())
116 infos = bertos_utils.getToolchainInfo(description)
117 if len(infos.keys()) == 4:
118 self._validItem(i, infos)
122 self._validationProcess.kill()
125 def isComplete(self):
126 if self.pageContent.toolchainList.currentRow() != -1:
127 self._projectInfoStore("TOOLCHAIN", self.pageContent.toolchainList.item(self.pageContent.toolchainList.currentRow()).data(Qt.UserRole).toString())