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