Add comment for each method and class
[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     Initial page of the wizard. Permit to select the project name and the directory
23     where the project will be created.
24     """
25     
26     def __init__(self):
27         BWizardPage.__init__(self, UI_LOCATION + "/dir_select.ui")
28         self.setTitle(self.tr("Select the project name"))
29         self._initializeAttributes()
30         self._setupUi()
31         self._connectSignals()
32
33     def _setupUi(self):
34         """
35         Sets up the user interface.
36         """
37         self.pageContent.warningLabel.setVisible(False)
38     
39     def _initializeAttributes(self):
40         """
41         Initializes the page attributes to the default values.
42         """
43         self._project_name = ""
44         self._destination_folder = os.path.expanduser("~")
45         self.pageContent.directoryEdit.setText(self._destination_folder)
46     
47     def _connectSignals(self):
48         """
49         Connects the signals to the related slots.
50         """
51         self.connect(self.pageContent.nameEdit, SIGNAL("textChanged(const QString)"), self._nameChanged)
52         self.connect(self.pageContent.directoryEdit, SIGNAL("textChanged(const QString)"), self._directoryChanged)
53         self.connect(self.pageContent.directoryButton, SIGNAL("clicked()"), self._selectDirectory)
54     
55     def _nameChanged(self, name):
56         """
57         Slot called when the project name is changed manually by the user.
58         """
59         self._project_name = str(name).replace(" ", "_")
60         self._setProjectPath()
61     
62     def _directoryChanged(self, directory):
63         """
64         Slot called when the project folder is changed manually by the user.
65         """
66         self._destination_folder = str(QDir.toNativeSeparators(directory))
67         self._setProjectPath()
68     
69     def _setProjectPath(self):
70         """
71         Analyzes the page attributes and generates the path string.
72         """
73         if self._destination_folder != "" and self._project_name <> "":
74             if not self._destination_folder.endswith(os.sep):
75                 self._destination_folder += "/"
76             self.pageContent.projectPath.setText(QDir.toNativeSeparators(self._destination_folder + self._project_name))
77             if os.path.exists(self._destination_folder + self._project_name):
78                 self.pageContent.warningLabel.setVisible(True)
79                 self.pageContent.warningLabel.setText(self.tr("<font color='#FF0000'>Warning: the selected directory exists, \
80                     it will be destroyed with all contained subdirectories and files...</font>"))
81             else:
82                 self.pageContent.warningLabel.setVisible(False)
83                 self.pageContent.warningLabel.setText("")
84         else:
85             self.pageContent.projectPath.setText("None")
86             self.pageContent.warningLabel.setVisible(False)
87             self.pageContent.warningLabel.setText("")
88         self.emit(SIGNAL("completeChanged()"))
89     
90     def _selectDirectory(self):
91         """
92         Slot called when the project folder is changed using the file dialog.
93         """
94         directory = unicode(QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), "", QFileDialog.ShowDirsOnly))
95         if len(directory) > 0:
96             self.pageContent.directoryEdit.setText(directory)
97     
98     def isComplete(self):
99         """
100         Overload of the QWizardPage isComplete method.
101         """
102         if self.pageContent.projectPath.text() != "None":
103             self._projectInfoStore("PROJECT_PATH", unicode(self.pageContent.projectPath.text()))
104             return True
105         else:
106             return False