|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2002 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the project properties dialog. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 from PyQt4.QtCore import * |
|
13 from PyQt4.QtGui import * |
|
14 |
|
15 from E4Gui.E4Application import e4App |
|
16 |
|
17 from E4Gui.E4Completers import E4FileCompleter, E4DirCompleter |
|
18 |
|
19 from Ui_PropertiesDialog import Ui_PropertiesDialog |
|
20 from TranslationPropertiesDialog import TranslationPropertiesDialog |
|
21 from SpellingPropertiesDialog import SpellingPropertiesDialog |
|
22 |
|
23 from VCS.RepositoryInfoDialog import VcsRepositoryInfoDialog |
|
24 |
|
25 import Preferences |
|
26 import Utilities |
|
27 |
|
28 class PropertiesDialog(QDialog, Ui_PropertiesDialog): |
|
29 """ |
|
30 Class implementing the project properties dialog. |
|
31 """ |
|
32 def __init__(self, project, new = True, parent = None, name = None): |
|
33 """ |
|
34 Constructor |
|
35 |
|
36 @param project reference to the project object |
|
37 @param new flag indicating the generation of a new project |
|
38 @param parent parent widget of this dialog (QWidget) |
|
39 @param name name of this dialog (string) |
|
40 """ |
|
41 QDialog.__init__(self, parent) |
|
42 if name: |
|
43 self.setObjectName(name) |
|
44 self.setupUi(self) |
|
45 |
|
46 self.project = project |
|
47 self.newProject = new |
|
48 self.transPropertiesDlg = None |
|
49 self.spellPropertiesDlg = None |
|
50 |
|
51 self.dirCompleter = E4DirCompleter(self.dirEdit) |
|
52 self.mainscriptCompleter = E4FileCompleter(self.mainscriptEdit) |
|
53 |
|
54 projectLanguages = sorted( |
|
55 e4App().getObject("DebugServer").getSupportedLanguages()) |
|
56 self.languageComboBox.addItems(projectLanguages) |
|
57 |
|
58 projectTypes = project.getProjectTypes() |
|
59 for projectTypeKey in sorted(projectTypes.keys()): |
|
60 self.projectTypeComboBox.addItem(projectTypes[projectTypeKey], |
|
61 QVariant(projectTypeKey)) |
|
62 |
|
63 if not new: |
|
64 name = os.path.splitext(self.project.pfile)[0] |
|
65 self.nameEdit.setText(os.path.basename(name)) |
|
66 self.languageComboBox.setCurrentIndex(\ |
|
67 self.languageComboBox.findText(self.project.pdata["PROGLANGUAGE"][0])) |
|
68 self.mixedLanguageCheckBox.setChecked(self.project.pdata["MIXEDLANGUAGE"][0]) |
|
69 try: |
|
70 curIndex = \ |
|
71 self.projectTypeComboBox.findText(\ |
|
72 projectTypes[self.project.pdata["PROJECTTYPE"][0]]) |
|
73 except KeyError: |
|
74 curIndex = -1 |
|
75 if curIndex == -1: |
|
76 curIndex = self.projectTypeComboBox.findText(projectTypes["Qt4"]) |
|
77 self.projectTypeComboBox.setCurrentIndex(curIndex) |
|
78 self.dirEdit.setText(self.project.ppath) |
|
79 try: |
|
80 self.versionEdit.setText(self.project.pdata["VERSION"][0]) |
|
81 except IndexError: |
|
82 pass |
|
83 try: |
|
84 self.mainscriptEdit.setText(self.project.pdata["MAINSCRIPT"][0]) |
|
85 except IndexError: |
|
86 pass |
|
87 try: |
|
88 self.authorEdit.setText(self.project.pdata["AUTHOR"][0]) |
|
89 except IndexError: |
|
90 pass |
|
91 try: |
|
92 self.emailEdit.setText(self.project.pdata["EMAIL"][0]) |
|
93 except IndexError: |
|
94 pass |
|
95 try: |
|
96 self.descriptionEdit.setPlainText(self.project.pdata["DESCRIPTION"][0]) |
|
97 except LookupError: |
|
98 pass |
|
99 self.vcsLabel.show() |
|
100 if self.project.vcs is not None: |
|
101 vcsSystemsDict = e4App().getObject("PluginManager")\ |
|
102 .getPluginDisplayStrings("version_control") |
|
103 try: |
|
104 vcsSystemDisplay = vcsSystemsDict[self.project.pdata["VCS"][0]] |
|
105 except KeyError: |
|
106 vcsSystemDisplay = "None" |
|
107 self.vcsLabel.setText(\ |
|
108 self.trUtf8("The project is version controlled by <b>{0}</b>.") |
|
109 .format(vcsSystemDisplay)) |
|
110 self.vcsInfoButton.show() |
|
111 else: |
|
112 self.vcsLabel.setText(\ |
|
113 self.trUtf8("The project is not version controlled.")) |
|
114 self.vcsInfoButton.hide() |
|
115 else: |
|
116 self.projectTypeComboBox.setCurrentIndex(\ |
|
117 self.projectTypeComboBox.findText(projectTypes["Qt4"])) |
|
118 hp = os.getcwd() |
|
119 hp = hp + os.sep |
|
120 self.dirEdit.setText(hp) |
|
121 self.versionEdit.setText('0.1') |
|
122 self.vcsLabel.hide() |
|
123 self.vcsInfoButton.hide() |
|
124 |
|
125 @pyqtSlot() |
|
126 def on_dirButton_clicked(self): |
|
127 """ |
|
128 Private slot to display a directory selection dialog. |
|
129 """ |
|
130 directory = QFileDialog.getExistingDirectory(\ |
|
131 self, |
|
132 self.trUtf8("Select project directory"), |
|
133 self.dirEdit.text(), |
|
134 QFileDialog.Options(QFileDialog.ShowDirsOnly)) |
|
135 |
|
136 if directory: |
|
137 self.dirEdit.setText(Utilities.toNativeSeparators(directory)) |
|
138 |
|
139 @pyqtSlot() |
|
140 def on_spellPropertiesButton_clicked(self): |
|
141 """ |
|
142 Private slot to display the spelling properties dialog. |
|
143 """ |
|
144 if self.spellPropertiesDlg is None: |
|
145 self.spellPropertiesDlg = \ |
|
146 SpellingPropertiesDialog(self.project, self.newProject, self) |
|
147 res = self.spellPropertiesDlg.exec_() |
|
148 if res == QDialog.Rejected: |
|
149 self.spellPropertiesDlg.initDialog() # reset the dialogs contents |
|
150 |
|
151 @pyqtSlot() |
|
152 def on_transPropertiesButton_clicked(self): |
|
153 """ |
|
154 Private slot to display the translations properties dialog. |
|
155 """ |
|
156 if self.transPropertiesDlg is None: |
|
157 self.transPropertiesDlg = \ |
|
158 TranslationPropertiesDialog(self.project, self.newProject, self) |
|
159 else: |
|
160 self.transPropertiesDlg.initFilters() |
|
161 res = self.transPropertiesDlg.exec_() |
|
162 if res == QDialog.Rejected: |
|
163 self.transPropertiesDlg.initDialog() # reset the dialogs contents |
|
164 |
|
165 @pyqtSlot() |
|
166 def on_mainscriptButton_clicked(self): |
|
167 """ |
|
168 Private slot to display a file selection dialog. |
|
169 """ |
|
170 dir = self.dirEdit.text() |
|
171 if not dir: |
|
172 dir = QDir.currentPath() |
|
173 patterns = [] |
|
174 for pattern, filetype in self.project.pdata["FILETYPES"].items(): |
|
175 if filetype == "SOURCES": |
|
176 patterns.append(pattern) |
|
177 filters = self.trUtf8("Source Files ({0});;All Files (*)")\ |
|
178 .format(" ".join(patterns)) |
|
179 fn = QFileDialog.getOpenFileName(\ |
|
180 self, |
|
181 self.trUtf8("Select main script file"), |
|
182 dir, |
|
183 filters) |
|
184 |
|
185 if fn: |
|
186 ppath = self.dirEdit.text() |
|
187 if ppath: |
|
188 ppath = QDir(ppath).absolutePath() |
|
189 ppath.append(QDir.separator()) |
|
190 fn.replace(ppath, "") |
|
191 self.mainscriptEdit.setText(Utilities.toNativeSeparators(fn)) |
|
192 |
|
193 @pyqtSlot() |
|
194 def on_vcsInfoButton_clicked(self): |
|
195 """ |
|
196 Private slot to display a vcs information dialog. |
|
197 """ |
|
198 if self.project.vcs is None: |
|
199 return |
|
200 |
|
201 info = self.project.vcs.vcsRepositoryInfos(self.project.ppath) |
|
202 dlg = VcsRepositoryInfoDialog(self, info) |
|
203 dlg.exec_() |
|
204 |
|
205 def getProjectType(self): |
|
206 """ |
|
207 Public method to get the selected project type. |
|
208 |
|
209 @return selected UI type (string) |
|
210 """ |
|
211 data = self.projectTypeComboBox.itemData(self.projectTypeComboBox.currentIndex()) |
|
212 return data.toString() |
|
213 |
|
214 def getPPath(self): |
|
215 """ |
|
216 Public method to get the project path. |
|
217 |
|
218 @return data of the project directory edit (string) |
|
219 """ |
|
220 return os.path.abspath(self.dirEdit.text()) |
|
221 |
|
222 def storeData(self): |
|
223 """ |
|
224 Public method to store the entered/modified data. |
|
225 """ |
|
226 self.project.ppath = os.path.abspath(self.dirEdit.text()) |
|
227 fn = self.nameEdit.text() |
|
228 if fn: |
|
229 self.project.name = fn |
|
230 if Preferences.getProject("CompressedProjectFiles"): |
|
231 fn = "%s.e4pz" % fn |
|
232 else: |
|
233 fn = "%s.e4p" % fn |
|
234 self.project.pfile = os.path.join(self.project.ppath, fn) |
|
235 else: |
|
236 self.project.pfile = "" |
|
237 self.project.pdata["VERSION"] = [self.versionEdit.text()] |
|
238 fn = self.mainscriptEdit.text() |
|
239 if fn: |
|
240 fn = fn.replace(self.project.ppath+os.sep, "") |
|
241 self.project.pdata["MAINSCRIPT"] = [fn] |
|
242 self.project.translationsRoot = os.path.splitext(fn)[0] |
|
243 else: |
|
244 self.project.pdata["MAINSCRIPT"] = [] |
|
245 self.project.translationsRoot = "" |
|
246 self.project.pdata["AUTHOR"] = [self.authorEdit.text()] |
|
247 self.project.pdata["EMAIL"] = [self.emailEdit.text()] |
|
248 self.project.pdata["DESCRIPTION"] = [self.descriptionEdit.toPlainText()] |
|
249 self.project.pdata["PROGLANGUAGE"] = \ |
|
250 [self.languageComboBox.currentText()] |
|
251 self.project.pdata["MIXEDLANGUAGE"] = [self.mixedLanguageCheckBox.isChecked()] |
|
252 projectType = self.getProjectType() |
|
253 if projectType is not None: |
|
254 self.project.pdata["PROJECTTYPE"] = [projectType] |
|
255 |
|
256 if self.spellPropertiesDlg is not None: |
|
257 self.spellPropertiesDlg.storeData() |
|
258 |
|
259 if self.transPropertiesDlg is not None: |
|
260 self.transPropertiesDlg.storeData() |