4 # This file is part of BeRTOS.
6 # Bertos is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction. Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License. This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
33 # Author: Lorenzo Berni <duplo@develer.com>
37 from BWizardPage import *
39 import qvariant_converter
43 class BCpuPage(BWizardPage):
45 Page of the wizard that permits to choose the cpu from the supported ones.
49 BWizardPage.__init__(self, UI_LOCATION + "/cpu_select.ui")
50 self.setTitle(self.tr("Select the CPU on your board"))
51 self.freq_modified = False
53 ## Overloaded QWizardPage methods ##
57 Overload of the QWizardPage isComplete method.
59 if self.pageContent.cpuList.currentRow() != -1:
60 self.pageContent.frequencyLabel.setVisible(True)
61 self.pageContent.frequencySpinBox.setVisible(True)
62 infos = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole))
63 for key, value in infos.items():
65 if type(CPU_DEF[key]) == list:
66 infos[key] = qvariant_converter.getStringList(value)
67 if type(CPU_DEF[key]) == str or type(CPU_DEF) == unicode:
68 infos[key] = qvariant_converter.getString(value)
69 elif key.startswith(MK_PARAM_ID):
70 infos[key] = qvariant_converter.getString(value)
73 self.setProjectInfo("CPU_INFOS", infos)
74 self.setProjectInfo("CPU_NAME", unicode(self.pageContent.cpuList.currentItem().text()))
75 self.setProjectInfo("SELECTED_FREQ", unicode(long(self.pageContent.frequencySpinBox.value())))
76 tag_dict = self.projectInfo("ALL_CPU_TAGS")
78 if tag in infos["CPU_TAGS"] + [infos["CPU_NAME"], infos["TOOLCHAIN"]]:
82 self.setProjectInfo("ALL_CPU_TAGS", tag_dict)
89 ## Overloaded BWizardPage methods ##
93 Overload of the BWizardPage setupUi method.
95 self.pageContent.cpuList.setSortingEnabled(True)
96 self.pageContent.frequencyLabel.setVisible(False)
97 self.pageContent.frequencySpinBox.setVisible(False)
98 preset_advanced = self.projectInfo("PRESET_ADVANCED_CONFIG")
100 self.pageContent.cpuList.setEnabled(False)
102 def connectSignals(self):
104 Overload of the BWizardPage connectSignals method.
106 self.connect(self.pageContent.cpuList, SIGNAL("currentItemChanged(QListWidgetItem *, QListWidgetItem*)"), self.rowChanged)
107 self.connect(self.pageContent.frequencySpinBox, SIGNAL("editingFinished()"), self.freqChanged)
109 def reloadData(self, previous_id=None):
111 Overload of the BWizardPage reloadData method.
114 QApplication.instance().setOverrideCursor(Qt.WaitCursor)
115 self.project.loadSourceTree()
116 self.populateCpuList()
117 cpu_name = self.projectInfo("CPU_NAME")
118 selected_freq = self.projectInfo("SELECTED_FREQ")
121 self.selectItem(cpu_name)
123 self.setFrequency(selected_freq)
124 self.freq_modified = True
126 QApplication.instance().restoreOverrideCursor()
127 self.emit(SIGNAL("completeChanged()"))
133 def rowChanged(self):
135 Slot called when the user select an entry from the cpu list.
137 if self.pageContent.cpuList.currentItem():
138 description = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole))["CPU_DESC"]
139 description = qvariant_converter.getStringList(description)
140 if not self.freq_modified:
141 # Retrieve the default cpu frequency when the value isn't already modified
142 current_freq = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole))["CPU_DEFAULT_FREQ"]
143 current_freq = qvariant_converter.getString(current_freq)
144 current_freq = long(current_freq.replace("U", "").replace("L", ""))
145 self.pageContent.frequencySpinBox.setValue(long(current_freq))
146 self.pageContent.descriptionLabel.setText("<br>".join(description))
147 self.pageContent.descriptionLabel.setVisible(True)
148 self.emit(SIGNAL("completeChanged()"))
150 def freqChanged(self):
152 Slot called when the user change the frequency value.
154 self.freq_modified = True
155 self.emit(SIGNAL("completeChanged()"))
159 def populateCpuList(self):
163 self.pageContent.cpuList.clear()
164 self.pageContent.cpuList.setCurrentItem(None)
165 infos = self.project.getCpuInfos()
166 tag_list = bertos_utils.getTagSet(infos)
167 # Create, fill and store the dict with the tags
169 for element in tag_list:
170 tag_dict[element] = False
171 self.setProjectInfo("ALL_CPU_TAGS", tag_dict)
173 item = QListWidgetItem(cpu["CPU_NAME"])
174 item.setData(Qt.UserRole, qvariant_converter.convertDict(cpu))
175 self.pageContent.cpuList.addItem(item)
177 def selectItem(self, cpu):
179 Selects the given cpu from the list.
181 elements = self.pageContent.cpuList.findItems(cpu, Qt.MatchCaseSensitive)
182 if len(elements) == 1:
183 self.pageContent.cpuList.setCurrentItem(elements[0])
185 def setFrequency(self, frequency):
186 self.pageContent.frequencySpinBox.setValue(long(frequency))