Group methods in classes in topics
[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             infos = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole))
36             for key, value in infos.items():
37                 if type(CPU_DEF[key]) == list:
38                     infos[key] = qvariant_converter.getStringList(value)
39                 if type(CPU_DEF[key]) == str or type(CPU_DEF) == unicode:
40                     infos[key] = qvariant_converter.getString(value)
41             self.setProjectInfo("CPU_INFOS", infos)
42             self.setProjectInfo("CPU_NAME", unicode(self.pageContent.cpuList.currentItem().text()))
43             return True
44         else:
45             return False
46     
47     ####
48     
49     ## Overloaded BWizardPage methods ##
50
51     def setupUi(self):
52         """
53         Overload of the BWizardPage setupUi method.
54         """
55         self.pageContent.cpuList.setSortingEnabled(True)
56         self.pageContent.descriptionLabel.setVisible(False)
57         self.pageContent.descriptionLabel.setText("")
58
59     def connectSignals(self):
60         """
61         Overload of the BWizardPage connectSignals method.
62         """
63         self.connect(self.pageContent.cpuList, SIGNAL("itemSelectionChanged()"), self.rowChanged)
64
65     def reloadData(self):
66         """
67         Overload of the BWizardPage reloadData method.
68         """
69         QApplication.instance().setOverrideCursor(Qt.WaitCursor)
70         bertos_utils.loadSourceTree(self.project())
71         self.populateCpuList()
72         cpu_name = self.projectInfo("CPU_NAME")
73         self.setupUi()
74         if not cpu_name is None:
75             self.selectItem(cpu_name)
76         QApplication.instance().restoreOverrideCursor()
77         self.emit(SIGNAL("completeChanged()"))
78
79     ####
80     
81     ## Slots ##
82
83     def rowChanged(self):
84         """
85         Slot called when the user select an entry from the cpu list.
86         """
87         description = qvariant_converter.getDict(self.pageContent.cpuList.currentItem().data(Qt.UserRole))["CPU_DESC"]
88         description = qvariant_converter.getStringList(description)
89         self.pageContent.descriptionLabel.setText("<br>".join(description))
90         self.pageContent.descriptionLabel.setVisible(True)
91         self.emit(SIGNAL("completeChanged()"))
92
93     ####
94     
95     def populateCpuList(self):
96         """
97         Fills the cpu list.
98         """
99         self.pageContent.cpuList.clear()
100         self.pageContent.cpuList.setCurrentItem(None)
101         infos = bertos_utils.loadCpuInfos(self.project())
102         for cpu in infos:
103             item = QListWidgetItem(cpu["CPU_NAME"])
104             item.setData(Qt.UserRole, qvariant_converter.convertDict(cpu))
105             self.pageContent.cpuList.addItem(item)
106     
107     def selectItem(self, cpu):
108         """
109         Selects the given cpu from the list.
110         """
111         elements = self.pageContent.cpuList.findItems(cpu, Qt.MatchCaseSensitive)
112         if len(elements) == 1:
113             self.pageContent.cpuList.setCurrentItem(elements[0])