8fa44c1e1304da964b5cc1d4c8f527cff7ec5e39
[bertos.git] / wizard / BWizardPage.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # Copyright 2008 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 from PyQt4.QtCore import *
13 from PyQt4.QtGui import *
14 from PyQt4 import uic
15
16 import qvariant_converter
17
18 class BWizardPage(QWizardPage):
19     """
20     Base class for all the wizard pages. It has the utility method used in all
21     the pages. A wizard page class need to extend this class.
22     """
23     
24     def __init__(self, wizardGui, parent = None):
25         QWizardPage.__init__(self, parent)
26         self.pageContent = uic.loadUi(wizardGui, None)
27         layout = QVBoxLayout()
28         layout.addWidget(self.pageContent)
29         self.setLayout(layout)
30         self.setupUi()
31         self.connectSignals()
32     
33     def exceptionOccurred(self, message):
34         """
35         Simple message box showing method.
36         """
37         QMessageBox.critical(self, self.tr("Error occurred"), message, QMessageBox.Ok, QMessageBox.NoButton)
38     
39     def showMessage(self, title, message):
40         """
41         Show an information message box with title and message.
42         """
43         QMessageBox.information(self, title, message)
44         
45     ## BProject interaction methods ##
46     
47     def setProjectInfo(self, key, value):
48         """
49         Stores the given value in the BProject class associating it with the given
50         key.
51         """
52         QApplication.instance().project.setInfo(key, value)
53     
54     def projectInfo(self, key):
55         """
56         Retrieves the information associated with the given key.
57         """
58         return QApplication.instance().project.info(key)
59     
60     def project(self):
61         """
62         Returns the BProject instance.
63         """
64         return QApplication.instance().project
65     
66     ####
67     
68     ## QSettings interaction methods ##
69
70     def settingsStore(self, key, value):
71         """
72         Stores the given value in the QSettings associated with the given key.
73         """
74         QApplication.instance().settings.setValue(QString(key), value)
75     
76     def settingsRetrieve(self, key):
77         """
78         Retrieves the value associated to key in the QSettings. Note that this
79         Value is a QVariant and neet to be converted in a standard type.
80         """
81         return QApplication.instance().settings.value(QString(key), QVariant())
82     
83     def versions(self):
84         """
85         Returns the version list from the QSettings.
86         """
87         return qvariant_converter.getStringList(self.settingsRetrieve("versions"))
88     
89     def setVersions(self, versions):
90         """
91         Stores the given versions in the QSettings.
92         """
93         self.settingsStore("versions", qvariant_converter.convertStringList(versions))
94         
95     def searchDirList(self):
96         """
97         Returns the search dir list from the QSettings.
98         """
99         return qvariant_converter.getStringList(self.settingsRetrieve("search_dir_list"))
100     
101     def setSearchDirList(self, search_dir_list):
102         """
103         Stores the search dir list in the QSettings.
104         """
105         self.settingsStore("search_dir_list", qvariant_converter.convertStringList(search_dir_list))
106     
107     def pathSearch(self):
108         """
109         Returns the value of path search from the QSettings.
110         """
111         return qvariant_converter.getBool(self.settingsRetrieve("path_search"))
112     
113     def setPathSearch(self, path_search):
114         """
115         Stores the path search value in the QSettings.
116         """
117         self.settingsStore("path_search", qvariant_converter.convertBool(path_search))
118     
119     def toolchains(self):
120         """
121         Returns the toolchains stored in the QSettings.
122         """
123         return qvariant_converter.getBoolDict(self.settingsRetrieve("toolchains"))
124
125     def setToolchains(self, toolchains):
126         """
127         Stores the toolchains in the QSettings.
128         """
129         self.settingsStore("toolchains", qvariant_converter.convertBoolDict(toolchains))
130     
131     def defaultFolder(self):
132         """
133         Returns the default save folder stored in the QSettings.
134         """
135         return qvariant_converter.getString(self.settingsRetrieve("folder"))
136     
137     def setDefaultFolder(self, folder):
138         """
139         Stores the default save folder in the QSettings.
140         """
141         self.settingsStore("folder", qvariant_converter.convertString(folder))
142
143     ####
144     
145     ## Methodo to be implemented in child classes when needed ##
146     
147     def reloadData(self):
148         """
149         Method called before the page is loaded. The pages that need to use this
150         method have to implement it.
151         """
152         pass
153     
154     def setupUi(self):
155         """
156         Method called automatically during the initialization of the wizard page.
157         It set up the interface. Pages that need to use this method have to
158         implement it.
159         """
160         pass
161     
162     def connectSignals(self):
163         """
164         Method called automatically during the initialization of the wizard page.
165         It connects the signals and the slots. The pages that need to use this
166         method have to implement it.
167         """
168         pass
169     
170     ####