Correct a little bug about empty configurations
[bertos.git] / wizard / BCreationPage.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
16 from BWizardPage import *
17 import bertos_utils
18
19 from const import *
20
21 class BCreationPage(BWizardPage):
22     
23     def __init__(self):
24         BWizardPage.__init__(self, UI_LOCATION + "/project_creation.ui")
25         self.setTitle(self.tr("Create the BeRTOS project"))
26         self._setupUi()
27         self._connectSignals()
28         self._completed = False
29     
30     def _setupUi(self):
31         self._confirm_group = QWidgetGroup(self.pageContent.summaryTree,
32                                             self.pageContent.createButton)
33         self._final_group = QWidgetGroup(self.pageContent.iconLabel,
34                                             self.pageContent.textLabel)
35         self._final_group.setVisible(False)
36         summary = self.pageContent.summaryTree
37         summary.setHeaderHidden(True)
38         summary.setColumnCount(1)
39     
40     def reloadData(self):
41         self._completed = False
42         self._setupUi()
43         self.pageContent.summaryTree.clear()
44         top_level = []
45         folder_title = QTreeWidgetItem(QStringList([self.tr("Project folder")]))
46         folder_item = QTreeWidgetItem(folder_title, QStringList([os.path.normpath(self._projectInfoRetrieve("PROJECT_PATH"))]))
47         top_level.append(folder_title)
48         version_title = QTreeWidgetItem(QStringList([self.tr("BeRTOS version")]))
49         sources_path = self._projectInfoRetrieve("SOURCES_PATH")
50         version = QTreeWidgetItem(version_title, QStringList([self.tr("version: ") + bertos_utils.bertosVersion(sources_path)]))
51         source_path = QTreeWidgetItem(version_title, QStringList([self.tr("path: ") + os.path.normpath(sources_path)]))
52         top_level.append(version_title)
53         cpu_title = QTreeWidgetItem(QStringList([self.tr("CPU")]))
54         cpu_name = QTreeWidgetItem(cpu_title, QStringList([self.tr("cpu name: ") + self._projectInfoRetrieve("CPU_NAME")]))
55         top_level.append(cpu_title)
56         toolchain_title = QTreeWidgetItem(QStringList([self.tr("Toolchain")]))
57         toolchain_info = self._projectInfoRetrieve("TOOLCHAIN")
58         if "target" in toolchain_info.keys():
59             toolchain_target = QTreeWidgetItem(toolchain_title, QStringList([self.tr("target: " + toolchain_info["target"])]))
60         if "version" in toolchain_info.keys():
61             toolchain_target = QTreeWidgetItem(toolchain_title, QStringList([self.tr("version: " + "GCC " + toolchain_info["version"] + " (" + toolchain_info["build"] + ")")]))
62         toolchain_path = QTreeWidgetItem(toolchain_title, QStringList([self.tr("path: " + os.path.normpath(toolchain_info["path"]))]))
63         top_level.append(toolchain_title)
64         module_title = QTreeWidgetItem(QStringList([self.tr("Modules")]))
65         configurations = self._projectInfoRetrieve("CONFIGURATIONS")
66         module_categories = {}
67         for module, information in self._projectInfoRetrieve("MODULES").items():
68             if information["enabled"]:
69                 if information["category"] not in module_categories.keys():
70                     module_categories[information["category"]] = []
71                 moduleItem = QTreeWidgetItem(QStringList([module + " - " + information["description"]]))
72                 module_categories[information["category"]].append(moduleItem)
73                 if len(information["configuration"]) > 0:
74                     for start, property in configurations[information["configuration"]]["paramlist"]:
75                         # If the final char of the brief is a dot (".") removes it.
76                         brief = configurations[information["configuration"]][property]["brief"]
77                         if brief[-1] == ".":
78                             brief = brief[:-1]
79                         configuration_item = QTreeWidgetItem(moduleItem, QStringList([brief + ": " + configurations[information["configuration"]][property]["value"]]))
80         for key, value in module_categories.items():
81             category_item = QTreeWidgetItem(module_title, QStringList([key]))
82             category_item.addChildren(value)
83         top_level.append(module_title)
84         self.pageContent.summaryTree.insertTopLevelItems(0, top_level)
85     
86     def _connectSignals(self):
87         self.connect(self.pageContent.createButton, SIGNAL("clicked(bool)"), self._createProject)
88     
89     def _createProject(self):
90         QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
91         self._confirm_group.setVisible(False)
92         bertos_utils.createBertosProject(self.wizard().project())
93         self._final_group.setVisible(True)
94         self._completed = True
95         QApplication.restoreOverrideCursor()
96         self.emit(SIGNAL("completeChanged()"))
97     
98     def isComplete(self):
99         return self._completed
100
101 class QWidgetGroup(QObject):
102     """
103     Container class, this class contains widgets and permit to set some
104     properties of the contained widgets at the same time.
105     """
106     def __init__(self, *elements):
107         self._widgets = []
108         for element in elements:
109             self._widgets.append(element)
110     
111     def addWidget(self, widget):
112         if widget not in self._widgets:
113             self._widgets.append(widget)
114     
115     def setVisible(self, visible):
116         for widget in self._widgets:
117             widget.setVisible(visible)
118     
119     def isVisible(self):
120         for widget in self._widgets:
121             if not widget.isVisible():
122                 return False
123         return True
124