Add the complete implementation of the folder selection page
[bertos.git] / wizard / BFolderPage.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 import os
13
14 from PyQt4.QtGui import *
15 from BWizardPage import *
16 import bertos_utils
17
18 class BFolderPage(BWizardPage):
19     
20     def __init__(self):
21         BWizardPage.__init__(self, "dir_select.ui")
22         self.setTitle(self.tr("Select the project name"))
23         self._initializeAttributes()
24         self._connectSignals()
25
26     def _initializeAttributes(self):
27         self._projectName = ""
28         self._destinationFolder = ""
29     
30     def _connectSignals(self):
31         self.connect(self.pageContent.nameEdit, SIGNAL("textChanged(const QString)"), self._nameChanged)
32         self.connect(self.pageContent.directoryEdit, SIGNAL("textChanged(const QString)"), self._directoryChanged)
33         self.connect(self.pageContent.directoryButton, SIGNAL("clicked()"), self._selectDirectory)
34     
35     def _nameChanged(self, name):
36         self._projectName = str(name).replace(" ", "_")
37         self._setProjectPath()
38     
39     def _directoryChanged(self, directory):
40         self._destinationFolder = str(directory)
41         self._setProjectPath()
42     
43     def _setProjectPath(self):
44         if self._destinationFolder <> "" and self._projectName <> "":
45             if not self._destinationFolder.endswith(os.sep):
46                 self._destinationFolder += os.sep
47             self.pageContent.projectPath.setText(self._destinationFolder + self._projectName + "/")
48         else:
49             self.pageContent.projectPath.setText("None")
50         self.emit(SIGNAL("completeChanged()"))
51     
52     def _selectDirectory(self):
53         directory = QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), "", QFileDialog.ShowDirsOnly)
54         self.pageContent.directoryEdit.setText(directory)
55     
56     def isComplete(self):
57         return self.pageContent.projectPath.text() != "None"