Change the indentation
[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 from const import *
19
20 class BFolderPage(BWizardPage):
21     
22     def __init__(self):
23         BWizardPage.__init__(self, UI_LOCATION + "/dir_select.ui")
24         self.setTitle(self.tr("Select the project name"))
25         self._initializeAttributes()
26         self._setupUi()
27         self._connectSignals()
28
29     def _setupUi(self):
30         self.pageContent.warningLabel.setVisible(False)
31     
32     def _initializeAttributes(self):
33         self._projectName = ""
34         self._destinationFolder = os.path.expanduser("~")
35         self.pageContent.directoryEdit.setText(self._destinationFolder)
36     
37     def _connectSignals(self):
38         self.connect(self.pageContent.nameEdit, SIGNAL("textChanged(const QString)"), self._nameChanged)
39         self.connect(self.pageContent.directoryEdit, SIGNAL("textChanged(const QString)"), self._directoryChanged)
40         self.connect(self.pageContent.directoryButton, SIGNAL("clicked()"), self._selectDirectory)
41     
42     def _nameChanged(self, name):
43         self._projectName = str(name).replace(" ", "_")
44         self._setProjectPath()
45     
46     def _directoryChanged(self, directory):
47         self._destinationFolder = str(directory)
48         self._setProjectPath()
49     
50     def _setProjectPath(self):
51         if self._destinationFolder != "" and self._projectName <> "":
52             if not self._destinationFolder.endswith(os.sep):
53                 self._destinationFolder += os.sep
54             self.pageContent.projectPath.setText(self._destinationFolder + self._projectName)
55             if os.path.exists(self._destinationFolder + self._projectName):
56                 self.pageContent.warningLabel.setVisible(True)
57                 self.pageContent.warningLabel.setText(self.tr("<font color='#FF0000'>Warning: the selected directory exists, \
58                     it will be destroyed with all contained subdirectories and files...</font>"))
59             else:
60                 self.pageContent.warningLabel.setVisible(False)
61                 self.pageContent.warningLabel.setText("")
62         else:
63             self.pageContent.projectPath.setText("None")
64             self.pageContent.warningLabel.setVisible(False)
65             self.pageContent.warningLabel.setText("")
66         self.emit(SIGNAL("completeChanged()"))
67     
68     def _selectDirectory(self):
69         directory = unicode(QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), "", QFileDialog.ShowDirsOnly))
70         if len(directory) == "":
71             self.pageContent.directoryEdit.setText(directory)
72     
73     def isComplete(self):
74         if self.pageContent.projectPath.text() != "None":
75             self._projectInfoStore("PROJECT_PATH", unicode(self.pageContent.projectPath.text()))
76             return True
77         else:
78             return False