b7ffe1f51e96a2fb76e431935cc806973c20a8b2
[bertos.git] / wizard / BWizardPage.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.QtCore import *
39 from PyQt4.QtGui import *
40 from PyQt4 import uic
41
42 import qvariant_converter
43
44 import const
45
46 class BWizardPage(QWizardPage):
47     """
48     Base class for all the wizard pages. It has the utility method used in all
49     the pages. A wizard page class need to extend this class.
50     """
51     
52     def __init__(self, wizardGui, parent = None):
53         QWizardPage.__init__(self, parent)
54         self.pageContent = uic.loadUi(os.path.join(const.DATA_DIR, wizardGui), None)
55         layout = QVBoxLayout()
56         layout.addWidget(self.pageContent)
57         self.setLayout(layout)
58         self.setupUi()
59         self.connectSignals()
60     
61     def exceptionOccurred(self, message):
62         """
63         Simple message box showing method.
64         """
65         QMessageBox.critical(self, self.tr("Error occurred"), message, QMessageBox.Ok, QMessageBox.NoButton)
66     
67     def showMessage(self, title, message):
68         """
69         Show an information message box with title and message.
70         """
71         QMessageBox.information(self, title, message)
72         
73     ## BProject interaction methods ##
74     
75     def setProjectInfo(self, key, value):
76         """
77         Stores the given value in the BProject class associating it with the given
78         key.
79         """
80         QApplication.instance().project.setInfo(key, value)
81     
82     def projectInfo(self, key):
83         """
84         Retrieves the information associated with the given key.
85         """
86         return QApplication.instance().project.info(key)
87     
88     @property
89     def project(self):
90         """
91         Returns the BProject instance.
92         """
93         return QApplication.instance().project
94     
95     ####
96     
97     ## QSettings interaction methods ##
98
99     def settingsStore(self, key, value):
100         """
101         Stores the given value in the QSettings associated with the given key.
102         """
103         QApplication.instance().settings.setValue(QString(key), value)
104     
105     def settingsRetrieve(self, key):
106         """
107         Retrieves the value associated to key in the QSettings. Note that this
108         Value is a QVariant and neet to be converted in a standard type.
109         """
110         return QApplication.instance().settings.value(QString(key), QVariant())
111
112     def plugins(self):
113         """
114         Returns the list of actived plugins.
115         """
116         return qvariant_converter.getStringList(self.settingsRetrieve("plugins"))
117
118     def setPlugins(self, plugins):
119         """
120         Stores the given list of actived plugins.
121         """
122         self.settingsStore("plugins", qvariant_converter.convertStringList(plugins))
123     
124     def versions(self):
125         """
126         Returns the version list from the QSettings.
127         """
128         return qvariant_converter.getStringList(self.settingsRetrieve("versions"))
129     
130     def setVersions(self, versions):
131         """
132         Stores the given versions in the QSettings.
133         """
134         self.settingsStore("versions", qvariant_converter.convertStringList(versions))
135         
136     def searchDirList(self):
137         """
138         Returns the search dir list from the QSettings.
139         """
140         return qvariant_converter.getStringList(self.settingsRetrieve("search_dir_list"))
141     
142     def setSearchDirList(self, search_dir_list):
143         """
144         Stores the search dir list in the QSettings.
145         """
146         self.settingsStore("search_dir_list", qvariant_converter.convertStringList(search_dir_list))
147     
148     def pathSearch(self):
149         """
150         Returns the value of path search from the QSettings.
151         """
152         return qvariant_converter.getBool(self.settingsRetrieve("path_search"))
153     
154     def setPathSearch(self, path_search):
155         """
156         Stores the path search value in the QSettings.
157         """
158         self.settingsStore("path_search", qvariant_converter.convertBool(path_search))
159     
160     def toolchains(self):
161         """
162         Returns the toolchains stored in the QSettings.
163         """
164         return qvariant_converter.getBoolDict(self.settingsRetrieve("toolchains"))
165
166     def setToolchains(self, toolchains):
167         """
168         Stores the toolchains in the QSettings.
169         """
170         self.settingsStore("toolchains", qvariant_converter.convertBoolDict(toolchains))
171     
172     def defaultFolder(self):
173         """
174         Returns the default save folder stored in the QSettings.
175         """
176         return qvariant_converter.getString(self.settingsRetrieve("folder"))
177     
178     def setDefaultFolder(self, folder):
179         """
180         Stores the default save folder in the QSettings.
181         """
182         self.settingsStore("folder", qvariant_converter.convertString(folder))
183
184     ####
185     
186     ## Methodo to be implemented in child classes when needed ##
187     
188     def reloadData(self):
189         """
190         Method called before the page is loaded. The pages that need to use this
191         method have to implement it.
192         """
193         pass
194     
195     def setupUi(self):
196         """
197         Method called automatically during the initialization of the wizard page.
198         It set up the interface. Pages that need to use this method have to
199         implement it.
200         """
201         pass
202     
203     def connectSignals(self):
204         """
205         Method called automatically during the initialization of the wizard page.
206         It connects the signals and the slots. The pages that need to use this
207         method have to implement it.
208         """
209         pass
210     
211     ####