|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2003 - 2009 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 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_FileDialogWizardDialog import Ui_FileDialogWizardDialog |
|
20 |
|
21 class FileDialogWizardDialog(QDialog, Ui_FileDialogWizardDialog): |
|
22 """ |
|
23 Class implementing the color dialog wizard dialog. |
|
24 |
|
25 It displays a dialog for entering the parameters |
|
26 for the QFileDialog code generator. |
|
27 """ |
|
28 def __init__(self, parent=None): |
|
29 """ |
|
30 Constructor |
|
31 |
|
32 @param parent parent widget (QWidget) |
|
33 """ |
|
34 QDialog.__init__(self, parent) |
|
35 self.setupUi(self) |
|
36 |
|
37 self.eStartWithCompleter = E4FileCompleter(self.eStartWith) |
|
38 self.eWorkDirCompleter = E4DirCompleter(self.eWorkDir) |
|
39 |
|
40 self.connect(self.rSaveFile, SIGNAL("toggled(bool)"), |
|
41 self.__toggleConfirmCheckBox) |
|
42 self.connect(self.rfSaveFile, SIGNAL("toggled(bool)"), |
|
43 self.__toggleConfirmCheckBox) |
|
44 self.connect(self.rDirectory, SIGNAL("toggled(bool)"), |
|
45 self.__toggleGroupsAndTest) |
|
46 self.connect(self.cStartWith, SIGNAL("toggled(bool)"), |
|
47 self.__toggleGroupsAndTest) |
|
48 self.connect(self.cWorkDir, SIGNAL("toggled(bool)"), |
|
49 self.__toggleGroupsAndTest) |
|
50 self.connect(self.cFilters, SIGNAL("toggled(bool)"), |
|
51 self.__toggleGroupsAndTest) |
|
52 |
|
53 self.bTest = \ |
|
54 self.buttonBox.addButton(self.trUtf8("Test"), QDialogButtonBox.ActionRole) |
|
55 |
|
56 def on_buttonBox_clicked(self, button): |
|
57 """ |
|
58 Private slot called by a button of the button box clicked. |
|
59 |
|
60 @param button button that was clicked (QAbstractButton) |
|
61 """ |
|
62 if button == self.bTest: |
|
63 self.on_bTest_clicked() |
|
64 |
|
65 @pyqtSlot() |
|
66 def on_bTest_clicked(self): |
|
67 """ |
|
68 Private method to test the selected options. |
|
69 """ |
|
70 if self.rOpenFile.isChecked() or self.rfOpenFile.isChecked(): |
|
71 if not self.cSymlinks.isChecked(): |
|
72 options = QFileDialog.Options(QFileDialog.DontResolveSymlinks) |
|
73 else: |
|
74 options = QFileDialog.Options() |
|
75 QFileDialog.getOpenFileName(\ |
|
76 None, |
|
77 self.eCaption.text(), |
|
78 self.eStartWith.text(), |
|
79 self.eFilters.text(), |
|
80 options) |
|
81 elif self.rOpenFiles.isChecked() or self.rfOpenFiles.isChecked(): |
|
82 if not self.cSymlinks.isChecked(): |
|
83 options = QFileDialog.Options(QFileDialog.DontResolveSymlinks) |
|
84 else: |
|
85 options = QFileDialog.Options() |
|
86 QFileDialog.getOpenFileNames(\ |
|
87 None, |
|
88 self.eCaption.text(), |
|
89 self.eStartWith.text(), |
|
90 self.eFilters.text(), |
|
91 options) |
|
92 elif self.rSaveFile.isChecked() or self.rfSaveFile.isChecked(): |
|
93 if not self.cSymlinks.isChecked(): |
|
94 options = QFileDialog.Options(QFileDialog.DontResolveSymlinks) |
|
95 else: |
|
96 options = QFileDialog.Options() |
|
97 QFileDialog.getSaveFileName(\ |
|
98 None, |
|
99 self.eCaption.text(), |
|
100 self.eStartWith.text(), |
|
101 self.eFilters.text(), |
|
102 options) |
|
103 elif self.rDirectory.isChecked(): |
|
104 options = QFileDialog.Options() |
|
105 if not self.cSymlinks.isChecked(): |
|
106 options |= QFileDialog.Options(QFileDialog.DontResolveSymlinks) |
|
107 if self.cDirOnly.isChecked(): |
|
108 options |= QFileDialog.Options(QFileDialog.ShowDirsOnly) |
|
109 else: |
|
110 options |= QFileDialog.Options(QFileDialog.Option(0)) |
|
111 QFileDialog.getExistingDirectory(\ |
|
112 None, |
|
113 self.eCaption.text(), |
|
114 self.eWorkDir.text(), |
|
115 options) |
|
116 |
|
117 def __toggleConfirmCheckBox(self): |
|
118 """ |
|
119 Private slot to enable/disable the confirmation check box. |
|
120 """ |
|
121 self.cConfirmOverwrite.setEnabled( |
|
122 self.rSaveFile.isChecked() or self.rfSaveFile.isChecked()) |
|
123 |
|
124 def __toggleGroupsAndTest(self): |
|
125 """ |
|
126 Private slot to enable/disable certain groups and the test button. |
|
127 """ |
|
128 if self.rDirectory.isChecked(): |
|
129 self.filePropertiesGroup.setEnabled(False) |
|
130 self.dirPropertiesGroup.setEnabled(True) |
|
131 self.bTest.setDisabled(self.cWorkDir.isChecked()) |
|
132 else: |
|
133 self.filePropertiesGroup.setEnabled(True) |
|
134 self.dirPropertiesGroup.setEnabled(False) |
|
135 self.bTest.setDisabled(\ |
|
136 self.cStartWith.isChecked() or self.cFilters.isChecked()) |
|
137 |
|
138 def __getCode4(self, indLevel, indString): |
|
139 """ |
|
140 Private method to get the source code for Qt4. |
|
141 |
|
142 @param indLevel indentation level (int) |
|
143 @param indString string used for indentation (space or tab) (string) |
|
144 @return generated code (string) |
|
145 """ |
|
146 # calculate our indentation level and the indentation string |
|
147 il = indLevel + 1 |
|
148 istring = il * indString |
|
149 |
|
150 # now generate the code |
|
151 code = 'QFileDialog.' |
|
152 if self.rOpenFile.isChecked() or self.rfOpenFile.isChecked(): |
|
153 if self.rOpenFile.isChecked(): |
|
154 code += 'getOpenFileName(\\%s%s' % (os.linesep, istring) |
|
155 else: |
|
156 code += 'getOpenFileNameAndFilter(\\%s%s' % (os.linesep, istring) |
|
157 code += 'None,%s%s' % (os.linesep, istring) |
|
158 if not self.eCaption.text(): |
|
159 code += '"",%s%s' % (os.linesep, istring) |
|
160 else: |
|
161 code += 'self.trUtf8("%s"),%s%s' % \ |
|
162 (self.eCaption.text(), os.linesep, istring) |
|
163 if not self.eStartWith.text(): |
|
164 code += '"",%s%s' % (os.linesep, istring) |
|
165 else: |
|
166 if self.cStartWith.isChecked(): |
|
167 fmt = '%s,%s%s' |
|
168 else: |
|
169 fmt = 'self.trUtf8("%s"),%s%s' |
|
170 code += fmt % (self.eStartWith.text(), os.linesep, istring) |
|
171 if self.eFilters.text(): |
|
172 code += '""' |
|
173 else: |
|
174 if self.cFilters.isChecked(): |
|
175 fmt = '%s' |
|
176 else: |
|
177 fmt = 'self.trUtf8("%s")' |
|
178 code += fmt % self.eFilters.text() |
|
179 if self.rfOpenFile.isChecked(): |
|
180 code += ',%s%sNone' % (os.linesep, istring) |
|
181 if not self.cSymlinks.isChecked(): |
|
182 code += ',%s%sQFileDialog.Options(QFileDialog.DontResolveSymlinks)' % \ |
|
183 (os.linesep, istring) |
|
184 code += ')%s' % os.linesep |
|
185 elif self.rOpenFiles.isChecked() or self.rfOpenFiles.isChecked(): |
|
186 if self.rOpenFiles.isChecked(): |
|
187 code += 'getOpenFileNames(\\%s%s' % (os.linesep, istring) |
|
188 else: |
|
189 code += 'getOpenFileNamesAndFilter(\\%s%s' % (os.linesep, istring) |
|
190 code += 'None,%s%s' % (os.linesep, istring) |
|
191 if not self.eCaption.text(): |
|
192 code += '"",%s%s' % (os.linesep, istring) |
|
193 else: |
|
194 code += 'self.trUtf8("%s"),%s%s' % \ |
|
195 (self.eCaption.text(), os.linesep, istring) |
|
196 if not self.eStartWith.text(): |
|
197 code += '"",%s%s' % (os.linesep, istring) |
|
198 else: |
|
199 if self.cStartWith.isChecked(): |
|
200 fmt = '%s,%s%s' |
|
201 else: |
|
202 fmt = 'self.trUtf8("%s"),%s%s' |
|
203 code += fmt % (self.eStartWith.text(), os.linesep, istring) |
|
204 if not self.eFilters.text(): |
|
205 code += '""' |
|
206 else: |
|
207 if self.cFilters.isChecked(): |
|
208 fmt = '%s' |
|
209 else: |
|
210 fmt = 'self.trUtf8("%s")' |
|
211 code += fmt % self.eFilters.text() |
|
212 if self.rfOpenFiles.isChecked(): |
|
213 code += ',%s%sNone' % (os.linesep, istring) |
|
214 if not self.cSymlinks.isChecked(): |
|
215 code += ',%s%sQFileDialog.Options(QFileDialog.DontResolveSymlinks)' % \ |
|
216 (os.linesep, istring) |
|
217 code += ')%s' % os.linesep |
|
218 elif self.rSaveFile.isChecked() or self.rfSaveFile.isChecked(): |
|
219 if self.rSaveFile.isChecked(): |
|
220 code += 'getSaveFileName(\\%s%s' % (os.linesep, istring) |
|
221 else: |
|
222 code += 'getSaveFileNameAndFilter(\\%s%s' % (os.linesep, istring) |
|
223 code += 'None,%s%s' % (os.linesep, istring) |
|
224 if not self.eCaption.text(): |
|
225 code += '"",%s%s' % (os.linesep, istring) |
|
226 else: |
|
227 code += 'self.trUtf8("%s"),%s%s' % \ |
|
228 (self.eCaption.text(), os.linesep, istring) |
|
229 if not self.eStartWith.text(): |
|
230 code += '"",%s%s' % (os.linesep, istring) |
|
231 else: |
|
232 if self.cStartWith.isChecked(): |
|
233 fmt = '%s,%s%s' |
|
234 else: |
|
235 fmt = 'self.trUtf8("%s"),%s%s' |
|
236 code += fmt % (self.eStartWith.text(), os.linesep, istring) |
|
237 if not self.eFilters.text(): |
|
238 code += '""' |
|
239 else: |
|
240 if self.cFilters.isChecked(): |
|
241 fmt = '%s' |
|
242 else: |
|
243 fmt = 'self.trUtf8("%s")' |
|
244 code += fmt % self.eFilters.text() |
|
245 if self.rfSaveFile.isChecked(): |
|
246 code += ',%s%sNone' % (os.linesep, istring) |
|
247 if (not self.cSymlinks.isChecked()) or \ |
|
248 (not self.cConfirmOverwrite.isChecked()): |
|
249 code += ',%s%sQFileDialog.Options(' % (os.linesep, istring) |
|
250 if not self.cSymlinks.isChecked(): |
|
251 code += 'QFileDialog.DontResolveSymlinks' |
|
252 if (not self.cSymlinks.isChecked()) and \ |
|
253 (not self.cConfirmOverwrite.isChecked()): |
|
254 code += ' | ' |
|
255 if not self.cConfirmOverwrite.isChecked(): |
|
256 code += 'QFileDialog.DontConfirmOverwrite' |
|
257 code += ')' |
|
258 code += ')%s' % os.linesep |
|
259 elif self.rDirectory.isChecked(): |
|
260 code += 'getExistingDirectory(\\%s%s' % (os.linesep, istring) |
|
261 code += 'None,%s%s' % (os.linesep, istring) |
|
262 if not self.eCaption.text(): |
|
263 code += '"",%s%s' % (os.linesep, istring) |
|
264 else: |
|
265 code += 'self.trUtf8("%s"),%s%s' % \ |
|
266 (self.eCaption.text(), os.linesep, istring) |
|
267 if not self.eWorkDir.text(): |
|
268 code += '""' |
|
269 else: |
|
270 if self.cWorkDir.isChecked(): |
|
271 fmt = '%s' |
|
272 else: |
|
273 fmt = 'self.trUtf8("%s")' |
|
274 code += fmt % self.eWorkDir.text() |
|
275 code += ',%s%sQFileDialog.Options(' % (os.linesep, istring) |
|
276 if not self.cSymlinks.isChecked(): |
|
277 code += 'QFileDialog.DontResolveSymlinks | ' |
|
278 if self.cDirOnly.isChecked(): |
|
279 code += 'QFileDialog.ShowDirsOnly' |
|
280 else: |
|
281 code += 'QFileDialog.Option(0)' |
|
282 code += '))%s' % os.linesep |
|
283 |
|
284 return code |
|
285 |
|
286 def getCode(self, indLevel, indString): |
|
287 """ |
|
288 Public method to get the source code. |
|
289 |
|
290 @param indLevel indentation level (int) |
|
291 @param indString string used for indentation (space or tab) (string) |
|
292 @return generated code (string) |
|
293 """ |
|
294 return self.__getCode4(indLevel, indString) |