Remove the QVariant -> python type conversion from the application
[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 import qvariant_converter
16
17 class BCpuPage(BWizardPage):
18     
19     def __init__(self):
20         BWizardPage.__init__(self, "cpu_select.ui")
21         self.setTitle(self.tr("Select the CPU"))
22         self._connectSignals()
23         self._setupUi()
24     
25     def _populateCpuList(self):
26         self.pageContent.cpuList.clear()
27         self.pageContent.cpuList.setCurrentItem(None)
28         infos = bertos_utils.loadCpuInfos(self._projectInfoRetrieve("SOURCES_PATH"))
29         for cpu in infos:
30             item = QListWidgetItem(cpu["CPU_NAME"])
31             # The CPU_DESC field in the cpu definition is a list of string, so we need to 
32             # store it as a QStringList in a QVariant
33             item.setData(Qt.UserRole, QVariant(cpu))
34             self.pageContent.cpuList.addItem(item)
35     
36     def _connectSignals(self):
37         self.connect(self.pageContent.cpuList, SIGNAL("itemSelectionChanged()"), self.rowChanged)
38     
39     def _selectItem(self, cpu):
40         elements = self.pageContent.cpuList.findItems(cpu, Qt.MatchCaseSensitive)
41         if len(elements) == 1:
42             self.pageContent.cpuList.setCurrentItem(elements[0])
43     
44     def _setupUi(self):
45         self.pageContent.descriptionLabel.setVisible(False)
46         self.pageContent.descriptionLabel.setText("")
47     
48     def reloadData(self):
49         self._populateCpuList()
50         cpuName = self._projectInfoRetrieve("CPU_NAME")
51         self._setupUi()
52         if not cpuName is None:
53             self._selectItem(cpuName)
54         self.emit(SIGNAL("completeChanged()"))
55     
56     def isComplete(self):
57         if self.pageContent.cpuList.currentRow() != -1:
58             self._projectInfoStore("CPU_INFOS", qvariant_converter.getStringDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole)))
59             return True
60         else:
61             return False
62         
63     def rowChanged(self):
64         description = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole))["CPU_DESC"]
65         description = qvariant_converter.getStringList(description)
66         self.pageContent.descriptionLabel.setText("<br>".join(description))
67         self.pageContent.descriptionLabel.setVisible(True)
68         self.emit(SIGNAL("completeChanged()"))