X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=wizard%2FBFolderPage.py;h=0539c62b5f5ba137e420dbb0b0fabeeda2d3fffb;hb=81f2387d160fee072af03291b5682a06f5b807cd;hp=b98c5ee4e3132a23b2c8fab2e8a096c1b9625a16;hpb=76a48f1d3021b18df251ee4992c6b3973befbd87;p=bertos.git diff --git a/wizard/BFolderPage.py b/wizard/BFolderPage.py index b98c5ee4..0539c62b 100644 --- a/wizard/BFolderPage.py +++ b/wizard/BFolderPage.py @@ -4,25 +4,123 @@ # Copyright 2008 Develer S.r.l. (http://www.develer.com/) # All rights reserved. # -# $Id:$ +# $Id$ # # Author: Lorenzo Berni # +import os + from PyQt4.QtGui import * from BWizardPage import * 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, "dir_select.ui") - self.setTitle(self.tr("Select the BeRTOS version needed")) - self._folder = "" - self._connectSignals() + BWizardPage.__init__(self, UI_LOCATION + "/dir_select.ui") + self.setTitle(self.tr("Select the project name")) + 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): + """ + Overload of the BWizardPage setupUi method. + """ + self.pageContent.warningLabel.setVisible(False) + + 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) + + #### + + ## Slots ## + + 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): + """ + 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"), self.pageContent.directoryEdit.text(), QFileDialog.ShowDirsOnly)) + if len(directory) > 0: + self.pageContent.directoryEdit.setText(directory) + + #### - def _connectSignals(self): - self.connect(self.pageContent.nameEdit, SIGNAL("textChanged(con QString)"), self._nameChanged) + 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 + elif os.name == "nt": + from win32com.shell import shell, shellcon + self._destination_folder = shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, 0, 0) + del shell + del shellcon + else: + self._destination_folder = os.path.expanduser("~") + self.pageContent.directoryEdit.setText(self._destination_folder) - def _nameChanged(self, name): - print "name changed" \ No newline at end of file + 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...")) + else: + self.pageContent.warningLabel.setVisible(False) + self.pageContent.warningLabel.setText("") + else: + self.pageContent.projectPath.setText("None") + self.pageContent.warningLabel.setVisible(False) + self.pageContent.warningLabel.setText("") + self.emit(SIGNAL("completeChanged()"))