Add a label that warn the user if the selected directory exists
[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, it will be destroyed with all contained subdirectories and files...</font>"))
58             else:
59                 self.pageContent.warningLabel.setVisible(False)
60                 self.pageContent.warningLabel.setText("")
61         else:
62             self.pageContent.projectPath.setText("None")
63             self.pageContent.warningLabel.setVisible(False)
64             self.pageContent.warningLabel.setText("")
65         self.emit(SIGNAL("completeChanged()"))
66     
67     def _selectDirectory(self):
68         directory = unicode(QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), "", QFileDialog.ShowDirsOnly))
69         if len(directory) == "":
70             self.pageContent.directoryEdit.setText(directory)
71     
72     def isComplete(self):
73         if self.pageContent.projectPath.text() != "None":
74             self._projectInfoStore("PROJECT_PATH", unicode(self.pageContent.projectPath.text()))
75             return True
76         else:
77             return False