|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2002 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the project properties dialog. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 import os |
|
13 |
|
14 from PyQt5.QtCore import QDir, pyqtSlot |
|
15 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
16 |
|
17 from E5Gui.E5Application import e5App |
|
18 from E5Gui.E5PathPicker import E5PathPickerModes |
|
19 |
|
20 from .Ui_PropertiesDialog import Ui_PropertiesDialog |
|
21 |
|
22 import Utilities |
|
23 import Preferences |
|
24 import UI.PixmapCache |
|
25 |
|
26 |
|
27 class PropertiesDialog(QDialog, Ui_PropertiesDialog): |
|
28 """ |
|
29 Class implementing the project properties dialog. |
|
30 """ |
|
31 def __init__(self, project, new=True, parent=None, name=None): |
|
32 """ |
|
33 Constructor |
|
34 |
|
35 @param project reference to the project object |
|
36 @param new flag indicating the generation of a new project |
|
37 @param parent parent widget of this dialog (QWidget) |
|
38 @param name name of this dialog (string) |
|
39 """ |
|
40 super(PropertiesDialog, self).__init__(parent) |
|
41 if name: |
|
42 self.setObjectName(name) |
|
43 self.setupUi(self) |
|
44 |
|
45 self.dirPicker.setMode(E5PathPickerModes.DirectoryMode) |
|
46 self.mainscriptPicker.setMode(E5PathPickerModes.OpenFileMode) |
|
47 |
|
48 self.makeButton.setIcon(UI.PixmapCache.getIcon("makefile.png")) |
|
49 |
|
50 self.project = project |
|
51 self.newProject = new |
|
52 self.transPropertiesDlg = None |
|
53 self.spellPropertiesDlg = None |
|
54 self.makePropertiesDlg = None |
|
55 |
|
56 patterns = [] |
|
57 for pattern, filetype in self.project.pdata["FILETYPES"].items(): |
|
58 if filetype == "SOURCES": |
|
59 patterns.append(pattern) |
|
60 filters = self.tr("Source Files ({0});;All Files (*)")\ |
|
61 .format(" ".join(sorted(patterns))) |
|
62 self.mainscriptPicker.setFilters(filters) |
|
63 |
|
64 self.languageComboBox.addItems(project.getProgrammingLanguages()) |
|
65 |
|
66 projectTypes = [] |
|
67 for projectTypeItem in project.getProjectTypes().items(): |
|
68 projectTypes.append((projectTypeItem[1], projectTypeItem[0])) |
|
69 self.projectTypeComboBox.clear() |
|
70 for projectType in sorted(projectTypes): |
|
71 self.projectTypeComboBox.addItem( |
|
72 projectType[0], projectType[1]) |
|
73 |
|
74 ipath = Preferences.getMultiProject("Workspace") or \ |
|
75 Utilities.getHomeDir() |
|
76 self.__initPaths = [ |
|
77 Utilities.fromNativeSeparators(ipath), |
|
78 Utilities.fromNativeSeparators(ipath) + "/", |
|
79 ] |
|
80 |
|
81 if not new: |
|
82 name = os.path.splitext(self.project.pfile)[0] |
|
83 self.nameEdit.setText(os.path.basename(name)) |
|
84 self.languageComboBox.setCurrentIndex( |
|
85 self.languageComboBox.findText( |
|
86 self.project.pdata["PROGLANGUAGE"])) |
|
87 self.mixedLanguageCheckBox.setChecked( |
|
88 self.project.pdata["MIXEDLANGUAGE"]) |
|
89 curIndex = self.projectTypeComboBox.findData( |
|
90 self.project.pdata["PROJECTTYPE"]) |
|
91 if curIndex == -1: |
|
92 curIndex = self.projectTypeComboBox.findData("Qt4") |
|
93 self.projectTypeComboBox.setCurrentIndex(curIndex) |
|
94 self.dirPicker.setText(self.project.ppath) |
|
95 self.versionEdit.setText(self.project.pdata["VERSION"]) |
|
96 self.mainscriptPicker.setText(self.project.pdata["MAINSCRIPT"]) |
|
97 self.authorEdit.setText(self.project.pdata["AUTHOR"]) |
|
98 self.emailEdit.setText(self.project.pdata["EMAIL"]) |
|
99 self.descriptionEdit.setPlainText( |
|
100 self.project.pdata["DESCRIPTION"]) |
|
101 self.eolComboBox.setCurrentIndex(self.project.pdata["EOL"]) |
|
102 self.vcsLabel.show() |
|
103 if self.project.vcs is not None: |
|
104 vcsSystemsDict = e5App().getObject("PluginManager")\ |
|
105 .getPluginDisplayStrings("version_control") |
|
106 try: |
|
107 vcsSystemDisplay = \ |
|
108 vcsSystemsDict[self.project.pdata["VCS"]] |
|
109 except KeyError: |
|
110 vcsSystemDisplay = "None" |
|
111 self.vcsLabel.setText( |
|
112 self.tr( |
|
113 "The project is version controlled by <b>{0}</b>.") |
|
114 .format(vcsSystemDisplay)) |
|
115 self.vcsInfoButton.show() |
|
116 else: |
|
117 self.vcsLabel.setText( |
|
118 self.tr("The project is not version controlled.")) |
|
119 self.vcsInfoButton.hide() |
|
120 self.vcsCheckBox.hide() |
|
121 self.makeCheckBox.setChecked( |
|
122 self.project.pdata["MAKEPARAMS"]["MakeEnabled"]) |
|
123 else: |
|
124 self.languageComboBox.setCurrentIndex( |
|
125 self.languageComboBox.findText("Python3")) |
|
126 self.projectTypeComboBox.setCurrentIndex( |
|
127 self.projectTypeComboBox.findData("PyQt5")) |
|
128 self.dirPicker.setText(self.__initPaths[0]) |
|
129 self.versionEdit.setText('0.1') |
|
130 self.vcsLabel.hide() |
|
131 self.vcsInfoButton.hide() |
|
132 if not self.project.vcsSoftwareAvailable(): |
|
133 self.vcsCheckBox.hide() |
|
134 |
|
135 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
|
136 bool(self.dirPicker.text()) and |
|
137 self.dirPicker.text() not in self.__initPaths) |
|
138 |
|
139 @pyqtSlot(str) |
|
140 def on_languageComboBox_currentIndexChanged(self, language): |
|
141 """ |
|
142 Private slot handling the selection of a programming language. |
|
143 |
|
144 @param language selected programming language (string) |
|
145 """ |
|
146 curProjectType = self.getProjectType() |
|
147 |
|
148 projectTypes = [] |
|
149 for projectTypeItem in self.project.getProjectTypes().items(): |
|
150 projectTypes.append((projectTypeItem[1], projectTypeItem[0])) |
|
151 self.projectTypeComboBox.clear() |
|
152 for projectType in sorted(projectTypes): |
|
153 self.projectTypeComboBox.addItem( |
|
154 projectType[0], projectType[1]) |
|
155 |
|
156 index = self.projectTypeComboBox.findData(curProjectType) |
|
157 if index == -1: |
|
158 index = 0 |
|
159 self.projectTypeComboBox.setCurrentIndex(index) |
|
160 |
|
161 @pyqtSlot(str) |
|
162 def on_dirPicker_textChanged(self, txt): |
|
163 """ |
|
164 Private slot to handle a change of the project directory. |
|
165 |
|
166 @param txt name of the project directory (string) |
|
167 """ |
|
168 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
|
169 bool(txt) and |
|
170 Utilities.fromNativeSeparators(txt) not in self.__initPaths) |
|
171 |
|
172 @pyqtSlot() |
|
173 def on_spellPropertiesButton_clicked(self): |
|
174 """ |
|
175 Private slot to display the spelling properties dialog. |
|
176 """ |
|
177 if self.spellPropertiesDlg is None: |
|
178 from .SpellingPropertiesDialog import SpellingPropertiesDialog |
|
179 self.spellPropertiesDlg = \ |
|
180 SpellingPropertiesDialog(self.project, self.newProject, self) |
|
181 res = self.spellPropertiesDlg.exec_() |
|
182 if res == QDialog.Rejected: |
|
183 self.spellPropertiesDlg.initDialog() # reset the dialogs contents |
|
184 |
|
185 @pyqtSlot() |
|
186 def on_transPropertiesButton_clicked(self): |
|
187 """ |
|
188 Private slot to display the translations properties dialog. |
|
189 """ |
|
190 if self.transPropertiesDlg is None: |
|
191 from .TranslationPropertiesDialog import \ |
|
192 TranslationPropertiesDialog |
|
193 self.transPropertiesDlg = \ |
|
194 TranslationPropertiesDialog(self.project, self.newProject, |
|
195 self) |
|
196 else: |
|
197 self.transPropertiesDlg.initFilters() |
|
198 res = self.transPropertiesDlg.exec_() |
|
199 if res == QDialog.Rejected: |
|
200 self.transPropertiesDlg.initDialog() # reset the dialogs contents |
|
201 |
|
202 @pyqtSlot() |
|
203 def on_makeButton_clicked(self): |
|
204 """ |
|
205 Private slot to display the make properties dialog. |
|
206 """ |
|
207 if self.makePropertiesDlg is None: |
|
208 from .MakePropertiesDialog import MakePropertiesDialog |
|
209 self.makePropertiesDlg = \ |
|
210 MakePropertiesDialog(self.project, self.newProject, self) |
|
211 res = self.makePropertiesDlg.exec_() |
|
212 if res == QDialog.Rejected: |
|
213 self.makePropertiesDlg.initDialog() |
|
214 |
|
215 @pyqtSlot(str) |
|
216 def on_mainscriptPicker_pathSelected(self, script): |
|
217 """ |
|
218 Private slot to check the selected main script name. |
|
219 |
|
220 @param script name of the main script |
|
221 @type str |
|
222 """ |
|
223 if script: |
|
224 ppath = self.dirPicker.text() |
|
225 if ppath: |
|
226 ppath = QDir(ppath).absolutePath() + QDir.separator() |
|
227 script = script.replace(ppath, "") |
|
228 self.mainscriptPicker.setText(script) |
|
229 |
|
230 @pyqtSlot() |
|
231 def on_mainscriptPicker_aboutToShowPathPickerDialog(self): |
|
232 """ |
|
233 Private slot to perform actions before the main script selection dialog |
|
234 is shown. |
|
235 """ |
|
236 path = self.dirPicker.text() |
|
237 if not path: |
|
238 path = QDir.currentPath() |
|
239 self.mainscriptPicker.setDefaultDirectory(path) |
|
240 |
|
241 @pyqtSlot() |
|
242 def on_vcsInfoButton_clicked(self): |
|
243 """ |
|
244 Private slot to display a vcs information dialog. |
|
245 """ |
|
246 if self.project.vcs is None: |
|
247 return |
|
248 |
|
249 from VCS.RepositoryInfoDialog import VcsRepositoryInfoDialog |
|
250 info = self.project.vcs.vcsRepositoryInfos(self.project.ppath) |
|
251 dlg = VcsRepositoryInfoDialog(self, info) |
|
252 dlg.exec_() |
|
253 |
|
254 def getProjectType(self): |
|
255 """ |
|
256 Public method to get the selected project type. |
|
257 |
|
258 @return selected UI type (string) |
|
259 """ |
|
260 return self.projectTypeComboBox.itemData( |
|
261 self.projectTypeComboBox.currentIndex()) |
|
262 |
|
263 def getPPath(self): |
|
264 """ |
|
265 Public method to get the project path. |
|
266 |
|
267 @return data of the project directory edit (string) |
|
268 """ |
|
269 return os.path.abspath(self.dirPicker.text()) |
|
270 |
|
271 def storeData(self): |
|
272 """ |
|
273 Public method to store the entered/modified data. |
|
274 """ |
|
275 self.project.ppath = os.path.abspath(self.dirPicker.text()) |
|
276 fn = self.nameEdit.text() |
|
277 if fn: |
|
278 self.project.name = fn |
|
279 fn = "{0}.e4p".format(fn) |
|
280 self.project.pfile = os.path.join(self.project.ppath, fn) |
|
281 else: |
|
282 self.project.pfile = "" |
|
283 self.project.pdata["VERSION"] = self.versionEdit.text() |
|
284 fn = self.mainscriptPicker.text() |
|
285 if fn: |
|
286 fn = self.project.getRelativePath(fn) |
|
287 self.project.pdata["MAINSCRIPT"] = fn |
|
288 self.project.translationsRoot = os.path.splitext(fn)[0] |
|
289 else: |
|
290 self.project.pdata["MAINSCRIPT"] = "" |
|
291 self.project.translationsRoot = "" |
|
292 self.project.pdata["AUTHOR"] = self.authorEdit.text() |
|
293 self.project.pdata["EMAIL"] = self.emailEdit.text() |
|
294 self.project.pdata["DESCRIPTION"] = self.descriptionEdit.toPlainText() |
|
295 self.project.pdata["PROGLANGUAGE"] = \ |
|
296 self.languageComboBox.currentText() |
|
297 self.project.pdata["MIXEDLANGUAGE"] = \ |
|
298 self.mixedLanguageCheckBox.isChecked() |
|
299 projectType = self.getProjectType() |
|
300 if projectType is not None: |
|
301 self.project.pdata["PROJECTTYPE"] = projectType |
|
302 self.project.pdata["EOL"] = self.eolComboBox.currentIndex() |
|
303 |
|
304 self.project.vcsRequested = self.vcsCheckBox.isChecked() |
|
305 |
|
306 if self.spellPropertiesDlg is not None: |
|
307 self.spellPropertiesDlg.storeData() |
|
308 |
|
309 if self.transPropertiesDlg is not None: |
|
310 self.transPropertiesDlg.storeData() |
|
311 |
|
312 self.project.pdata["MAKEPARAMS"]["MakeEnabled"] = \ |
|
313 self.makeCheckBox.isChecked() |
|
314 if self.makePropertiesDlg is not None: |
|
315 self.makePropertiesDlg.storeData() |