Add the cpu descrpition in the cpu select page
[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         infos = bertos_utils.loadCpuInfos(self._projectInfoRetrieve("SOURCES_PATH"))
27         for cpu in infos:
28             item = QListWidgetItem(cpu["CPU_NAME"])
29             # The CPU_DESC field in the cpu definition is a list of string, so we need to 
30             # store it as a QStringList in a QVariant
31             item.setData(Qt.UserRole, QVariant(QStringList(cpu["CPU_DESC"])))
32             self.pageContent.cpuList.addItem(item)
33     
34     def _connectSignals(self):
35         self.connect(self.pageContent.cpuList, SIGNAL("itemSelectionChanged()"), self.rowChanged)
36     
37     def _selectItem(self, cpu):
38         elements = self.pageContent.cpuList.findItems(cpu, Qt.MatchCaseSensitive)
39         if len(elements) == 1:
40             self.pageContent.cpuList.setCurrentItem(elements[0])
41     
42     def _setupUi(self):
43         self.pageContent.descriptionLabel.setVisible(False)
44     
45     def reloadData(self):
46         self._populateCpuList()
47         cpuName = self._projectInfoRetrieve("CPU_NAME")
48         if not cpuName is None:
49             self._selectItem(cpuName)
50     
51     def isComplete(self):
52         if self.pageContent.cpuList.currentRow() != -1:
53             self._projectInfoStore("CPU_NAME", self.pageContent.cpuList.currentItem().text())
54             return True
55         else:
56             return False
57         
58     def rowChanged(self):
59         description = self.pageContent.cpuList.currentItem().data(Qt.UserRole).toStringList()
60         # We need to convert the list of QString in a list of unicode
61         description =  [unicode(line) for line in description]
62         self.pageContent.descriptionLabel.setText("<br>".join(description))
63         self.pageContent.descriptionLabel.setVisible(True)
64         self.emit(SIGNAL("completeChanged()"))