Change comment.
[bertos.git] / wizard / BWizard.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 #
32 # Author: Lorenzo Berni <duplo@develer.com>
33 #
34
35 import copy
36
37 from PyQt4.QtCore import *
38 from PyQt4.QtGui import *
39
40 try:
41     from version import wizard_version
42 except ImportError:
43     wizard_version = "sandbox"
44
45 class BWizard(QWizard):
46     """
47     Main class of the wizard. It adds the pages automatically.
48     """
49
50     def __init__(self, page_list):
51         self._current = None
52         QWizard.__init__(self)
53         geometry = QApplication.instance().settings.value("geometry", None)
54         if geometry:
55             geometry = geometry.toRect()
56             self.setGeometry(geometry)
57         self.setWindowTitle(self.tr("Create a BeRTOS project - rev.%1").arg(wizard_version))
58         self.setWindowIcon(QIcon(":/images/appicon.png"))
59         self.setOption(QWizard.DisabledBackButtonOnLastPage, True)
60         self.addPages(page_list)
61         self.connectSignals()
62
63     def addPages(self, page_list):
64         """
65         Adds the pages in the wizard.
66         """
67         self._page_dict = {}
68         for i, page in enumerate(page_list):
69             self._page_dict[page] = i
70             self.setPage(i, page())
71
72     def pageIndex(self, page_class):
73         return self._page_dict[page_class]
74
75     def connectSignals(self):
76         """
77         Connects the signals with the related slots.
78         """
79         self.connect(self, SIGNAL("currentIdChanged(int)"), self.pageChanged)
80
81     def pageChanged(self, pageId):
82         """
83         Slot called when the user change the current page. It calls the reloadData
84         method of the next page.
85         """
86         page = self.page(pageId)
87         if page:
88             page.reloadData(previous_id= self._current)
89         self._current = pageId
90
91     def project(self):
92         """
93         Returns the BProject associated with the wizard.
94         """
95         return copy.deepcopy(QApplication.instance().project)
96
97     def done(self, result):
98         geometry = self.geometry()
99         QApplication.instance().settings.setValue("geometry", QVariant(geometry))
100         QWizard.done(self, result)