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 ## Overloaded QWizardPage methods ##
35 Overload of the QWizardPage isComplete method.
37 self.setDefaultFolder(self._destination_folder)
38 if self.pageContent.projectPath.text() != "None":
39 self.setProjectInfo("PROJECT_PATH", unicode(self.pageContent.projectPath.text()))
46 ## Overloaded BWizardPage methods ##
50 Overload of the BWizardPage setupUi method.
52 self.pageContent.warningLabel.setVisible(False)
54 def connectSignals(self):
56 Overload of the BWizardPage connectSignals method.
58 self.connect(self.pageContent.nameEdit, SIGNAL("textChanged(const QString)"), self.nameChanged)
59 self.connect(self.pageContent.directoryEdit, SIGNAL("textChanged(const QString)"), self.directoryChanged)
60 self.connect(self.pageContent.directoryButton, SIGNAL("clicked()"), self.selectDirectory)
66 def nameChanged(self, name):
68 Slot called when the project name is changed manually by the user.
70 self._project_name = str(name).replace(" ", "_")
73 def directoryChanged(self, directory):
75 Slot called when the project folder is changed manually by the user.
77 self._destination_folder = str(QDir.toNativeSeparators(directory))
80 def selectDirectory(self):
82 Slot called when the project folder is changed using the file dialog.
84 directory = unicode(QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), self.pageContent.directoryEdit.text(), QFileDialog.ShowDirsOnly))
85 if len(directory) > 0:
86 self.pageContent.directoryEdit.setText(directory)
90 def initializeAttributes(self):
92 Initializes the page attributes to the default values.
94 self._project_name = ""
95 stored_folder = self.defaultFolder()
96 if stored_folder != "":
97 self._destination_folder = stored_folder
99 from win32com.shell import shell, shellcon
100 self._destination_folder = shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, 0, 0)
104 self._destination_folder = os.path.expanduser("~")
105 self.pageContent.directoryEdit.setText(self._destination_folder)
107 def setProjectPath(self):
109 Analyzes the page attributes and generates the path string.
111 if self._destination_folder != "" and self._project_name <> "":
112 if not self._destination_folder.endswith(os.sep):
113 self._destination_folder += os.sep
114 self.pageContent.projectPath.setText(QDir.toNativeSeparators(self._destination_folder + self._project_name))
115 if os.path.exists(self._destination_folder + self._project_name):
116 self.pageContent.warningLabel.setVisible(True)
117 self.pageContent.warningLabel.setText(self.tr("<font color='#FF0000'>Warning: the selected directory exists, \
118 it will be destroyed with all contained subdirectories and files...</font>"))
120 self.pageContent.warningLabel.setVisible(False)
121 self.pageContent.warningLabel.setText("")
123 self.pageContent.projectPath.setText("None")
124 self.pageContent.warningLabel.setVisible(False)
125 self.pageContent.warningLabel.setText("")
126 self.emit(SIGNAL("completeChanged()"))