If an empty string is returned by the filedialog it does nothing
[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 = os.path.expanduser("~")
29         self.pageContent.directoryEdit.setText(self._destinationFolder)
30     
31     def _connectSignals(self):
32         self.connect(self.pageContent.nameEdit, SIGNAL("textChanged(const QString)"), self._nameChanged)
33         self.connect(self.pageContent.directoryEdit, SIGNAL("textChanged(const QString)"), self._directoryChanged)
34         self.connect(self.pageContent.directoryButton, SIGNAL("clicked()"), self._selectDirectory)
35     
36     def _nameChanged(self, name):
37         self._projectName = str(name).replace(" ", "_")
38         self._setProjectPath()
39     
40     def _directoryChanged(self, directory):
41         self._destinationFolder = str(directory)
42         self._setProjectPath()
43     
44     def _setProjectPath(self):
45         if self._destinationFolder != "" and self._projectName <> "":
46             if not self._destinationFolder.endswith(os.sep):
47                 self._destinationFolder += os.sep
48             self.pageContent.projectPath.setText(self._destinationFolder + self._projectName + "/")
49         else:
50             self.pageContent.projectPath.setText("None")
51         self.emit(SIGNAL("completeChanged()"))
52     
53     def _selectDirectory(self):
54         directory = unicode(QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), "", QFileDialog.ShowDirsOnly))
55         if len(directory) == "":
56             self.pageContent.directoryEdit.setText(directory)
57     
58     def isComplete(self):
59         if self.pageContent.projectPath.text() != "None":
60             self._projectInfoStore("PROJECT_PATH", self.pageContent.projectPath.text())
61             return True
62         else:
63             return False