Improove the ui
[bertos.git] / wizard / BOutputPage.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 import plugins
19
20 from const import *
21
22 class BOutputPage(BWizardPage):
23     """
24     Page of the wizard that show a little summary of the previous decisions.
25     """
26     
27     def __init__(self):
28         BWizardPage.__init__(self, UI_LOCATION + "/output_select.ui")
29         self.setTitle(self.tr("Choose the project output"))
30     
31     ## Overloaded BWizardPage methods. ##
32     
33     def connectSignals(self):
34         """
35         Overload of the BWizardPage connectSignals method.
36         """
37         for plugin in self._plugin_dict:
38             self.connect(plugin, SIGNAL("stateChanged(int)"), self.modeChecked)
39     
40     def setupUi(self):
41         """
42         Overload of the BWizardPage setupUi method.
43         """
44         self._plugin_dict = {}
45         scrollLayout = QVBoxLayout()
46         group, check = self.createNewOutput("BeRTOS Build System",
47                                             "Classic BeRTOS makefile based project",
48                                             True, False)
49         scrollLayout.addWidget(group)
50         for plugin in self.availablePlugins():
51             module = bertos_utils.loadPlugin(plugin)
52             group, check = self.createNewOutput(module.PLUGIN_NAME,
53                                                 module.PLUGIN_DESCRIPTION,
54                                                 True, True)
55             scrollLayout.addWidget(group)
56             self._plugin_dict[check] = plugin
57         scrollLayout.addStretch()
58         widget = QWidget()
59         widget.setLayout(scrollLayout)
60         self.pageContent.scrollArea.setWidget(widget)
61     
62     def reloadData(self):
63         """
64         Overload of the BWizardPage reloadData method.
65         """
66         self.modeChecked()
67         
68     ####
69     
70     ## Slots ##
71     
72     def modeChecked(self):
73         """
74         Slot called when one of the mode checkbox is checked. It stores it.
75         """
76         plugins = []
77         for checkBox, plugin in self._plugin_dict.items():
78             if checkBox.checkState() == Qt.Checked:
79                 plugins.append(plugin)
80         self.setProjectInfo("OUTPUT", plugins)
81
82     ####
83     
84     def availablePlugins(self):
85         """
86         Returns the list of the available plugins.
87         """
88         return plugins.__all__
89     
90     def createNewOutput(self, name, description, checked=True, enabled=True):
91         """
92         Create a groupBox for the given pieces of information. Returns the
93         groupBox and the checkBox
94         """
95         check = QCheckBox(description)
96         if checked:
97             check.setCheckState(Qt.Checked)
98         else:
99             check.setCheckState(Qt.Unchecked)
100         groupLayout = QVBoxLayout()
101         groupLayout.addWidget(check)
102         group = QGroupBox(name)
103         group.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)
104         group.setLayout(groupLayout)
105         group.setEnabled(enabled)
106         return group, check