Copy and add hw files to makefile when needed
[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 from const import *
18
19 class BCpuPage(BWizardPage):
20     """
21     Page of the wizard that permits to choose the cpu from the supported ones.
22     """
23     
24     def __init__(self):
25         BWizardPage.__init__(self, UI_LOCATION + "/cpu_select.ui")
26         self.setTitle(self.tr("Select the CPU"))
27     
28     ## Overloaded QWizardPage methods ##
29
30     def isComplete(self):
31         """
32         Overload of the QWizardPage isComplete method.
33         """
34         if self.pageContent.cpuList.currentRow() != -1:
35             self.pageContent.frequencyLabel.setVisible(True)
36             self.pageContent.frequencySpinBox.setVisible(True)
37             infos = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole))
38             for key, value in infos.items():
39                 if type(CPU_DEF[key]) == list:
40                     infos[key] = qvariant_converter.getStringList(value)
41                 if type(CPU_DEF[key]) == str or type(CPU_DEF) == unicode:
42                     infos[key] = qvariant_converter.getString(value)
43             self.setProjectInfo("CPU_INFOS", infos)
44             self.setProjectInfo("CPU_NAME", unicode(self.pageContent.cpuList.currentItem().text()))
45             self.setProjectInfo("SELECTED_FREQ", unicode(long(self.pageContent.frequencySpinBox.value())))
46             return True
47         else:
48             return False
49     
50     ####
51     
52     ## Overloaded BWizardPage methods ##
53
54     def setupUi(self):
55         """
56         Overload of the BWizardPage setupUi method.
57         """
58         self.pageContent.cpuList.setSortingEnabled(True)
59         self.pageContent.descriptionLabel.setVisible(False)
60         self.pageContent.descriptionLabel.setText("")
61         self.pageContent.frequencyLabel.setVisible(False)
62         self.pageContent.frequencySpinBox.setVisible(False)
63
64     def connectSignals(self):
65         """
66         Overload of the BWizardPage connectSignals method.
67         """
68         self.connect(self.pageContent.cpuList, SIGNAL("itemSelectionChanged()"), self.rowChanged)
69         self.connect(self.pageContent.frequencySpinBox, SIGNAL("valueChanged(double)"), self.freqChanged)
70
71     def reloadData(self):
72         """
73         Overload of the BWizardPage reloadData method.
74         """
75         QApplication.instance().setOverrideCursor(Qt.WaitCursor)
76         bertos_utils.loadSourceTree(self.project())
77         self.populateCpuList()
78         cpu_name = self.projectInfo("CPU_NAME")
79         self.setupUi()
80         if not cpu_name is None:
81             self.selectItem(cpu_name)
82         cpu_frequency = self.projectInfo("SELECTED_FREQ")
83         if not cpu_frequency is None:
84             self.pageContent.frequencySpinBox.setValue(cpu_frequency)
85         QApplication.instance().restoreOverrideCursor()
86         self.emit(SIGNAL("completeChanged()"))
87
88     ####
89     
90     ## Slots ##
91
92     def rowChanged(self):
93         """
94         Slot called when the user select an entry from the cpu list.
95         """
96         description = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole))["CPU_DESC"]
97         description = qvariant_converter.getStringList(description)
98         frequency = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole))["CPU_DEFAULT_FREQ"]
99         frequency = qvariant_converter.getString(frequency)
100         frequency = frequency.replace("U", "").replace("L", "")
101         self.pageContent.descriptionLabel.setText("<br>".join(description))
102         self.pageContent.descriptionLabel.setVisible(True)
103         self.pageContent.frequencySpinBox.setValue(long(frequency))
104         self.emit(SIGNAL("completeChanged()"))
105     
106     def freqChanged(self):
107         self.emit(SIGNAL("completeChanged()"))
108
109     ####
110     
111     def populateCpuList(self):
112         """
113         Fills the cpu list.
114         """
115         self.pageContent.cpuList.clear()
116         self.pageContent.cpuList.setCurrentItem(None)
117         infos = bertos_utils.loadCpuInfos(self.project())
118         for cpu in infos:
119             item = QListWidgetItem(cpu["CPU_NAME"])
120             item.setData(Qt.UserRole, qvariant_converter.convertDict(cpu))
121             self.pageContent.cpuList.addItem(item)
122     
123     def selectItem(self, cpu):
124         """
125         Selects the given cpu from the list.
126         """
127         elements = self.pageContent.cpuList.findItems(cpu, Qt.MatchCaseSensitive)
128         if len(elements) == 1:
129             self.pageContent.cpuList.setCurrentItem(elements[0])