4 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
9 # Author: Lorenzo Berni <duplo@develer.com>
14 from PyQt4.QtGui import *
15 from BWizardPage import *
20 class BFolderPage(BWizardPage):
22 Initial page of the wizard. Permit to select the project name and the directory
23 where the project will be created.
27 BWizardPage.__init__(self, UI_LOCATION + "/dir_select.ui")
28 self.setTitle(self.tr("Select the project name"))
29 self._initializeAttributes()
31 self._connectSignals()
35 Sets up the user interface.
37 self.pageContent.warningLabel.setVisible(False)
39 def _initializeAttributes(self):
41 Initializes the page attributes to the default values.
43 self._project_name = ""
44 self._destination_folder = os.path.expanduser("~")
45 self.pageContent.directoryEdit.setText(self._destination_folder)
47 def _connectSignals(self):
49 Connects the signals to the related slots.
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)
55 def _nameChanged(self, name):
57 Slot called when the project name is changed manually by the user.
59 self._project_name = str(name).replace(" ", "_")
60 self._setProjectPath()
62 def _directoryChanged(self, directory):
64 Slot called when the project folder is changed manually by the user.
66 self._destination_folder = str(QDir.toNativeSeparators(directory))
67 self._setProjectPath()
69 def _setProjectPath(self):
71 Analyzes the page attributes and generates the path string.
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>"))
82 self.pageContent.warningLabel.setVisible(False)
83 self.pageContent.warningLabel.setText("")
85 self.pageContent.projectPath.setText("None")
86 self.pageContent.warningLabel.setVisible(False)
87 self.pageContent.warningLabel.setText("")
88 self.emit(SIGNAL("completeChanged()"))
90 def _selectDirectory(self):
92 Slot called when the project folder is changed using the file dialog.
94 directory = unicode(QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), "", QFileDialog.ShowDirsOnly))
95 if len(directory) > 0:
96 self.pageContent.directoryEdit.setText(directory)
100 Overload of the QWizardPage isComplete method.
102 if self.pageContent.projectPath.text() != "None":
103 self._projectInfoStore("PROJECT_PATH", unicode(self.pageContent.projectPath.text()))