4 # This file is part of BeRTOS.
6 # Bertos is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction. Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License. This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
33 # Author: Lorenzo Berni <duplo@develer.com>
38 from PyQt4.QtGui import *
39 from BWizardPage import *
42 from BVersionPage import BVersionPage
43 from BBoardPage import BBoardPage
47 class BFolderPage(BWizardPage):
49 Initial page of the wizard. Permit to select the project name and the directory
50 where the project will be created.
54 BWizardPage.__init__(self, UI_LOCATION + "/dir_select.ui")
55 self.setTitle(self.tr("Select the project name"))
56 self.initializeAttributes()
58 ## Overloaded QWizardPage methods ##
62 Overload of the QWizardPage isComplete method.
64 self.setDefaultFolder(self._destination_folder)
65 if self.pageContent.projectPath.text() != "None":
66 self.setProjectInfo("PROJECT_PATH", unicode(self.pageContent.projectPath.text()))
67 self.setProjectInfo("PROJECT_NAME", os.path.basename(unicode(self.pageContent.projectPath.text())))
74 Overload of the QWizardPage nextId method.
76 return self.wizard().pageIndex(self.next_page)
81 ## Overloaded BWizardPage methods ##
85 Overload of the BWizardPage setupUi method.
87 self.pageContent.warningLabel.setVisible(False)
89 def connectSignals(self):
91 Overload of the BWizardPage connectSignals method.
93 self.connect(self.pageContent.nameEdit, SIGNAL("textChanged(const QString)"), self.nameChanged)
94 self.connect(self.pageContent.directoryEdit, SIGNAL("textChanged(const QString)"), self.directoryChanged)
95 self.connect(self.pageContent.directoryButton, SIGNAL("clicked()"), self.selectDirectory)
101 def nameChanged(self, name):
103 Slot called when the project name is changed manually by the user.
106 name = unicode(name).encode("ascii")
107 except UnicodeEncodeError:
108 name = self._project_name
109 self.pageContent.nameEdit.setText(name)
110 self._project_name = unicode(name).replace(" ", "_")
111 self.setProjectPath()
113 def directoryChanged(self, directory):
115 Slot called when the project folder is changed manually by the user.
118 directory = unicode(directory).encode("ascii")
119 except UnicodeEncodeError:
120 directory = self._destination_folder
121 self.pageContent.directoryEdit.setText(directory)
122 self._destination_folder = directory
123 self.setProjectPath()
125 def selectDirectory(self):
127 Slot called when the project folder is changed using the file dialog.
129 directory = unicode(QFileDialog.getExistingDirectory(self, self.tr("Open Directory"), self.pageContent.directoryEdit.text(), QFileDialog.ShowDirsOnly))
130 if len(directory) > 0:
131 self.pageContent.directoryEdit.setText(QDir.toNativeSeparators(directory))
138 Contains the next page class.
140 if self.pageContent.customButton.isChecked():
145 def initializeAttributes(self):
147 Initializes the page attributes to the default values.
149 self._project_name = ""
150 stored_folder = self.defaultFolder()
151 if stored_folder != "":
152 self._destination_folder = stored_folder
153 elif os.name == "nt":
154 from win32com.shell import shell, shellcon
155 self._destination_folder = shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, 0, 0)
159 self._destination_folder = os.path.expanduser("~")
160 self.pageContent.directoryEdit.setText(self._destination_folder)
162 def setProjectPath(self):
164 Analyzes the page attributes and generates the path string.
166 if self._destination_folder != "" and self._project_name <> "":
167 if not self._destination_folder.endswith(os.sep):
168 self._destination_folder += os.sep
169 self.pageContent.projectPath.setText(QDir.toNativeSeparators(self._destination_folder + self._project_name))
170 if os.path.exists(self._destination_folder + self._project_name):
171 self.pageContent.warningLabel.setVisible(True)
172 self.pageContent.warningLabel.setText(self.tr("<font color='#FF0000'>Warning: the selected directory exists, \
173 it will be destroyed with all contained subdirectories and files...</font>"))
175 self.pageContent.warningLabel.setVisible(False)
176 self.pageContent.warningLabel.setText("")
178 self.pageContent.projectPath.setText("None")
179 self.pageContent.warningLabel.setVisible(False)
180 self.pageContent.warningLabel.setText("")
181 self.emit(SIGNAL("completeChanged()"))