24 Class implementing the color dialog wizard dialog. |
24 Class implementing the color dialog wizard dialog. |
25 |
25 |
26 It displays a dialog for entering the parameters |
26 It displays a dialog for entering the parameters |
27 for the QFileDialog code generator. |
27 for the QFileDialog code generator. |
28 """ |
28 """ |
29 def __init__(self, parent=None): |
29 def __init__(self, pyqtVariant, parent=None): |
30 """ |
30 """ |
31 Constructor |
31 Constructor |
32 |
32 |
|
33 @param pyqtVariant variant of PyQt (integer; 0, 4 or 5) |
33 @param parent parent widget (QWidget) |
34 @param parent parent widget (QWidget) |
34 """ |
35 """ |
35 super().__init__(parent) |
36 super().__init__(parent) |
36 self.setupUi(self) |
37 self.setupUi(self) |
37 |
38 |
38 self.eStartWithCompleter = E5FileCompleter(self.eStartWith) |
39 self.eStartWithCompleter = E5FileCompleter(self.eStartWith) |
39 self.eWorkDirCompleter = E5DirCompleter(self.eWorkDir) |
40 self.eWorkDirCompleter = E5DirCompleter(self.eWorkDir) |
|
41 |
|
42 self.__pyqtVariant = pyqtVariant |
|
43 |
|
44 self.__typeButtonsGroup = QButtonGroup(self) |
|
45 self.__typeButtonsGroup.setExclusive(True) |
|
46 self.__typeButtonsGroup.addButton(self.rOpenFile, 1) |
|
47 self.__typeButtonsGroup.addButton(self.rOpenFiles, 2) |
|
48 self.__typeButtonsGroup.addButton(self.rSaveFile, 3) |
|
49 self.__typeButtonsGroup.addButton(self.rfOpenFile, 11) |
|
50 self.__typeButtonsGroup.addButton(self.rfOpenFiles, 12) |
|
51 self.__typeButtonsGroup.addButton(self.rfSaveFile, 13) |
|
52 self.__typeButtonsGroup.addButton(self.rDirectory, 20) |
|
53 self.__typeButtonsGroup.buttonClicked[int].connect( |
|
54 self.__toggleInitialFilter) |
|
55 self.__toggleInitialFilter(1) |
|
56 |
|
57 self.pyqtComboBox.addItems(["PyQt4", "PyQt5"]) |
|
58 if self.__pyqtVariant == 5: |
|
59 self.pyqtComboBox.setCurrentIndex(1) |
|
60 else: |
|
61 self.pyqtComboBox.setCurrentIndex(0) |
40 |
62 |
41 self.rSaveFile.toggled[bool].connect(self.__toggleConfirmCheckBox) |
63 self.rSaveFile.toggled[bool].connect(self.__toggleConfirmCheckBox) |
42 self.rfSaveFile.toggled[bool].connect(self.__toggleConfirmCheckBox) |
64 self.rfSaveFile.toggled[bool].connect(self.__toggleConfirmCheckBox) |
43 self.rDirectory.toggled[bool].connect(self.__toggleGroupsAndTest) |
65 self.rDirectory.toggled[bool].connect(self.__toggleGroupsAndTest) |
44 self.cStartWith.toggled[bool].connect(self.__toggleGroupsAndTest) |
66 self.cStartWith.toggled[bool].connect(self.__toggleGroupsAndTest) |
45 self.cWorkDir.toggled[bool].connect(self.__toggleGroupsAndTest) |
67 self.cWorkDir.toggled[bool].connect(self.__toggleGroupsAndTest) |
46 self.cFilters.toggled[bool].connect(self.__toggleGroupsAndTest) |
68 self.cFilters.toggled[bool].connect(self.__toggleGroupsAndTest) |
47 |
69 |
48 self.bTest = self.buttonBox.addButton( |
70 self.bTest = self.buttonBox.addButton( |
49 self.trUtf8("Test"), QDialogButtonBox.ActionRole) |
71 self.trUtf8("Test"), QDialogButtonBox.ActionRole) |
50 |
72 |
51 def __adjustOptions(self, options): |
73 def __adjustOptions(self, options): |
52 """ |
74 """ |
53 Private method to adjust the file dialog options. |
75 Private method to adjust the file dialog options. |
54 |
76 |
55 @param options file dialog options (QFileDialog.Options) |
77 @param options file dialog options (QFileDialog.Options) |
56 @return modified options (QFileDialog.Options) |
78 @return modified options (QFileDialog.Options) |
57 """ |
79 """ |
58 if Globals.isLinuxPlatform(): |
80 if Globals.isLinuxPlatform(): |
59 options |= QFileDialog.DontUseNativeDialog |
81 options |= QFileDialog.DontUseNativeDialog |
60 return options |
82 return options |
61 |
83 |
|
84 @pyqtSlot(str) |
|
85 def on_pyqtComboBox_currentIndexChanged(self, txt): |
|
86 """ |
|
87 Private slot to setup the dialog for the selected PyQt variant. |
|
88 |
|
89 @param txt text of the selected combo box entry (string) |
|
90 """ |
|
91 self.rfOpenFile.setEnabled(txt == "PyQt4") |
|
92 self.rfOpenFiles.setEnabled(txt == "PyQt4") |
|
93 self.rfSaveFile.setEnabled(txt == "PyQt4") |
|
94 |
|
95 if txt == "PyQt5": |
|
96 if self.rfOpenFile.isChecked(): |
|
97 self.rOpenFile.setChecked(True) |
|
98 elif self.rfOpenFiles.isChecked(): |
|
99 self.rOpenFiles.setChecked(True) |
|
100 elif self.rfSaveFile.isChecked(): |
|
101 self.rSaveFile.setChecked(True) |
|
102 |
|
103 self.__pyqtVariant = 5 if txt == "PyQt5" else 4 |
|
104 |
|
105 self.__toggleInitialFilter(self.__typeButtonsGroup.checkedId()) |
|
106 |
62 def on_buttonBox_clicked(self, button): |
107 def on_buttonBox_clicked(self, button): |
63 """ |
108 """ |
64 Private slot called by a button of the button box clicked. |
109 Private slot called by a button of the button box clicked. |
65 |
110 |
66 @param button button that was clicked (QAbstractButton) |
111 @param button button that was clicked (QAbstractButton) |
77 if not self.cSymlinks.isChecked(): |
122 if not self.cSymlinks.isChecked(): |
78 options = QFileDialog.Options(QFileDialog.DontResolveSymlinks) |
123 options = QFileDialog.Options(QFileDialog.DontResolveSymlinks) |
79 else: |
124 else: |
80 options = QFileDialog.Options() |
125 options = QFileDialog.Options() |
81 options = self.__adjustOptions(options) |
126 options = self.__adjustOptions(options) |
82 QFileDialog.getOpenFileName( |
127 if self.rOpenFile.isChecked() and self.__pyqtVariant == 4: |
83 None, |
128 QFileDialog.getOpenFileName( |
84 self.eCaption.text(), |
129 None, |
85 self.eStartWith.text(), |
130 self.eCaption.text(), |
86 self.eFilters.text(), |
131 self.eStartWith.text(), |
87 options) |
132 self.eFilters.text(), |
|
133 options) |
|
134 else: |
|
135 QFileDialog.getOpenFileNameAndFilter( |
|
136 None, |
|
137 self.eCaption.text(), |
|
138 self.eStartWith.text(), |
|
139 self.eFilters.text(), |
|
140 self.eInitialFilter.text(), |
|
141 options) |
88 elif self.rOpenFiles.isChecked() or self.rfOpenFiles.isChecked(): |
142 elif self.rOpenFiles.isChecked() or self.rfOpenFiles.isChecked(): |
89 if not self.cSymlinks.isChecked(): |
143 if not self.cSymlinks.isChecked(): |
90 options = QFileDialog.Options(QFileDialog.DontResolveSymlinks) |
144 options = QFileDialog.Options(QFileDialog.DontResolveSymlinks) |
91 else: |
145 else: |
92 options = QFileDialog.Options() |
146 options = QFileDialog.Options() |
93 options = self.__adjustOptions(options) |
147 options = self.__adjustOptions(options) |
94 QFileDialog.getOpenFileNames( |
148 if self.rOpenFiles.isChecked() and self.__pyqtVariant == 4: |
95 None, |
149 QFileDialog.getOpenFileNames( |
96 self.eCaption.text(), |
150 None, |
97 self.eStartWith.text(), |
151 self.eCaption.text(), |
98 self.eFilters.text(), |
152 self.eStartWith.text(), |
99 options) |
153 self.eFilters.text(), |
|
154 options) |
|
155 else: |
|
156 QFileDialog.getOpenFileNamesAndFilter( |
|
157 None, |
|
158 self.eCaption.text(), |
|
159 self.eStartWith.text(), |
|
160 self.eFilters.text(), |
|
161 self.eInitialFilter.text(), |
|
162 options) |
100 elif self.rSaveFile.isChecked() or self.rfSaveFile.isChecked(): |
163 elif self.rSaveFile.isChecked() or self.rfSaveFile.isChecked(): |
101 if not self.cSymlinks.isChecked(): |
164 if not self.cSymlinks.isChecked(): |
102 options = QFileDialog.Options(QFileDialog.DontResolveSymlinks) |
165 options = QFileDialog.Options(QFileDialog.DontResolveSymlinks) |
103 else: |
166 else: |
104 options = QFileDialog.Options() |
167 options = QFileDialog.Options() |
105 options = self.__adjustOptions(options) |
168 options = self.__adjustOptions(options) |
106 QFileDialog.getSaveFileName( |
169 if self.rSaveFile.isChecked() and self.__pyqtVariant == 4: |
107 None, |
170 QFileDialog.getSaveFileName( |
108 self.eCaption.text(), |
171 None, |
109 self.eStartWith.text(), |
172 self.eCaption.text(), |
110 self.eFilters.text(), |
173 self.eStartWith.text(), |
111 options) |
174 self.eFilters.text(), |
|
175 options) |
|
176 else: |
|
177 QFileDialog.getSaveFileNameAndFilter( |
|
178 None, |
|
179 self.eCaption.text(), |
|
180 self.eStartWith.text(), |
|
181 self.eFilters.text(), |
|
182 self.eInitialFilter.text(), |
|
183 options) |
112 elif self.rDirectory.isChecked(): |
184 elif self.rDirectory.isChecked(): |
113 options = QFileDialog.Options() |
185 options = QFileDialog.Options() |
114 if not self.cSymlinks.isChecked(): |
186 if not self.cSymlinks.isChecked(): |
115 options |= QFileDialog.Options(QFileDialog.DontResolveSymlinks) |
187 options |= QFileDialog.Options(QFileDialog.DontResolveSymlinks) |
116 if self.cDirOnly.isChecked(): |
188 if self.cDirOnly.isChecked(): |
121 QFileDialog.getExistingDirectory( |
193 QFileDialog.getExistingDirectory( |
122 None, |
194 None, |
123 self.eCaption.text(), |
195 self.eCaption.text(), |
124 self.eWorkDir.text(), |
196 self.eWorkDir.text(), |
125 options) |
197 options) |
126 |
198 |
127 def __toggleConfirmCheckBox(self): |
199 def __toggleConfirmCheckBox(self): |
128 """ |
200 """ |
129 Private slot to enable/disable the confirmation check box. |
201 Private slot to enable/disable the confirmation check box. |
130 """ |
202 """ |
131 self.cConfirmOverwrite.setEnabled( |
203 self.cConfirmOverwrite.setEnabled( |
132 self.rSaveFile.isChecked() or self.rfSaveFile.isChecked()) |
204 self.rSaveFile.isChecked() or self.rfSaveFile.isChecked()) |
133 |
205 |
134 def __toggleGroupsAndTest(self): |
206 def __toggleGroupsAndTest(self): |
135 """ |
207 """ |
136 Private slot to enable/disable certain groups and the test button. |
208 Private slot to enable/disable certain groups and the test button. |
137 """ |
209 """ |
138 if self.rDirectory.isChecked(): |
210 if self.rDirectory.isChecked(): |
142 else: |
214 else: |
143 self.filePropertiesGroup.setEnabled(True) |
215 self.filePropertiesGroup.setEnabled(True) |
144 self.dirPropertiesGroup.setEnabled(False) |
216 self.dirPropertiesGroup.setEnabled(False) |
145 self.bTest.setDisabled( |
217 self.bTest.setDisabled( |
146 self.cStartWith.isChecked() or self.cFilters.isChecked()) |
218 self.cStartWith.isChecked() or self.cFilters.isChecked()) |
147 |
219 |
148 def __getCode4(self, indLevel, indString): |
220 def __toggleInitialFilter(self, id): |
149 """ |
221 """ |
150 Private method to get the source code for Qt4/Qt5. |
222 Private slot to enable/disable the initial filter elements. |
|
223 |
|
224 @param id id of the clicked button (integer) |
|
225 """ |
|
226 if (self.__pyqtVariant == 4 and id in [11, 12, 13]) or \ |
|
227 (self.__pyqtVariant == 5 and id in [1, 2, 3]): |
|
228 enable = True |
|
229 else: |
|
230 enable = False |
|
231 self.lInitialFilter.setEnabled(enable) |
|
232 self.eInitialFilter.setEnabled(enable) |
|
233 self.cInitialFilter.setEnabled(enable) |
|
234 |
|
235 def getCode(self, indLevel, indString): |
|
236 """ |
|
237 Public method to get the source code for Qt4 and Qt5. |
151 |
238 |
152 @param indLevel indentation level (int) |
239 @param indLevel indentation level (int) |
153 @param indString string used for indentation (space or tab) (string) |
240 @param indString string used for indentation (space or tab) (string) |
154 @return generated code (string) |
241 @return generated code (string) |
155 """ |
242 """ |
157 il = indLevel + 1 |
244 il = indLevel + 1 |
158 istring = il * indString |
245 istring = il * indString |
159 estring = os.linesep + indLevel * indString |
246 estring = os.linesep + indLevel * indString |
160 |
247 |
161 # now generate the code |
248 # now generate the code |
|
249 if self.parentSelf.isChecked(): |
|
250 parent = "self" |
|
251 elif self.parentNone.isChecked(): |
|
252 parent = "None" |
|
253 elif self.parentOther.isChecked(): |
|
254 parent = self.parentEdit.text() |
|
255 if parent == "": |
|
256 parent = "None" |
|
257 |
162 code = 'QFileDialog.' |
258 code = 'QFileDialog.' |
163 if self.rOpenFile.isChecked() or self.rfOpenFile.isChecked(): |
259 if self.rOpenFile.isChecked() or self.rfOpenFile.isChecked(): |
164 if self.rOpenFile.isChecked(): |
260 if self.rOpenFile.isChecked(): |
165 code += 'getOpenFileName({0}{1}'.format(os.linesep, istring) |
261 code += 'getOpenFileName({0}{1}'.format(os.linesep, istring) |
166 else: |
262 else: |
167 code += 'getOpenFileNameAndFilter({0}{1}'.format( |
263 code += 'getOpenFileNameAndFilter({0}{1}'.format( |
168 os.linesep, istring) |
264 os.linesep, istring) |
169 code += 'None,{0}{1}'.format(os.linesep, istring) |
265 code += '{0},{1}{2}'.format(parent, os.linesep, istring) |
170 if not self.eCaption.text(): |
266 if not self.eCaption.text(): |
171 code += '"",{0}{1}'.format(os.linesep, istring) |
267 code += '"",{0}{1}'.format(os.linesep, istring) |
172 else: |
268 else: |
173 code += 'self.trUtf8("{0}"),{1}{2}'.format( |
269 code += 'self.trUtf8("{0}"),{1}{2}'.format( |
174 self.eCaption.text(), os.linesep, istring) |
270 self.eCaption.text(), os.linesep, istring) |
186 if self.cFilters.isChecked(): |
282 if self.cFilters.isChecked(): |
187 fmt = '{0}' |
283 fmt = '{0}' |
188 else: |
284 else: |
189 fmt = 'self.trUtf8("{0}")' |
285 fmt = 'self.trUtf8("{0}")' |
190 code += fmt.format(self.eFilters.text()) |
286 code += fmt.format(self.eFilters.text()) |
191 if self.rfOpenFile.isChecked(): |
287 if self.rfOpenFile.isChecked() or self.__pyqtVariant == 5: |
192 code += ',{0}{1}None'.format(os.linesep, istring) |
288 if self.eInitialFilter.text() == "": |
|
289 filter = "None" |
|
290 else: |
|
291 if self.cInitialFilter.isChecked(): |
|
292 fmt = '{0}' |
|
293 else: |
|
294 fmt = 'self.trUtf8("{0}")' |
|
295 filter = fmt.format(self.eInitialFilter.text()) |
|
296 code += ',{0}{1}{2}'.format(os.linesep, istring, filter) |
193 if not self.cSymlinks.isChecked(): |
297 if not self.cSymlinks.isChecked(): |
194 code += \ |
298 code += \ |
195 ',{0}{1}QFileDialog.Options(' \ |
299 ',{0}{1}QFileDialog.Options(' \ |
196 'QFileDialog.DontResolveSymlinks)' \ |
300 'QFileDialog.DontResolveSymlinks)' \ |
197 .format(os.linesep, istring) |
301 .format(os.linesep, istring) |
200 if self.rOpenFiles.isChecked(): |
304 if self.rOpenFiles.isChecked(): |
201 code += 'getOpenFileNames({0}{1}'.format(os.linesep, istring) |
305 code += 'getOpenFileNames({0}{1}'.format(os.linesep, istring) |
202 else: |
306 else: |
203 code += 'getOpenFileNamesAndFilter({0}{1}'.format( |
307 code += 'getOpenFileNamesAndFilter({0}{1}'.format( |
204 os.linesep, istring) |
308 os.linesep, istring) |
205 code += 'None,{0}{1}'.format(os.linesep, istring) |
309 code += '{0},{1}{2}'.format(parent, os.linesep, istring) |
206 if not self.eCaption.text(): |
310 if not self.eCaption.text(): |
207 code += '"",{0}{1}'.format(os.linesep, istring) |
311 code += '"",{0}{1}'.format(os.linesep, istring) |
208 else: |
312 else: |
209 code += 'self.trUtf8("{0}"),{1}{2}'.format( |
313 code += 'self.trUtf8("{0}"),{1}{2}'.format( |
210 self.eCaption.text(), os.linesep, istring) |
314 self.eCaption.text(), os.linesep, istring) |
222 if self.cFilters.isChecked(): |
326 if self.cFilters.isChecked(): |
223 fmt = '{0}' |
327 fmt = '{0}' |
224 else: |
328 else: |
225 fmt = 'self.trUtf8("{0}")' |
329 fmt = 'self.trUtf8("{0}")' |
226 code += fmt.format(self.eFilters.text()) |
330 code += fmt.format(self.eFilters.text()) |
227 if self.rfOpenFiles.isChecked(): |
331 if self.rfOpenFiles.isChecked() or self.__pyqtVariant == 5: |
228 code += ',{0}{1}None'.format(os.linesep, istring) |
332 if self.eInitialFilter.text() == "": |
|
333 filter = "None" |
|
334 else: |
|
335 if self.cInitialFilter.isChecked(): |
|
336 fmt = '{0}' |
|
337 else: |
|
338 fmt = 'self.trUtf8("{0}")' |
|
339 filter = fmt.format(self.eInitialFilter.text()) |
|
340 code += ',{0}{1}{2}'.format(os.linesep, istring, filter) |
229 if not self.cSymlinks.isChecked(): |
341 if not self.cSymlinks.isChecked(): |
230 code += \ |
342 code += \ |
231 ',{0}{1}QFileDialog.Options(' \ |
343 ',{0}{1}QFileDialog.Options(' \ |
232 'QFileDialog.DontResolveSymlinks)' \ |
344 'QFileDialog.DontResolveSymlinks)' \ |
233 .format(os.linesep, istring) |
345 .format(os.linesep, istring) |
236 if self.rSaveFile.isChecked(): |
348 if self.rSaveFile.isChecked(): |
237 code += 'getSaveFileName({0}{1}'.format(os.linesep, istring) |
349 code += 'getSaveFileName({0}{1}'.format(os.linesep, istring) |
238 else: |
350 else: |
239 code += 'getSaveFileNameAndFilter({0}{1}'.format( |
351 code += 'getSaveFileNameAndFilter({0}{1}'.format( |
240 os.linesep, istring) |
352 os.linesep, istring) |
241 code += 'None,{0}{1}'.format(os.linesep, istring) |
353 code += '{0},{1}{2}'.format(parent, os.linesep, istring) |
242 if not self.eCaption.text(): |
354 if not self.eCaption.text(): |
243 code += '"",{0}{1}'.format(os.linesep, istring) |
355 code += '"",{0}{1}'.format(os.linesep, istring) |
244 else: |
356 else: |
245 code += 'self.trUtf8("{0}"),{1}{2}'.format( |
357 code += 'self.trUtf8("{0}"),{1}{2}'.format( |
246 self.eCaption.text(), os.linesep, istring) |
358 self.eCaption.text(), os.linesep, istring) |
258 if self.cFilters.isChecked(): |
370 if self.cFilters.isChecked(): |
259 fmt = '{0}' |
371 fmt = '{0}' |
260 else: |
372 else: |
261 fmt = 'self.trUtf8("{0}")' |
373 fmt = 'self.trUtf8("{0}")' |
262 code += fmt.format(self.eFilters.text()) |
374 code += fmt.format(self.eFilters.text()) |
263 if self.rfSaveFile.isChecked(): |
375 if self.rfSaveFile.isChecked() or self.__pyqtVariant == 5: |
264 code += ',{0}{1}None'.format(os.linesep, istring) |
376 if self.eInitialFilter.text() == "": |
|
377 filter = "None" |
|
378 else: |
|
379 if self.cInitialFilter.isChecked(): |
|
380 fmt = '{0}' |
|
381 else: |
|
382 fmt = 'self.trUtf8("{0}")' |
|
383 filter = fmt.format(self.eInitialFilter.text()) |
|
384 code += ',{0}{1}{2}'.format(os.linesep, istring, filter) |
265 if (not self.cSymlinks.isChecked()) or \ |
385 if (not self.cSymlinks.isChecked()) or \ |
266 (not self.cConfirmOverwrite.isChecked()): |
386 (not self.cConfirmOverwrite.isChecked()): |
267 code += ',{0}{1}QFileDialog.Options('.format( |
387 code += ',{0}{1}QFileDialog.Options('.format( |
268 os.linesep, istring) |
388 os.linesep, istring) |
269 if not self.cSymlinks.isChecked(): |
389 if not self.cSymlinks.isChecked(): |
275 code += 'QFileDialog.DontConfirmOverwrite' |
395 code += 'QFileDialog.DontConfirmOverwrite' |
276 code += ')' |
396 code += ')' |
277 code += '){0}'.format(estring) |
397 code += '){0}'.format(estring) |
278 elif self.rDirectory.isChecked(): |
398 elif self.rDirectory.isChecked(): |
279 code += 'getExistingDirectory({0}{1}'.format(os.linesep, istring) |
399 code += 'getExistingDirectory({0}{1}'.format(os.linesep, istring) |
280 code += 'None,{0}{1}'.format(os.linesep, istring) |
400 code += '{0},{1}{2}'.format(parent, os.linesep, istring) |
281 if not self.eCaption.text(): |
401 if not self.eCaption.text(): |
282 code += '"",{0}{1}'.format(os.linesep, istring) |
402 code += '"",{0}{1}'.format(os.linesep, istring) |
283 else: |
403 else: |
284 code += 'self.trUtf8("{0}"),{1}{2}'.format( |
404 code += 'self.trUtf8("{0}"),{1}{2}'.format( |
285 self.eCaption.text(), os.linesep, istring) |
405 self.eCaption.text(), os.linesep, istring) |