X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=wizard%2FBFolderPage.py;h=4e1174457fd71bc7a95d26521068a5ce872625c9;hb=166b09310df7d5829ea832c707278dd38bff8a2d;hp=a14dda2f5d000e8c358b77d5904d2a29ad5fc853;hpb=320721d8b6cab26650cbd91a4accb61f66ff0e62;p=bertos.git diff --git a/wizard/BFolderPage.py b/wizard/BFolderPage.py index a14dda2f..4e117445 100644 --- a/wizard/BFolderPage.py +++ b/wizard/BFolderPage.py @@ -4,7 +4,7 @@ # Copyright 2008 Develer S.r.l. (http://www.develer.com/) # All rights reserved. # -# $Id:$ +# $Id$ # # Author: Lorenzo Berni # @@ -18,43 +18,99 @@ import bertos_utils from const import * class BFolderPage(BWizardPage): + """ + Initial page of the wizard. Permit to select the project name and the directory + where the project will be created. + """ def __init__(self): BWizardPage.__init__(self, UI_LOCATION + "/dir_select.ui") self.setTitle(self.tr("Select the project name")) - self._initializeAttributes() - self._setupUi() - self._connectSignals() + self.initializeAttributes() + + ## Overloaded QWizardPage methods ## + + def isComplete(self): + """ + Overload of the QWizardPage isComplete method. + """ + self.setDefaultFolder(self._destination_folder) + if self.pageContent.projectPath.text() != "None": + self.setProjectInfo("PROJECT_PATH", unicode(self.pageContent.projectPath.text())) + return True + else: + return False + + #### + + ## Overloaded BWizardPage methods ## - def _setupUi(self): + def setupUi(self): + """ + Overload of the BWizardPage setupUi method. + """ self.pageContent.warningLabel.setVisible(False) - def _initializeAttributes(self): - self._projectName = "" - self._destinationFolder = os.path.expanduser("~") - self.pageContent.directoryEdit.setText(self._destinationFolder) + def connectSignals(self): + """ + Overload of the BWizardPage connectSignals method. + """ + self.connect(self.pageContent.nameEdit, SIGNAL("textChanged(const QString)"), self.nameChanged) + self.connect(self.pageContent.directoryEdit, SIGNAL("textChanged(const QString)"), self.directoryChanged) + self.connect(self.pageContent.directoryButton, SIGNAL("clicked()"), self.selectDirectory) - def _connectSignals(self): - self.connect(self.pageContent.nameEdit, SIGNAL("textChanged(const QString)"), self._nameChanged) - self.connect(self.pageContent.directoryEdit, SIGNAL("textChanged(const QString)"), self._directoryChanged) - self.connect(self.pageContent.directoryButton, SIGNAL("clicked()"), self._selectDirectory) + #### + + ## Slots ## - def _nameChanged(self, name): - self._projectName = str(name).replace(" ", "_") - self._setProjectPath() + def nameChanged(self, name): + """ + Slot called when the project name is changed manually by the user. + """ + self._project_name = str(name).replace(" ", "_") + self.setProjectPath() - def _directoryChanged(self, directory): - self._destinationFolder = str(directory) - self._setProjectPath() + def directoryChanged(self, directory): + """ + Slot called when the project folder is changed manually by the user. + """ + self._destination_folder = str(QDir.toNativeSeparators(directory)) + self.setProjectPath() + + def selectDirectory(self): + """ + Slot called when the project folder is changed using the file dialog. + """ + directory = unicode(QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), "", QFileDialog.ShowDirsOnly)) + if len(directory) > 0: + self.pageContent.directoryEdit.setText(directory) + + #### + + def initializeAttributes(self): + """ + Initializes the page attributes to the default values. + """ + self._project_name = "" + stored_folder = self.defaultFolder() + if stored_folder != "": + self._destination_folder = stored_folder + else: + self._destination_folder = os.path.expanduser("~") + self.pageContent.directoryEdit.setText(self._destination_folder) - def _setProjectPath(self): - if self._destinationFolder != "" and self._projectName <> "": - if not self._destinationFolder.endswith(os.sep): - self._destinationFolder += os.sep - self.pageContent.projectPath.setText(self._destinationFolder + self._projectName) - if os.path.exists(self._destinationFolder + self._projectName): + def setProjectPath(self): + """ + Analyzes the page attributes and generates the path string. + """ + if self._destination_folder != "" and self._project_name <> "": + if not self._destination_folder.endswith(os.sep): + self._destination_folder += os.sep + self.pageContent.projectPath.setText(QDir.toNativeSeparators(self._destination_folder + self._project_name)) + if os.path.exists(self._destination_folder + self._project_name): self.pageContent.warningLabel.setVisible(True) - self.pageContent.warningLabel.setText(self.tr("Warning: the selected directory exists, it will be destroyed with all contained subdirectories and files...")) + self.pageContent.warningLabel.setText(self.tr("Warning: the selected directory exists, \ + it will be destroyed with all contained subdirectories and files...")) else: self.pageContent.warningLabel.setVisible(False) self.pageContent.warningLabel.setText("") @@ -63,15 +119,3 @@ class BFolderPage(BWizardPage): self.pageContent.warningLabel.setVisible(False) self.pageContent.warningLabel.setText("") self.emit(SIGNAL("completeChanged()")) - - def _selectDirectory(self): - directory = unicode(QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), "", QFileDialog.ShowDirsOnly)) - if len(directory) == "": - self.pageContent.directoryEdit.setText(directory) - - def isComplete(self): - if self.pageContent.projectPath.text() != "None": - self._projectInfoStore("PROJECT_PATH", unicode(self.pageContent.projectPath.text())) - return True - else: - return False \ No newline at end of file