Add the check for the right toolchain for the selected cpu
[bertos.git] / wizard / BCpuPage.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
5 # All rights reserved.
6 #
7 # $Id:$
8 #
9 # Author: Lorenzo Berni <duplo@develer.com>
10 #
11
12
13 from BWizardPage import *
14 import bertos_utils
15
16 class BCpuPage(BWizardPage):
17     
18     def __init__(self):
19         BWizardPage.__init__(self, "cpu_select.ui")
20         self.setTitle(self.tr("Select the CPU"))
21         self._connectSignals()
22         self._setupUi()
23     
24     def _populateCpuList(self):
25         self.pageContent.cpuList.clear()
26         self.pageContent.cpuList.setCurrentItem(None)
27         infos = bertos_utils.loadCpuInfos(self._projectInfoRetrieve("SOURCES_PATH"))
28         for cpu in infos:
29             item = QListWidgetItem(cpu["CPU_NAME"])
30             # The CPU_DESC field in the cpu definition is a list of string, so we need to 
31             # store it as a QStringList in a QVariant
32             item.setData(Qt.UserRole, QVariant(cpu))
33             self.pageContent.cpuList.addItem(item)
34     
35     def _connectSignals(self):
36         self.connect(self.pageContent.cpuList, SIGNAL("itemSelectionChanged()"), self.rowChanged)
37     
38     def _selectItem(self, cpu):
39         elements = self.pageContent.cpuList.findItems(cpu, Qt.MatchCaseSensitive)
40         if len(elements) == 1:
41             self.pageContent.cpuList.setCurrentItem(elements[0])
42     
43     def _setupUi(self):
44         self.pageContent.descriptionLabel.setVisible(False)
45         self.pageContent.descriptionLabel.setText("")
46     
47     def reloadData(self):
48         self._populateCpuList()
49         cpuName = self._projectInfoRetrieve("CPU_NAME")
50         self._setupUi()
51         if not cpuName is None:
52             self._selectItem(cpuName)
53         self.emit(SIGNAL("completeChanged()"))
54     
55     def isComplete(self):
56         if self.pageContent.cpuList.currentRow() != -1:
57             self._projectInfoStore("CPU_INFOS", self.pageContent.cpuList.currentItem().data(Qt.UserRole).toMap())
58             return True
59         else:
60             return False
61         
62     def rowChanged(self):
63         description = self.pageContent.cpuList.currentItem().data(Qt.UserRole).toMap()
64         # I don't like to use QString as key in the dict, but the QVariant.toMap() return a dict<QString,QVariant>
65         description =  description[QString("CPU_DESC")].toStringList()
66         # We need to convert the list of QString in a list of unicode
67         description = [unicode(line) for line in description]
68         self.pageContent.descriptionLabel.setText("<br>".join(description))
69         self.pageContent.descriptionLabel.setVisible(True)
70         self.emit(SIGNAL("completeChanged()"))