Add spinbox for cpu frequency
[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         QApplication.instance().restoreOverrideCursor()
83         self.emit(SIGNAL("completeChanged()"))
84
85     ####
86     
87     ## Slots ##
88
89     def rowChanged(self):
90         """
91         Slot called when the user select an entry from the cpu list.
92         """
93         description = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole))["CPU_DESC"]
94         description = qvariant_converter.getStringList(description)
95         frequency = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole))["CPU_DEFAULT_FREQ"]
96         frequency = qvariant_converter.getString(frequency)
97         frequency = frequency.replace("U", "").replace("L", "")
98         self.pageContent.descriptionLabel.setText("<br>".join(description))
99         self.pageContent.descriptionLabel.setVisible(True)
100         self.pageContent.frequencySpinBox.setValue(long(frequency))
101         self.emit(SIGNAL("completeChanged()"))
102     
103     def freqChanged(self):
104         self.emit(SIGNAL("completeChanged()"))
105
106     ####
107     
108     def populateCpuList(self):
109         """
110         Fills the cpu list.
111         """
112         self.pageContent.cpuList.clear()
113         self.pageContent.cpuList.setCurrentItem(None)
114         infos = bertos_utils.loadCpuInfos(self.project())
115         for cpu in infos:
116             item = QListWidgetItem(cpu["CPU_NAME"])
117             item.setData(Qt.UserRole, qvariant_converter.convertDict(cpu))
118             self.pageContent.cpuList.addItem(item)
119     
120     def selectItem(self, cpu):
121         """
122         Selects the given cpu from the list.
123         """
124         elements = self.pageContent.cpuList.findItems(cpu, Qt.MatchCaseSensitive)
125         if len(elements) == 1:
126             self.pageContent.cpuList.setCurrentItem(elements[0])