Correct errors under Windows
[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     
31     ## Overloaded QWizardPage methods ##
32
33     def isComplete(self):
34         """
35         Overload of the QWizardPage isComplete method.
36         """
37         if self.pageContent.projectPath.text() != "None":
38             self.setProjectInfo("PROJECT_PATH", unicode(self.pageContent.projectPath.text()))
39             return True
40         else:
41             return False
42     
43     ####
44
45     ## Overloaded BWizardPage methods ##
46
47     def setupUi(self):
48         """
49         Overload of the BWizardPage setupUi method.
50         """
51         self.pageContent.warningLabel.setVisible(False)
52     
53     def connectSignals(self):
54         """
55         Overload of the BWizardPage connectSignals method.
56         """
57         self.connect(self.pageContent.nameEdit, SIGNAL("textChanged(const QString)"), self.nameChanged)
58         self.connect(self.pageContent.directoryEdit, SIGNAL("textChanged(const QString)"), self.directoryChanged)
59         self.connect(self.pageContent.directoryButton, SIGNAL("clicked()"), self.selectDirectory)
60     
61     ####
62
63     ## Slots ##
64     
65     def nameChanged(self, name):
66         """
67         Slot called when the project name is changed manually by the user.
68         """
69         self._project_name = str(name).replace(" ", "_")
70         self.setProjectPath()
71     
72     def directoryChanged(self, directory):
73         """
74         Slot called when the project folder is changed manually by the user.
75         """
76         self._destination_folder = str(QDir.toNativeSeparators(directory))
77         self.setProjectPath()
78
79     def selectDirectory(self):
80         """
81         Slot called when the project folder is changed using the file dialog.
82         """
83         directory = unicode(QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), "", QFileDialog.ShowDirsOnly))
84         if len(directory) > 0:
85             self.pageContent.directoryEdit.setText(directory)
86
87     ####
88     
89     def initializeAttributes(self):
90         """
91         Initializes the page attributes to the default values.
92         """
93         self._project_name = ""
94         self._destination_folder = os.path.expanduser("~")
95         self.pageContent.directoryEdit.setText(self._destination_folder)
96     
97     def setProjectPath(self):
98         """
99         Analyzes the page attributes and generates the path string.
100         """
101         if self._destination_folder != "" and self._project_name <> "":
102             if not self._destination_folder.endswith(os.sep):
103                 self._destination_folder += os.sep
104             self.pageContent.projectPath.setText(QDir.toNativeSeparators(self._destination_folder + self._project_name))
105             if os.path.exists(self._destination_folder + self._project_name):
106                 self.pageContent.warningLabel.setVisible(True)
107                 self.pageContent.warningLabel.setText(self.tr("<font color='#FF0000'>Warning: the selected directory exists, \
108                     it will be destroyed with all contained subdirectories and files...</font>"))
109             else:
110                 self.pageContent.warningLabel.setVisible(False)
111                 self.pageContent.warningLabel.setText("")
112         else:
113             self.pageContent.projectPath.setText("None")
114             self.pageContent.warningLabel.setVisible(False)
115             self.pageContent.warningLabel.setText("")
116         self.emit(SIGNAL("completeChanged()"))