Add comment for each method and class
[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         self._connectSignals()
28         self._setupUi()
29     
30     def _populateCpuList(self):
31         """
32         Fills the cpu list.
33         """
34         self.pageContent.cpuList.clear()
35         self.pageContent.cpuList.setCurrentItem(None)
36         infos = bertos_utils.loadCpuInfos(self._project())
37         for cpu in infos:
38             item = QListWidgetItem(cpu["CPU_NAME"])
39             item.setData(Qt.UserRole, qvariant_converter.convertDict(cpu))
40             self.pageContent.cpuList.addItem(item)
41     
42     def _connectSignals(self):
43         """
44         Connects the signals with the related slots.
45         """
46         self.connect(self.pageContent.cpuList, SIGNAL("itemSelectionChanged()"), self.rowChanged)
47     
48     def _selectItem(self, cpu):
49         """
50         Selects the given cpu from the list.
51         """
52         elements = self.pageContent.cpuList.findItems(cpu, Qt.MatchCaseSensitive)
53         if len(elements) == 1:
54             self.pageContent.cpuList.setCurrentItem(elements[0])
55     
56     def _setupUi(self):
57         """
58         Sets up the user interface.
59         """
60         self.pageContent.cpuList.setSortingEnabled(True)
61         self.pageContent.descriptionLabel.setVisible(False)
62         self.pageContent.descriptionLabel.setText("")
63     
64     def reloadData(self):
65         """
66         Overload of the BWizardPage reloadData method.
67         """
68         QApplication.instance().setOverrideCursor(Qt.WaitCursor)
69         bertos_utils.loadSourceTree(self._project())
70         self._populateCpuList()
71         cpu_name = self._projectInfoRetrieve("CPU_NAME")
72         self._setupUi()
73         if not cpu_name is None:
74             self._selectItem(cpu_name)
75         QApplication.instance().restoreOverrideCursor()
76         self.emit(SIGNAL("completeChanged()"))
77     
78     def isComplete(self):
79         """
80         Overload of the QWizardPage isComplete method.
81         """
82         if self.pageContent.cpuList.currentRow() != -1:
83             infos = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole))
84             for key, value in infos.items():
85                 if type(CPU_DEF[key]) == list:
86                     infos[key] = qvariant_converter.getStringList(value)
87                 if type(CPU_DEF[key]) == str or type(CPU_DEF) == unicode:
88                     infos[key] = qvariant_converter.getString(value)
89             self._projectInfoStore("CPU_INFOS", infos)
90             self._projectInfoStore("CPU_NAME", unicode(self.pageContent.cpuList.currentItem().text()))
91             return True
92         else:
93             return False
94         
95     def rowChanged(self):
96         """
97         Slot called when the user select an entry from the cpu list.
98         """
99         description = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole))["CPU_DESC"]
100         description = qvariant_converter.getStringList(description)
101         self.pageContent.descriptionLabel.setText("<br>".join(description))
102         self.pageContent.descriptionLabel.setVisible(True)
103         self.emit(SIGNAL("completeChanged()"))