Add BeRTOS header in sources files
[bertos.git] / wizard / BOutputPage.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # This file is part of BeRTOS.
5 #
6 # Bertos is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 #
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction.  Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License.  This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
28 #
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
30 #
31 # $Id$
32 #
33 # Author: Lorenzo Berni <duplo@develer.com>
34 #
35
36 import os
37
38 from PyQt4.QtGui import *
39 from BWizardPage import *
40 import bertos_utils
41
42 import plugins
43
44 from const import *
45
46 class BOutputPage(BWizardPage):
47     """
48     Page of the wizard that show a little summary of the previous decisions.
49     """
50     
51     def __init__(self):
52         BWizardPage.__init__(self, UI_LOCATION + "/output_select.ui")
53         self.setTitle(self.tr("Choose the project output"))
54     
55     ## Overloaded BWizardPage methods. ##
56     
57     def connectSignals(self):
58         """
59         Overload of the BWizardPage connectSignals method.
60         """
61         for plugin in self._plugin_dict:
62             self.connect(plugin, SIGNAL("stateChanged(int)"), self.modeChecked)
63     
64     def setupUi(self):
65         """
66         Overload of the BWizardPage setupUi method.
67         """
68         self._plugin_dict = {}
69         scrollLayout = QVBoxLayout()
70         group, check = self.createNewOutput("BeRTOS Build System",
71                                             "Classic BeRTOS makefile based project",
72                                             True, False)
73         scrollLayout.addWidget(group)
74         for plugin in self.availablePlugins():
75             module = bertos_utils.loadPlugin(plugin)
76             group, check = self.createNewOutput(module.PLUGIN_NAME,
77                                                 module.PLUGIN_DESCRIPTION,
78                                                 True, True)
79             scrollLayout.addWidget(group)
80             self._plugin_dict[check] = plugin
81         scrollLayout.addStretch()
82         widget = QWidget()
83         widget.setLayout(scrollLayout)
84         self.pageContent.scrollArea.setWidget(widget)
85     
86     def reloadData(self):
87         """
88         Overload of the BWizardPage reloadData method.
89         """
90         self.modeChecked()
91         
92     ####
93     
94     ## Slots ##
95     
96     def modeChecked(self):
97         """
98         Slot called when one of the mode checkbox is checked. It stores it.
99         """
100         plugins = []
101         for checkBox, plugin in self._plugin_dict.items():
102             if checkBox.checkState() == Qt.Checked:
103                 plugins.append(plugin)
104         self.setProjectInfo("OUTPUT", plugins)
105
106     ####
107     
108     def availablePlugins(self):
109         """
110         Returns the list of the available plugins.
111         """
112         return plugins.plugin_list
113     
114     def createNewOutput(self, name, description, checked=True, enabled=True):
115         """
116         Create a groupBox for the given pieces of information. Returns the
117         groupBox and the checkBox
118         """
119         check = QCheckBox(description)
120         if checked:
121             check.setCheckState(Qt.Checked)
122         else:
123             check.setCheckState(Qt.Unchecked)
124         groupLayout = QVBoxLayout()
125         groupLayout.addWidget(check)
126         group = QGroupBox(name)
127         group.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)
128         group.setLayout(groupLayout)
129         group.setEnabled(enabled)
130         return group, check