Store the last used save directory
[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     ## BProject interaction methods ##
40     
41     def setProjectInfo(self, key, value):
42         """
43         Stores the given value in the BProject class associating it with the given
44         key.
45         """
46         QApplication.instance().project.setInfo(key, value)
47     
48     def projectInfo(self, key):
49         """
50         Retrieves the information associated with the given key.
51         """
52         return QApplication.instance().project.info(key)
53     
54     def project(self):
55         """
56         Returns the BProject instance.
57         """
58         return QApplication.instance().project
59     
60     ####
61     
62     ## QSettings interaction methods ##
63
64     def settingsStore(self, key, value):
65         """
66         Stores the given value in the QSettings associated with the given key.
67         """
68         QApplication.instance().settings.setValue(QString(key), value)
69     
70     def settingsRetrieve(self, key):
71         """
72         Retrieves the value associated to key in the QSettings. Note that this
73         Value is a QVariant and neet to be converted in a standard type.
74         """
75         return QApplication.instance().settings.value(QString(key), QVariant())
76     
77     def versions(self):
78         """
79         Returns the version list from the QSettings.
80         """
81         return qvariant_converter.getStringList(self.settingsRetrieve("versions"))
82     
83     def setVersions(self, versions):
84         """
85         Stores the given versions in the QSettings.
86         """
87         self.settingsStore("versions", qvariant_converter.convertStringList(versions))
88         
89     def searchDirList(self):
90         """
91         Returns the search dir list from the QSettings.
92         """
93         return qvariant_converter.getStringList(self.settingsRetrieve("search_dir_list"))
94     
95     def setSearchDirList(self, search_dir_list):
96         """
97         Stores the search dir list in the QSettings.
98         """
99         self.settingsStore("search_dir_list", qvariant_converter.convertStringList(search_dir_list))
100     
101     def pathSearch(self):
102         """
103         Returns the value of path search from the QSettings.
104         """
105         return qvariant_converter.getBool(self.settingsRetrieve("path_search"))
106     
107     def setPathSearch(self, path_search):
108         """
109         Stores the path search value in the QSettings.
110         """
111         self.settingsStore("path_search", qvariant_converter.convertBool(path_search))
112     
113     def toolchains(self):
114         """
115         Returns the toolchains stored in the QSettings.
116         """
117         return qvariant_converter.getBoolDict(self.settingsRetrieve("toolchains"))
118
119     def setToolchains(self, toolchains):
120         """
121         Stores the toolchains in the QSettings.
122         """
123         self.settingsStore("toolchains", qvariant_converter.convertBoolDict(toolchains))
124     
125     def defaultFolder(self):
126         """
127         Returns the default save folder stored in the QSettings.
128         """
129         return qvariant_converter.getString(self.settingsRetrieve("folder"))
130     
131     def setDefaultFolder(self, folder):
132         """
133         Stores the default save folder in the QSettings.
134         """
135         self.settingsStore("folder", qvariant_converter.convertString(folder))
136
137     ####
138     
139     ## Methodo to be implemented in child classes when needed ##
140     
141     def reloadData(self):
142         """
143         Method called before the page is loaded. The pages that need to use this
144         method have to implement it.
145         """
146         pass
147     
148     def setupUi(self):
149         """
150         Method called automatically during the initialization of the wizard page.
151         It set up the interface. Pages that need to use this method have to
152         implement it.
153         """
154         pass
155     
156     def connectSignals(self):
157         """
158         Method called automatically during the initialization of the wizard page.
159         It connects the signals and the slots. The pages that need to use this
160         method have to implement it.
161         """
162         pass
163     
164     ####