|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2003 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the file dialog wizard dialog. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot, QUrl |
|
13 from PyQt5.QtWidgets import ( |
|
14 QDialog, QDialogButtonBox, QFileDialog, QButtonGroup |
|
15 ) |
|
16 |
|
17 from E5Gui.E5Completers import E5FileCompleter, E5DirCompleter |
|
18 |
|
19 from .Ui_FileDialogWizardDialog import Ui_FileDialogWizardDialog |
|
20 |
|
21 import Globals |
|
22 |
|
23 |
|
24 class FileDialogWizardDialog(QDialog, Ui_FileDialogWizardDialog): |
|
25 """ |
|
26 Class implementing the color dialog wizard dialog. |
|
27 |
|
28 It displays a dialog for entering the parameters for the |
|
29 E5FileDialog or QFileDialog code generator. |
|
30 """ |
|
31 def __init__(self, dialogVariant, parent=None): |
|
32 """ |
|
33 Constructor |
|
34 |
|
35 @param dialogVariant variant of the file dialog to be generated |
|
36 (-1 = E5FileDialog, 0 = unknown, 5 = PyQt5) |
|
37 @type int |
|
38 @param parent parent widget |
|
39 @type QWidget |
|
40 """ |
|
41 super().__init__(parent) |
|
42 self.setupUi(self) |
|
43 |
|
44 self.eStartWithCompleter = E5FileCompleter(self.eStartWith) |
|
45 self.eWorkDirCompleter = E5DirCompleter(self.eWorkDir) |
|
46 |
|
47 self.__typeButtonsGroup = QButtonGroup(self) |
|
48 self.__typeButtonsGroup.setExclusive(True) |
|
49 self.__typeButtonsGroup.addButton(self.rOpenFile, 1) |
|
50 self.__typeButtonsGroup.addButton(self.rOpenFiles, 2) |
|
51 self.__typeButtonsGroup.addButton(self.rSaveFile, 3) |
|
52 self.__typeButtonsGroup.addButton(self.rfOpenFile, 11) |
|
53 self.__typeButtonsGroup.addButton(self.rfOpenFiles, 12) |
|
54 self.__typeButtonsGroup.addButton(self.rfSaveFile, 13) |
|
55 self.__typeButtonsGroup.addButton(self.rOpenFileUrl, 21) |
|
56 self.__typeButtonsGroup.addButton(self.rOpenFileUrls, 22) |
|
57 self.__typeButtonsGroup.addButton(self.rSaveFileUrl, 23) |
|
58 self.__typeButtonsGroup.addButton(self.rDirectory, 30) |
|
59 self.__typeButtonsGroup.addButton(self.rDirectoryUrl, 31) |
|
60 self.__typeButtonsGroup.buttonClicked[int].connect( |
|
61 self.__toggleInitialFilterAndResult) |
|
62 self.__toggleInitialFilterAndResult(1) |
|
63 |
|
64 self.__dialogVariant = dialogVariant |
|
65 if self.__dialogVariant == -1: |
|
66 self.pyqtComboBox.addItems(["eric"]) |
|
67 self.setWindowTitle(self.tr("E5FileDialog Wizard")) |
|
68 self.pyqtComboBox.setCurrentIndex(0) |
|
69 self.pyqtComboBox.setEnabled(False) |
|
70 else: |
|
71 self.pyqtComboBox.addItems(["PyQt5", "PyQt6"]) |
|
72 self.setWindowTitle(self.tr("QFileDialog Wizard")) |
|
73 if self.__dialogVariant == 5: |
|
74 self.pyqtComboBox.setCurrentIndex(0) |
|
75 elif self.__dialogVariant == 6: |
|
76 self.pyqtComboBox.setCurrentIndex(1) |
|
77 else: |
|
78 self.pyqtComboBox.setCurrentIndex(0) |
|
79 |
|
80 self.rSaveFile.toggled[bool].connect(self.__toggleConfirmCheckBox) |
|
81 self.rfSaveFile.toggled[bool].connect(self.__toggleConfirmCheckBox) |
|
82 self.rSaveFileUrl.toggled[bool].connect(self.__toggleConfirmCheckBox) |
|
83 self.rDirectory.toggled[bool].connect(self.__toggleGroupsAndTest) |
|
84 self.rDirectoryUrl.toggled[bool].connect(self.__toggleGroupsAndTest) |
|
85 self.cStartWith.toggled[bool].connect(self.__toggleGroupsAndTest) |
|
86 self.cWorkDir.toggled[bool].connect(self.__toggleGroupsAndTest) |
|
87 self.cFilters.toggled[bool].connect(self.__toggleGroupsAndTest) |
|
88 |
|
89 self.bTest = self.buttonBox.addButton( |
|
90 self.tr("Test"), QDialogButtonBox.ButtonRole.ActionRole) |
|
91 |
|
92 msh = self.minimumSizeHint() |
|
93 self.resize(max(self.width(), msh.width()), msh.height()) |
|
94 |
|
95 def __adjustOptions(self, options): |
|
96 """ |
|
97 Private method to adjust the file dialog options. |
|
98 |
|
99 @param options file dialog options (QFileDialog.Options) |
|
100 @return modified options (QFileDialog.Options) |
|
101 """ |
|
102 if Globals.isLinuxPlatform(): |
|
103 options |= QFileDialog.Option.DontUseNativeDialog |
|
104 return options |
|
105 |
|
106 @pyqtSlot(int) |
|
107 def on_pyqtComboBox_currentIndexChanged(self, index): |
|
108 """ |
|
109 Private slot to setup the dialog for the selected PyQt variant. |
|
110 |
|
111 @param index index of the current item |
|
112 @type int |
|
113 """ |
|
114 txt = self.pyqtComboBox.itemText(index) |
|
115 self.rfOpenFile.setEnabled(txt == "eric") |
|
116 self.rfOpenFiles.setEnabled(txt == "eric") |
|
117 self.rfSaveFile.setEnabled(txt == "eric") |
|
118 |
|
119 self.rOpenFileUrl.setEnabled(txt in ["PyQt5", "PyQt6"]) |
|
120 self.rOpenFileUrls.setEnabled(txt in ["PyQt5", "PyQt6"]) |
|
121 self.rSaveFileUrl.setEnabled(txt in ["PyQt5", "PyQt6"]) |
|
122 self.rDirectoryUrl.setEnabled(txt in ["PyQt5", "PyQt6"]) |
|
123 |
|
124 if txt in ["PyQt5", "PyQt6"]: |
|
125 if self.rfOpenFile.isChecked(): |
|
126 self.rOpenFile.setChecked(True) |
|
127 elif self.rfOpenFiles.isChecked(): |
|
128 self.rOpenFiles.setChecked(True) |
|
129 elif self.rfSaveFile.isChecked(): |
|
130 self.rSaveFile.setChecked(True) |
|
131 else: |
|
132 if self.rOpenFileUrl.isChecked(): |
|
133 self.rOpenFile.setChecked(True) |
|
134 if self.rOpenFileUrls.isChecked(): |
|
135 self.rOpenFiles.setChecked(True) |
|
136 if self.rSaveFileUrl.isChecked(): |
|
137 self.rSaveFile.setChecked(True) |
|
138 if self.rDirectoryUrl.isChecked(): |
|
139 self.rDirectory.setChecked(True) |
|
140 |
|
141 if txt == "eric": |
|
142 self.__dialogVariant = -1 |
|
143 elif txt == "PyQt5": |
|
144 self.__dialogVariant = 5 |
|
145 elif txt == "PyQt6": |
|
146 self.__dialogVariant = 6 |
|
147 else: |
|
148 # default is PyQt5 |
|
149 self.__dialogVariant = 5 |
|
150 |
|
151 self.__toggleInitialFilterAndResult( |
|
152 self.__typeButtonsGroup.checkedId()) |
|
153 |
|
154 def on_buttonBox_clicked(self, button): |
|
155 """ |
|
156 Private slot called by a button of the button box clicked. |
|
157 |
|
158 @param button button that was clicked (QAbstractButton) |
|
159 """ |
|
160 if button == self.bTest: |
|
161 self.on_bTest_clicked() |
|
162 |
|
163 @pyqtSlot() |
|
164 def on_bTest_clicked(self): |
|
165 """ |
|
166 Private method to test the selected options. |
|
167 """ |
|
168 if self.rOpenFile.isChecked() or self.rfOpenFile.isChecked(): |
|
169 if not self.cSymlinks.isChecked(): |
|
170 options = QFileDialog.Options( |
|
171 QFileDialog.Option.DontResolveSymlinks) |
|
172 else: |
|
173 options = QFileDialog.Options() |
|
174 options = self.__adjustOptions(options) |
|
175 QFileDialog.getOpenFileName( |
|
176 None, |
|
177 self.eCaption.text(), |
|
178 self.eStartWith.text(), |
|
179 self.eFilters.text(), |
|
180 self.eInitialFilter.text(), |
|
181 options) |
|
182 elif self.rOpenFileUrl.isChecked(): |
|
183 if not self.cSymlinks.isChecked(): |
|
184 options = QFileDialog.Options( |
|
185 QFileDialog.Option.DontResolveSymlinks) |
|
186 else: |
|
187 options = QFileDialog.Options() |
|
188 options = self.__adjustOptions(options) |
|
189 try: |
|
190 QFileDialog.getOpenFileUrl( |
|
191 None, |
|
192 self.eCaption.text(), |
|
193 QUrl(self.eStartWith.text()), |
|
194 self.eFilters.text(), |
|
195 self.eInitialFilter.text(), |
|
196 options, |
|
197 self.schemesEdit.text().split()) |
|
198 except TypeError: |
|
199 # PyQt5 < 5.13.0 contains an error |
|
200 QFileDialog.getOpenFileUrl( |
|
201 None, |
|
202 self.eCaption.text(), |
|
203 self.eStartWith.text(), |
|
204 self.eFilters.text(), |
|
205 self.eInitialFilter.text(), |
|
206 options, |
|
207 self.schemesEdit.text().split()) |
|
208 elif self.rOpenFiles.isChecked() or self.rfOpenFiles.isChecked(): |
|
209 if not self.cSymlinks.isChecked(): |
|
210 options = QFileDialog.Options( |
|
211 QFileDialog.Option.DontResolveSymlinks) |
|
212 else: |
|
213 options = QFileDialog.Options() |
|
214 options = self.__adjustOptions(options) |
|
215 QFileDialog.getOpenFileNames( |
|
216 None, |
|
217 self.eCaption.text(), |
|
218 self.eStartWith.text(), |
|
219 self.eFilters.text(), |
|
220 self.eInitialFilter.text(), |
|
221 options) |
|
222 elif self.rOpenFileUrls.isChecked(): |
|
223 if not self.cSymlinks.isChecked(): |
|
224 options = QFileDialog.Options( |
|
225 QFileDialog.Option.DontResolveSymlinks) |
|
226 else: |
|
227 options = QFileDialog.Options() |
|
228 options = self.__adjustOptions(options) |
|
229 try: |
|
230 QFileDialog.getOpenFileUrls( |
|
231 None, |
|
232 self.eCaption.text(), |
|
233 QUrl(self.eStartWith.text()), |
|
234 self.eFilters.text(), |
|
235 self.eInitialFilter.text(), |
|
236 options, |
|
237 self.schemesEdit.text().split()) |
|
238 except TypeError: |
|
239 # PyQt5 < 5.13.0 contains an error |
|
240 QFileDialog.getOpenFileUrls( |
|
241 None, |
|
242 self.eCaption.text(), |
|
243 self.eStartWith.text(), |
|
244 self.eFilters.text(), |
|
245 self.eInitialFilter.text(), |
|
246 options, |
|
247 self.schemesEdit.text().split()) |
|
248 elif self.rSaveFile.isChecked() or self.rfSaveFile.isChecked(): |
|
249 if not self.cSymlinks.isChecked(): |
|
250 options = QFileDialog.Options( |
|
251 QFileDialog.Option.DontResolveSymlinks) |
|
252 else: |
|
253 options = QFileDialog.Options() |
|
254 options = self.__adjustOptions(options) |
|
255 QFileDialog.getSaveFileName( |
|
256 None, |
|
257 self.eCaption.text(), |
|
258 self.eStartWith.text(), |
|
259 self.eFilters.text(), |
|
260 self.eInitialFilter.text(), |
|
261 options) |
|
262 elif self.rSaveFileUrl.isChecked(): |
|
263 if not self.cSymlinks.isChecked(): |
|
264 options = QFileDialog.Options( |
|
265 QFileDialog.Option.DontResolveSymlinks) |
|
266 else: |
|
267 options = QFileDialog.Options() |
|
268 options = self.__adjustOptions(options) |
|
269 try: |
|
270 QFileDialog.getSaveFileUrl( |
|
271 None, |
|
272 self.eCaption.text(), |
|
273 QUrl(self.eStartWith.text()), |
|
274 self.eFilters.text(), |
|
275 self.eInitialFilter.text(), |
|
276 options, |
|
277 self.schemesEdit.text().split()) |
|
278 except TypeError: |
|
279 # PyQt5 < 5.13.0 contains an error |
|
280 QFileDialog.getSaveFileUrl( |
|
281 None, |
|
282 self.eCaption.text(), |
|
283 self.eStartWith.text(), |
|
284 self.eFilters.text(), |
|
285 self.eInitialFilter.text(), |
|
286 options, |
|
287 self.schemesEdit.text().split()) |
|
288 elif self.rDirectory.isChecked(): |
|
289 options = QFileDialog.Options() |
|
290 if not self.cSymlinks.isChecked(): |
|
291 options |= QFileDialog.Options( |
|
292 QFileDialog.Option.DontResolveSymlinks) |
|
293 if self.cDirOnly.isChecked(): |
|
294 options |= QFileDialog.Options(QFileDialog.Option.ShowDirsOnly) |
|
295 else: |
|
296 options |= QFileDialog.Options(QFileDialog.Option(0)) |
|
297 options = self.__adjustOptions(options) |
|
298 QFileDialog.getExistingDirectory( |
|
299 None, |
|
300 self.eCaption.text(), |
|
301 self.eWorkDir.text(), |
|
302 options) |
|
303 elif self.rDirectoryUrl.isChecked(): |
|
304 options = QFileDialog.Options() |
|
305 if not self.cSymlinks.isChecked(): |
|
306 options |= QFileDialog.Options( |
|
307 QFileDialog.Option.DontResolveSymlinks) |
|
308 if self.cDirOnly.isChecked(): |
|
309 options |= QFileDialog.Options(QFileDialog.Option.ShowDirsOnly) |
|
310 else: |
|
311 options |= QFileDialog.Options(QFileDialog.Option(0)) |
|
312 options = self.__adjustOptions(options) |
|
313 try: |
|
314 QFileDialog.getExistingDirectoryUrl( |
|
315 None, |
|
316 self.eCaption.text(), |
|
317 QUrl(self.eWorkDir.text()), |
|
318 options, |
|
319 self.schemesEdit.text().split()) |
|
320 except TypeError: |
|
321 # PyQt5 < 5.13.0 contains an error |
|
322 QFileDialog.getExistingDirectoryUrl( |
|
323 None, |
|
324 self.eCaption.text(), |
|
325 self.eWorkDir.text(), |
|
326 options, |
|
327 self.schemesEdit.text().split()) |
|
328 |
|
329 def __toggleConfirmCheckBox(self): |
|
330 """ |
|
331 Private slot to enable/disable the confirmation check box. |
|
332 """ |
|
333 self.cConfirmOverwrite.setEnabled( |
|
334 self.rSaveFile.isChecked() or self.rfSaveFile.isChecked() or |
|
335 self.rSaveFileUrl.isChecked()) |
|
336 |
|
337 def __toggleGroupsAndTest(self): |
|
338 """ |
|
339 Private slot to enable/disable certain groups and the test button. |
|
340 """ |
|
341 if self.rDirectory.isChecked() or self.rDirectoryUrl.isChecked(): |
|
342 self.filePropertiesGroup.setEnabled(False) |
|
343 self.dirPropertiesGroup.setEnabled(True) |
|
344 self.bTest.setDisabled(self.cWorkDir.isChecked()) |
|
345 else: |
|
346 self.filePropertiesGroup.setEnabled(True) |
|
347 self.dirPropertiesGroup.setEnabled(False) |
|
348 self.bTest.setDisabled( |
|
349 self.cStartWith.isChecked() or self.cFilters.isChecked()) |
|
350 |
|
351 def __toggleInitialFilterAndResult(self, checkedId): |
|
352 """ |
|
353 Private slot to enable/disable the initial filter elements and the |
|
354 results entries. |
|
355 |
|
356 @param checkedId id of the clicked button (integer) |
|
357 """ |
|
358 enable = ( |
|
359 (self.__dialogVariant in (-1, ) and checkedId in [11, 12, 13]) or |
|
360 (self.__dialogVariant in (5, 6) and |
|
361 checkedId in [1, 2, 3, 21, 22, 23]) |
|
362 ) |
|
363 |
|
364 self.lInitialFilter.setEnabled(enable) |
|
365 self.eInitialFilter.setEnabled(enable) |
|
366 self.cInitialFilter.setEnabled(enable) |
|
367 |
|
368 self.lFilterVariable.setEnabled(enable) |
|
369 self.eFilterVariable.setEnabled(enable) |
|
370 |
|
371 self.urlPropertiesGroup.setEnabled(checkedId in (21, 22, 23, 31)) |
|
372 |
|
373 def getCode(self, indLevel, indString): |
|
374 """ |
|
375 Public method to get the source code for Qt5. |
|
376 |
|
377 @param indLevel indentation level (int) |
|
378 @param indString string used for indentation (space or tab) (string) |
|
379 @return generated code (string) |
|
380 """ |
|
381 # calculate our indentation level and the indentation string |
|
382 il = indLevel + 1 |
|
383 istring = il * indString |
|
384 estring = os.linesep + indLevel * indString |
|
385 |
|
386 # now generate the code |
|
387 if self.parentSelf.isChecked(): |
|
388 parent = "self" |
|
389 elif self.parentNone.isChecked(): |
|
390 parent = "None" |
|
391 elif self.parentOther.isChecked(): |
|
392 parent = self.parentEdit.text() |
|
393 if parent == "": |
|
394 parent = "None" |
|
395 |
|
396 # prepare the result variables |
|
397 nameVariable = self.eNameVariable.text() |
|
398 if not nameVariable: |
|
399 if self.__typeButtonsGroup.checkedButton() in [ |
|
400 self.rOpenFile, self.rfOpenFile, |
|
401 self.rSaveFile, self.rfSaveFile]: |
|
402 nameVariable = "fileName" |
|
403 elif self.__typeButtonsGroup.checkedButton() in [ |
|
404 self.rOpenFiles, self.rfOpenFiles]: |
|
405 nameVariable = "fileNames" |
|
406 elif self.__typeButtonsGroup.checkedButton() == self.rDirectory: |
|
407 nameVariable = "dirName" |
|
408 else: |
|
409 nameVariable = "res" |
|
410 filterVariable = self.eFilterVariable.text() |
|
411 if not filterVariable: |
|
412 if ( |
|
413 (self.__dialogVariant in (-1, ) and |
|
414 self.__typeButtonsGroup.checkedButton() in [ |
|
415 self.rfOpenFile, self.rfOpenFiles, self.rfSaveFile]) or |
|
416 (self.__dialogVariant in (5, 6) and |
|
417 self.__typeButtonsGroup.checkedButton() in [ |
|
418 self.rOpenFile, self.rOpenFiles, self.rSaveFile]) |
|
419 ): |
|
420 filterVariable = ", selectedFilter" |
|
421 else: |
|
422 filterVariable = "" |
|
423 else: |
|
424 filterVariable = ", " + filterVariable |
|
425 |
|
426 if self.__dialogVariant == -1: |
|
427 dialogType = "E5FileDialog" |
|
428 optionStr = "" |
|
429 else: |
|
430 dialogType = "QFileDialog" |
|
431 optionStr = ".Option" |
|
432 |
|
433 code = '{0}{1} = {2}.'.format(nameVariable, filterVariable, dialogType) |
|
434 if ( |
|
435 self.rOpenFile.isChecked() or |
|
436 self.rfOpenFile.isChecked() or |
|
437 self.rOpenFileUrl.isChecked() |
|
438 ): |
|
439 if self.rOpenFile.isChecked(): |
|
440 code += 'getOpenFileName({0}{1}'.format(os.linesep, istring) |
|
441 elif self.rOpenFileUrl.isChecked(): |
|
442 code += 'getOpenFileUrl({0}{1}'.format(os.linesep, istring) |
|
443 else: |
|
444 code += 'getOpenFileNameAndFilter({0}{1}'.format( |
|
445 os.linesep, istring) |
|
446 code += '{0},{1}{2}'.format(parent, os.linesep, istring) |
|
447 if not self.eCaption.text(): |
|
448 code += '"",{0}{1}'.format(os.linesep, istring) |
|
449 else: |
|
450 code += 'self.tr("{0}"),{1}{2}'.format( |
|
451 self.eCaption.text(), os.linesep, istring) |
|
452 if self.rOpenFileUrl.isChecked(): |
|
453 if not self.eStartWith.text(): |
|
454 code += 'QUrl(),{0}{1}'.format(os.linesep, istring) |
|
455 else: |
|
456 if self.cStartWith.isChecked(): |
|
457 fmt = '{0},{1}{2}' |
|
458 else: |
|
459 fmt = 'QUrl("{0}"),{1}{2}' |
|
460 code += fmt.format(self.eStartWith.text(), os.linesep, |
|
461 istring) |
|
462 else: |
|
463 if not self.eStartWith.text(): |
|
464 code += '"",{0}{1}'.format(os.linesep, istring) |
|
465 else: |
|
466 if self.cStartWith.isChecked(): |
|
467 fmt = '{0},{1}{2}' |
|
468 else: |
|
469 fmt = '"{0}",{1}{2}' |
|
470 code += fmt.format(self.eStartWith.text(), os.linesep, |
|
471 istring) |
|
472 if self.eFilters.text() == "": |
|
473 code += '""' |
|
474 else: |
|
475 if self.cFilters.isChecked(): |
|
476 fmt = '{0}' |
|
477 else: |
|
478 fmt = 'self.tr("{0}")' |
|
479 code += fmt.format(self.eFilters.text()) |
|
480 if self.rfOpenFile.isChecked() or self.__dialogVariant in (5, 6): |
|
481 if self.eInitialFilter.text() == "": |
|
482 initialFilter = "None" |
|
483 else: |
|
484 if self.cInitialFilter.isChecked(): |
|
485 fmt = '{0}' |
|
486 else: |
|
487 fmt = 'self.tr("{0}")' |
|
488 initialFilter = fmt.format(self.eInitialFilter.text()) |
|
489 code += ',{0}{1}{2}'.format(os.linesep, istring, initialFilter) |
|
490 if not self.cSymlinks.isChecked(): |
|
491 code += ( |
|
492 ',{0}{1}{2}.Options({2}{3}.DontResolveSymlinks)' |
|
493 .format(os.linesep, istring, dialogType, optionStr) |
|
494 ) |
|
495 if self.rOpenFileUrl.isChecked() and bool(self.schemesEdit.text()): |
|
496 code += ',{0}{1}{2}'.format( |
|
497 os.linesep, istring, self.__prepareSchemesList()) |
|
498 code += '){0}'.format(estring) |
|
499 elif ( |
|
500 self.rOpenFiles.isChecked() or |
|
501 self.rfOpenFiles.isChecked() or |
|
502 self.rOpenFileUrls.isChecked() |
|
503 ): |
|
504 if self.rOpenFiles.isChecked(): |
|
505 code += 'getOpenFileNames({0}{1}'.format(os.linesep, istring) |
|
506 elif self.rOpenFileUrls.isChecked(): |
|
507 code += 'getOpenFileUrls({0}{1}'.format(os.linesep, istring) |
|
508 else: |
|
509 code += 'getOpenFileNamesAndFilter({0}{1}'.format( |
|
510 os.linesep, istring) |
|
511 code += '{0},{1}{2}'.format(parent, os.linesep, istring) |
|
512 if not self.eCaption.text(): |
|
513 code += '"",{0}{1}'.format(os.linesep, istring) |
|
514 else: |
|
515 code += 'self.tr("{0}"),{1}{2}'.format( |
|
516 self.eCaption.text(), os.linesep, istring) |
|
517 if self.rOpenFileUrls.isChecked(): |
|
518 if not self.eStartWith.text(): |
|
519 code += 'QUrl(),{0}{1}'.format(os.linesep, istring) |
|
520 else: |
|
521 if self.cStartWith.isChecked(): |
|
522 fmt = '{0},{1}{2}' |
|
523 else: |
|
524 fmt = 'QUrl("{0}"),{1}{2}' |
|
525 code += fmt.format(self.eStartWith.text(), os.linesep, |
|
526 istring) |
|
527 else: |
|
528 if not self.eStartWith.text(): |
|
529 code += '"",{0}{1}'.format(os.linesep, istring) |
|
530 else: |
|
531 if self.cStartWith.isChecked(): |
|
532 fmt = '{0},{1}{2}' |
|
533 else: |
|
534 fmt = '"{0}",{1}{2}' |
|
535 code += fmt.format(self.eStartWith.text(), os.linesep, |
|
536 istring) |
|
537 if not self.eFilters.text(): |
|
538 code += '""' |
|
539 else: |
|
540 if self.cFilters.isChecked(): |
|
541 fmt = '{0}' |
|
542 else: |
|
543 fmt = 'self.tr("{0}")' |
|
544 code += fmt.format(self.eFilters.text()) |
|
545 if self.rfOpenFiles.isChecked() or self.__dialogVariant in (5, 6): |
|
546 if self.eInitialFilter.text() == "": |
|
547 initialFilter = "None" |
|
548 else: |
|
549 if self.cInitialFilter.isChecked(): |
|
550 fmt = '{0}' |
|
551 else: |
|
552 fmt = 'self.tr("{0}")' |
|
553 initialFilter = fmt.format(self.eInitialFilter.text()) |
|
554 code += ',{0}{1}{2}'.format(os.linesep, istring, initialFilter) |
|
555 if not self.cSymlinks.isChecked(): |
|
556 code += ( |
|
557 ',{0}{1}{2}.Options({2}{3}.DontResolveSymlinks)' |
|
558 .format(os.linesep, istring, dialogType, optionStr) |
|
559 ) |
|
560 if ( |
|
561 self.rOpenFileUrls.isChecked() and |
|
562 bool(self.schemesEdit.text()) |
|
563 ): |
|
564 code += ',{0}{1}{2}'.format( |
|
565 os.linesep, istring, self.__prepareSchemesList()) |
|
566 code += '){0}'.format(estring) |
|
567 elif ( |
|
568 self.rSaveFile.isChecked() or |
|
569 self.rfSaveFile.isChecked() or |
|
570 self.rSaveFileUrl.isChecked() |
|
571 ): |
|
572 if self.rSaveFile.isChecked(): |
|
573 code += 'getSaveFileName({0}{1}'.format(os.linesep, istring) |
|
574 elif self.rSaveFileUrl.isChecked(): |
|
575 code += 'getSaveFileUrl({0}{1}'.format(os.linesep, istring) |
|
576 else: |
|
577 code += 'getSaveFileNameAndFilter({0}{1}'.format( |
|
578 os.linesep, istring) |
|
579 code += '{0},{1}{2}'.format(parent, os.linesep, istring) |
|
580 if not self.eCaption.text(): |
|
581 code += '"",{0}{1}'.format(os.linesep, istring) |
|
582 else: |
|
583 code += 'self.tr("{0}"),{1}{2}'.format( |
|
584 self.eCaption.text(), os.linesep, istring) |
|
585 if self.rSaveFileUrl.isChecked(): |
|
586 if not self.eStartWith.text(): |
|
587 code += 'QUrl(),{0}{1}'.format(os.linesep, istring) |
|
588 else: |
|
589 if self.cStartWith.isChecked(): |
|
590 fmt = '{0},{1}{2}' |
|
591 else: |
|
592 fmt = 'QUrl("{0}"),{1}{2}' |
|
593 code += fmt.format(self.eStartWith.text(), os.linesep, |
|
594 istring) |
|
595 else: |
|
596 if not self.eStartWith.text(): |
|
597 code += '"",{0}{1}'.format(os.linesep, istring) |
|
598 else: |
|
599 if self.cStartWith.isChecked(): |
|
600 fmt = '{0},{1}{2}' |
|
601 else: |
|
602 fmt = '"{0}",{1}{2}' |
|
603 code += fmt.format(self.eStartWith.text(), os.linesep, |
|
604 istring) |
|
605 if not self.eFilters.text(): |
|
606 code += '""' |
|
607 else: |
|
608 if self.cFilters.isChecked(): |
|
609 fmt = '{0}' |
|
610 else: |
|
611 fmt = 'self.tr("{0}")' |
|
612 code += fmt.format(self.eFilters.text()) |
|
613 if self.rfSaveFile.isChecked() or self.__dialogVariant in (5, 6): |
|
614 if self.eInitialFilter.text() == "": |
|
615 initialFilter = "None" |
|
616 else: |
|
617 if self.cInitialFilter.isChecked(): |
|
618 fmt = '{0}' |
|
619 else: |
|
620 fmt = 'self.tr("{0}")' |
|
621 initialFilter = fmt.format(self.eInitialFilter.text()) |
|
622 code += ',{0}{1}{2}'.format(os.linesep, istring, initialFilter) |
|
623 if ( |
|
624 (not self.cSymlinks.isChecked()) or |
|
625 (not self.cConfirmOverwrite.isChecked()) |
|
626 ): |
|
627 code += ',{0}{1}{2}.Options('.format( |
|
628 os.linesep, istring, dialogType) |
|
629 if not self.cSymlinks.isChecked(): |
|
630 code += '{0}{1}.DontResolveSymlinks'.format( |
|
631 dialogType, optionStr) |
|
632 if ( |
|
633 (not self.cSymlinks.isChecked()) and |
|
634 (not self.cConfirmOverwrite.isChecked()) |
|
635 ): |
|
636 code += ' | ' |
|
637 if not self.cConfirmOverwrite.isChecked(): |
|
638 code += '{0}{1}.DontConfirmOverwrite'.format( |
|
639 dialogType, optionStr) |
|
640 code += ')' |
|
641 if ( |
|
642 self.rSaveFileUrl.isChecked() and |
|
643 bool(self.schemesEdit.text()) |
|
644 ): |
|
645 code += ',{0}{1}{2}'.format( |
|
646 os.linesep, istring, self.__prepareSchemesList()) |
|
647 |
|
648 code += '){0}'.format(estring) |
|
649 elif self.rDirectory.isChecked() or self.rDirectoryUrl.isChecked(): |
|
650 if self.rDirectory.isChecked(): |
|
651 code += 'getExistingDirectory({0}{1}'.format( |
|
652 os.linesep, istring) |
|
653 else: |
|
654 code += 'getExistingDirectoryUrl({0}{1}'.format( |
|
655 os.linesep, istring) |
|
656 code += '{0},{1}{2}'.format(parent, os.linesep, istring) |
|
657 if not self.eCaption.text(): |
|
658 code += '"",{0}{1}'.format(os.linesep, istring) |
|
659 else: |
|
660 code += 'self.tr("{0}"),{1}{2}'.format( |
|
661 self.eCaption.text(), os.linesep, istring) |
|
662 if self.rDirectoryUrl.isChecked(): |
|
663 if not self.eWorkDir.text(): |
|
664 code += 'QUrl()' |
|
665 else: |
|
666 if self.cWorkDir.isChecked(): |
|
667 fmt = '{0}' |
|
668 else: |
|
669 fmt = 'QUrl("{0}")' |
|
670 code += fmt.format(self.eWorkDir.text()) |
|
671 else: |
|
672 if not self.eWorkDir.text(): |
|
673 code += '""' |
|
674 else: |
|
675 if self.cWorkDir.isChecked(): |
|
676 fmt = '{0}' |
|
677 else: |
|
678 fmt = '"{0}"' |
|
679 code += fmt.format(self.eWorkDir.text()) |
|
680 code += ',{0}{1}{2}.Options('.format(os.linesep, istring, |
|
681 dialogType) |
|
682 if not self.cSymlinks.isChecked(): |
|
683 code += '{0}{1}.DontResolveSymlinks | '.format( |
|
684 dialogType, optionStr) |
|
685 if self.cDirOnly.isChecked(): |
|
686 code += '{0}{1}.ShowDirsOnly'.format( |
|
687 dialogType, optionStr) |
|
688 else: |
|
689 code += '{0}.Option(0)'.format(dialogType) |
|
690 code += ')' |
|
691 if self.rDirectoryUrl.isChecked(): |
|
692 code += ',{0}{1}{2}'.format( |
|
693 os.linesep, istring, self.__prepareSchemesList()) |
|
694 code += '){0}'.format(estring) |
|
695 |
|
696 return code |
|
697 |
|
698 def __prepareSchemesList(self): |
|
699 """ |
|
700 Private method to prepare the list of supported schemes. |
|
701 |
|
702 @return string representation of the supported schemes |
|
703 @rtype str |
|
704 """ |
|
705 return repr(self.schemesEdit.text().strip().split()) |