Add the description for the selected property
[bertos.git] / wizard / BModulePage.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # Copyright 2009 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 import os
13
14 from PyQt4.QtGui import *
15 from BWizardPage import *
16 import bertos_utils
17
18
19 class BModulePage(BWizardPage):
20     
21     def __init__(self):
22         BWizardPage.__init__(self, "module_select.ui")
23         self.setTitle(self.tr("Configure the BeRTOS modules"))
24         self._setupUi()
25         self._connectSignals()
26     
27     def reloadData(self):
28         self._setupButtonGroup()
29         self._loadModuleData()
30         self._fillModuleTable()
31     
32     def _setupButtonGroup(self):
33         self._buttonGroup = QButtonGroup()
34         self._buttonGroup.setExclusive(False)
35     
36     def _loadModuleData(self):
37         modules = bertos_utils.loadModuleInfosDict(self._projectInfoRetrieve("SOURCES_PATH"))
38         lists = bertos_utils.loadDefineListsDict(self._projectInfoRetrieve("SOURCES_PATH"))
39         configurations = {}
40         for module, informations in modules.items():
41             configurations[informations["configuration"]] = bertos_utils.loadConfigurationInfos(self._projectInfoRetrieve("SOURCES_PATH") +
42                                                                                                 "/" + informations["configuration"])
43         self._projectInfoStore("MODULES", modules)
44         self._projectInfoStore("LISTS", lists)
45         self._projectInfoStore("CONFIGURATIONS", configurations)
46     
47     def _fillModuleTable(self):
48         modules = self._projectInfoRetrieve("MODULES")
49         self.pageContent.moduleTable.setRowCount(len(modules))
50         for index, module in enumerate(modules):
51             self.pageContent.moduleTable.setItem(index, 1, QTableWidgetItem(module))
52             checkBox = QCheckBox()
53             self._buttonGroup.addButton(checkBox, index)
54             self.pageContent.moduleTable.setCellWidget(index, 0, checkBox)
55     
56     def _fillPropertyTable(self):
57         module = unicode(self.pageContent.moduleTable.item(self.pageContent.moduleTable.currentRow(), 1).text())
58         configuration = self._projectInfoRetrieve("MODULES")[module]["configuration"]
59         configurations = self._projectInfoRetrieve("CONFIGURATIONS")[configuration]
60         self.pageContent.propertyTable.clear()
61         self.pageContent.propertyTable.setRowCount(len(configurations))
62         for index, property in enumerate(configurations):
63             item = QTableWidgetItem(property)
64             item.setData(Qt.UserRole, qvariant_converter.convertString(property))
65             self.pageContent.propertyTable.setItem(index, 0, item)
66             if "type" in configurations[property]["informations"].keys() and configurations[property]["informations"]["type"] == "boolean":
67                 ## boolean property
68                 checkBox = QCheckBox()
69                 self.pageContent.propertyTable.setCellWidget(index, 1, checkBox)
70                 if configurations[property]["value"] == "1":
71                     checkBox.setChecked(True)
72                 else:
73                     checkBox.setChecked(False)
74             elif "type" in configurations[property]["informations"].keys() and configurations[property]["informations"]["type"] == "enum":
75                 ## enum property
76                 comboBox = QComboBox()
77                 self.pageContent.propertyTable.setCellWidget(index, 1, comboBox)
78                 enum = self._projectInfoRetrieve("LISTS")[configurations[property]["informations"]["value_list"]]
79                 for element in enum:
80                     comboBox.addItem(element)
81             else:
82                 ## int, long or undefined type property
83                 spinBox = QSpinBox()
84                 self.pageContent.propertyTable.setCellWidget(index, 1, spinBox)
85                 if "min" in configurations[property]["informations"].keys():
86                     minimum = int(configurations[property]["informations"]["min"])
87                 else:
88                     minimum = -32768
89                 spinBox.setMinimum(minimum)
90                 if "max" in configurations[property]["informations"].keys():
91                     maximum = int(configurations[property]["infomations"]["max"])
92                 else:
93                     maximum = 32767
94                 spinBox.setMaximum(maximum)
95                 if "long" in configurations[property]["informations"].keys() and configurations[property]["informations"]["long"] == "True":
96                     spinBox.setSuffix("L")
97                 spinBox.setValue(int(configurations[property]["value"].replace("L", "")))
98     
99     def _currentModule(self):
100         return unicode(self.pageContent.moduleTable.item(self.pageContent.moduleTable.currentRow(), 1).text())
101     
102     def _currentModuleConfigurations(self):
103         return self._projectInfoRetrieve("MODULES")[self._currentModule()]["configuration"]
104     
105     def _currentProperty(self):
106         return qvariant_converter.getString(self.pageContent.propertyTable.item(self.pageContent.propertyTable.currentRow(), 0).data(Qt.UserRole))
107     
108     def _currentPropertyItem(self):
109         return self.pageContent.propertyTable.item(self.pageContent.propertyTable.currentRow(), 0)
110     
111     def _resetPropertyDescription(self):
112         for index in range(self.pageContent.propertyTable.rowCount()):
113             propertyName = qvariant_converter.getString(self.pageContent.propertyTable.item(index, 0).data(Qt.UserRole))
114             self.pageContent.propertyTable.item(index, 0).setText(propertyName)
115     
116     def _showPropertyDescription(self):
117         self._resetPropertyDescription()
118         description = self._projectInfoRetrieve("CONFIGURATIONS")[self._currentModuleConfigurations()][self._currentProperty()]["description"]
119         name = self._currentProperty()
120         self._currentPropertyItem().setText(name + "\n" + description)
121     
122     def _setupUi(self):
123         self.pageContent.moduleTable.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
124         self.pageContent.moduleTable.horizontalHeader().setStretchLastSection(True)
125         self.pageContent.moduleTable.horizontalHeader().setVisible(False)
126         self.pageContent.moduleTable.verticalHeader().setResizeMode(QHeaderView.ResizeToContents)
127         self.pageContent.moduleTable.verticalHeader().setVisible(False)
128         self.pageContent.moduleTable.setColumnCount(2)
129         self.pageContent.moduleTable.setRowCount(0)
130         self.pageContent.propertyTable.horizontalHeader().setResizeMode(QHeaderView.Stretch)
131         self.pageContent.propertyTable.horizontalHeader().setVisible(False)
132         self.pageContent.propertyTable.verticalHeader().setResizeMode(QHeaderView.ResizeToContents)
133         self.pageContent.propertyTable.verticalHeader().setVisible(False)
134         self.pageContent.propertyTable.setColumnCount(2)
135         self.pageContent.propertyTable.setRowCount(0)
136     
137     def _connectSignals(self):
138         self.connect(self.pageContent.moduleTable, SIGNAL("itemSelectionChanged()"), self._fillPropertyTable)
139         self.connect(self.pageContent.propertyTable, SIGNAL("itemSelectionChanged()"), self._showPropertyDescription)