|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 """ |
|
4 Module implementing the eric5 message box wizard dialog. |
|
5 """ |
|
6 |
|
7 import os |
|
8 |
|
9 from PyQt4.QtCore import pyqtSlot |
|
10 from PyQt4.QtGui import QDialog, QDialogButtonBox, QAbstractButton |
|
11 |
|
12 from E5Gui import E5MessageBox |
|
13 |
|
14 from .Ui_E5MessageBoxWizardDialog import Ui_E5MessageBoxWizardDialog |
|
15 |
|
16 class E5MessageBoxWizardDialog(QDialog, Ui_E5MessageBoxWizardDialog): |
|
17 """ |
|
18 Class implementing the eric5 message box wizard dialog. |
|
19 |
|
20 It displays a dialog for entering the parameters |
|
21 for the E5MessageBox code generator. |
|
22 """ |
|
23 def __init__(self, parent = None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param parent reference to the parent widget (QWidget) |
|
28 """ |
|
29 QDialog.__init__(self, parent) |
|
30 self.setupUi(self) |
|
31 |
|
32 # keep the following three lists in sync |
|
33 self.buttonsList = [ |
|
34 self.trUtf8("No button"), |
|
35 self.trUtf8("Abort"), |
|
36 self.trUtf8("Apply"), |
|
37 self.trUtf8("Cancel"), |
|
38 self.trUtf8("Close"), |
|
39 self.trUtf8("Discard"), |
|
40 self.trUtf8("Help"), |
|
41 self.trUtf8("Ignore"), |
|
42 self.trUtf8("No"), |
|
43 self.trUtf8("No to all"), |
|
44 self.trUtf8("Ok"), |
|
45 self.trUtf8("Open"), |
|
46 self.trUtf8("Reset"), |
|
47 self.trUtf8("Restore defaults"), |
|
48 self.trUtf8("Retry"), |
|
49 self.trUtf8("Save"), |
|
50 self.trUtf8("Save all"), |
|
51 self.trUtf8("Yes"), |
|
52 self.trUtf8("Yes to all"), |
|
53 ] |
|
54 self.buttonsCodeListBinary = [ |
|
55 E5MessageBox.NoButton, |
|
56 E5MessageBox.Abort, |
|
57 E5MessageBox.Apply, |
|
58 E5MessageBox.Cancel, |
|
59 E5MessageBox.Close, |
|
60 E5MessageBox.Discard, |
|
61 E5MessageBox.Help, |
|
62 E5MessageBox.Ignore, |
|
63 E5MessageBox.No, |
|
64 E5MessageBox.NoToAll, |
|
65 E5MessageBox.Ok, |
|
66 E5MessageBox.Open, |
|
67 E5MessageBox.Reset, |
|
68 E5MessageBox.RestoreDefaults, |
|
69 E5MessageBox.Retry, |
|
70 E5MessageBox.Save, |
|
71 E5MessageBox.SaveAll, |
|
72 E5MessageBox.Yes, |
|
73 E5MessageBox.YesToAll, |
|
74 ] |
|
75 self.buttonsCodeListText = [ |
|
76 "E5MessageBox.NoButton", |
|
77 "E5MessageBox.Abort", |
|
78 "E5MessageBox.Apply", |
|
79 "E5MessageBox.Cancel", |
|
80 "E5MessageBox.Close", |
|
81 "E5MessageBox.Discard", |
|
82 "E5MessageBox.Help", |
|
83 "E5MessageBox.Ignore", |
|
84 "E5MessageBox.No", |
|
85 "E5MessageBox.NoToAll", |
|
86 "E5MessageBox.Ok", |
|
87 "E5MessageBox.Open", |
|
88 "E5MessageBox.Reset", |
|
89 "E5MessageBox.RestoreDefaults", |
|
90 "E5MessageBox.Retry", |
|
91 "E5MessageBox.Save", |
|
92 "E5MessageBox.SaveAll", |
|
93 "E5MessageBox.Yes", |
|
94 "E5MessageBox.YesToAll", |
|
95 ] |
|
96 |
|
97 self.defaultCombo.addItems(self.buttonsList) |
|
98 |
|
99 self.bTest = \ |
|
100 self.buttonBox.addButton(self.trUtf8("Test"), QDialogButtonBox.ActionRole) |
|
101 |
|
102 self.__enabledGroups() |
|
103 |
|
104 def __enabledGroups(self): |
|
105 """ |
|
106 Private method to enable/disable some group boxes. |
|
107 """ |
|
108 self.standardButtons.setEnabled( |
|
109 self.rInformation.isChecked() or \ |
|
110 self.rQuestion.isChecked() or \ |
|
111 self.rWarning.isChecked() or \ |
|
112 self.rCritical.isChecked() or \ |
|
113 self.rStandard.isChecked() |
|
114 ) |
|
115 |
|
116 self.defaultButton.setEnabled( |
|
117 self.rInformation.isChecked() or \ |
|
118 self.rQuestion.isChecked() or \ |
|
119 self.rWarning.isChecked() or \ |
|
120 self.rCritical.isChecked() |
|
121 ) |
|
122 |
|
123 self.iconBox.setEnabled( |
|
124 self.rYesNo.isChecked() or \ |
|
125 self.rRetryAbort.isChecked() or \ |
|
126 self.rStandard.isChecked() |
|
127 ) |
|
128 |
|
129 self.bTest.setEnabled(not self.rStandard.isChecked()) |
|
130 |
|
131 @pyqtSlot(bool) |
|
132 def on_rInformation_toggled(self, checked): |
|
133 """ |
|
134 Private slot to handle the toggled signal of the rInformation radio button. |
|
135 |
|
136 @param on toggle state (boolean) (ignored) |
|
137 """ |
|
138 self.__enabledGroups() |
|
139 |
|
140 @pyqtSlot(bool) |
|
141 def on_rQuestion_toggled(self, checked): |
|
142 """ |
|
143 Private slot to handle the toggled signal of the rQuestion radio button. |
|
144 |
|
145 @param on toggle state (boolean) (ignored) |
|
146 """ |
|
147 self.__enabledGroups() |
|
148 |
|
149 @pyqtSlot(bool) |
|
150 def on_rWarning_toggled(self, checked): |
|
151 """ |
|
152 Private slot to handle the toggled signal of the rWarning radio button. |
|
153 |
|
154 @param on toggle state (boolean) (ignored) |
|
155 """ |
|
156 self.__enabledGroups() |
|
157 |
|
158 @pyqtSlot(bool) |
|
159 def on_rCritical_toggled(self, checked): |
|
160 """ |
|
161 Private slot to handle the toggled signal of the rCritical radio button. |
|
162 |
|
163 @param on toggle state (boolean) (ignored) |
|
164 """ |
|
165 self.__enabledGroups() |
|
166 |
|
167 @pyqtSlot(bool) |
|
168 def on_rYesNo_toggled(self, checked): |
|
169 """ |
|
170 Private slot to handle the toggled signal of the rYesNo radio button. |
|
171 |
|
172 @param on toggle state (boolean) (ignored) |
|
173 """ |
|
174 self.__enabledGroups() |
|
175 |
|
176 @pyqtSlot(bool) |
|
177 def on_rRetryAbort_toggled(self, checked): |
|
178 """ |
|
179 Private slot to handle the toggled signal of the rRetryAbort radio button. |
|
180 |
|
181 @param on toggle state (boolean) (ignored) |
|
182 """ |
|
183 self.__enabledGroups() |
|
184 |
|
185 @pyqtSlot(bool) |
|
186 def on_rOkToClearData_toggled(self, checked): |
|
187 """ |
|
188 Private slot to handle the toggled signal of the rOkToClearData radio button. |
|
189 |
|
190 @param on toggle state (boolean) (ignored) |
|
191 """ |
|
192 self.__enabledGroups() |
|
193 |
|
194 @pyqtSlot(bool) |
|
195 def on_rAbout_toggled(self, checked): |
|
196 """ |
|
197 Private slot to handle the toggled signal of the rAbout radio button. |
|
198 |
|
199 @param on toggle state (boolean) (ignored) |
|
200 """ |
|
201 self.__enabledGroups() |
|
202 |
|
203 @pyqtSlot(bool) |
|
204 def on_rAboutQt_toggled(self, checked): |
|
205 """ |
|
206 Private slot to handle the toggled signal of the rAboutQt radio button. |
|
207 |
|
208 @param on toggle state (boolean) (ignored) |
|
209 """ |
|
210 self.__enabledGroups() |
|
211 |
|
212 @pyqtSlot(bool) |
|
213 def on_rStandard_toggled(self, checked): |
|
214 """ |
|
215 Private slot to handle the toggled signal of the rStandard radio button. |
|
216 |
|
217 @param on toggle state (boolean) (ignored) |
|
218 """ |
|
219 self.__enabledGroups() |
|
220 |
|
221 @pyqtSlot(QAbstractButton) |
|
222 def on_buttonBox_clicked(self, button): |
|
223 """ |
|
224 Private slot called by a button of the button box clicked. |
|
225 |
|
226 @param button button that was clicked (QAbstractButton) |
|
227 """ |
|
228 if button == self.bTest: |
|
229 self.on_bTest_clicked() |
|
230 |
|
231 @pyqtSlot() |
|
232 def on_bTest_clicked(self): |
|
233 """ |
|
234 Private method to test the selected options. |
|
235 """ |
|
236 if self.rAbout.isChecked(): |
|
237 E5MessageBox.about(None, |
|
238 self.eCaption.text(), |
|
239 self.eMessage.toPlainText() |
|
240 ) |
|
241 elif self.rAboutQt.isChecked(): |
|
242 E5MessageBox.aboutQt(None, |
|
243 self.eCaption.text() |
|
244 ) |
|
245 elif self.rInformation.isChecked() or \ |
|
246 self.rQuestion.isChecked() or \ |
|
247 self.rWarning.isChecked() or \ |
|
248 self.rCritical.isChecked(): |
|
249 buttons = E5MessageBox.NoButton |
|
250 if self.abortCheck.isChecked(): |
|
251 buttons |= E5MessageBox.Abort |
|
252 if self.applyCheck.isChecked(): |
|
253 buttons |= E5MessageBox.Apply |
|
254 if self.cancelCheck.isChecked(): |
|
255 buttons |= E5MessageBox.Cancel |
|
256 if self.closeCheck.isChecked(): |
|
257 buttons |= E5MessageBox.Close |
|
258 if self.discardCheck.isChecked(): |
|
259 buttons |= E5MessageBox.Discard |
|
260 if self.helpCheck.isChecked(): |
|
261 buttons |= E5MessageBox.Help |
|
262 if self.ignoreCheck.isChecked(): |
|
263 buttons |= E5MessageBox.Ignore |
|
264 if self.noCheck.isChecked(): |
|
265 buttons |= E5MessageBox.No |
|
266 if self.notoallCheck.isChecked(): |
|
267 buttons |= E5MessageBox.NoToAll |
|
268 if self.okCheck.isChecked(): |
|
269 buttons |= E5MessageBox.Ok |
|
270 if self.openCheck.isChecked(): |
|
271 buttons |= E5MessageBox.Open |
|
272 if self.resetCheck.isChecked(): |
|
273 buttons |= E5MessageBox.Reset |
|
274 if self.restoreCheck.isChecked(): |
|
275 buttons |= E5MessageBox.RestoreDefaults |
|
276 if self.retryCheck.isChecked(): |
|
277 buttons |= E5MessageBox.Retry |
|
278 if self.saveCheck.isChecked(): |
|
279 buttons |= E5MessageBox.Save |
|
280 if self.saveallCheck.isChecked(): |
|
281 buttons |= E5MessageBox.SaveAll |
|
282 if self.yesCheck.isChecked(): |
|
283 buttons |= E5MessageBox.Yes |
|
284 if self.yestoallCheck.isChecked(): |
|
285 buttons |= E5MessageBox.YesToAll |
|
286 if buttons == E5MessageBox.NoButton: |
|
287 buttons = E5MessageBox.Ok |
|
288 |
|
289 defaultButton = self.buttonsCodeListBinary[self.defaultCombo.currentIndex()] |
|
290 |
|
291 if self.rInformation.isChecked(): |
|
292 E5MessageBox.information(self, |
|
293 self.eCaption.text(), |
|
294 self.eMessage.toPlainText(), |
|
295 E5MessageBox.StandardButtons(buttons), |
|
296 defaultButton |
|
297 ) |
|
298 elif self.rQuestion.isChecked(): |
|
299 E5MessageBox.question(self, |
|
300 self.eCaption.text(), |
|
301 self.eMessage.toPlainText(), |
|
302 E5MessageBox.StandardButtons(buttons), |
|
303 defaultButton |
|
304 ) |
|
305 elif self.rWarning.isChecked(): |
|
306 E5MessageBox.warning(self, |
|
307 self.eCaption.text(), |
|
308 self.eMessage.toPlainText(), |
|
309 E5MessageBox.StandardButtons(buttons), |
|
310 defaultButton |
|
311 ) |
|
312 elif self.rCritical.isChecked(): |
|
313 E5MessageBox.critical(self, |
|
314 self.eCaption.text(), |
|
315 self.eMessage.toPlainText(), |
|
316 E5MessageBox.StandardButtons(buttons), |
|
317 defaultButton |
|
318 ) |
|
319 elif self.rYesNo.isChecked() or \ |
|
320 self.rRetryAbort.isChecked(): |
|
321 if self.iconInformation.isChecked(): |
|
322 icon = E5MessageBox.Information |
|
323 elif self.iconQuestion.isChecked(): |
|
324 icon = E5MessageBox.Question |
|
325 elif self.iconWarning.isChecked(): |
|
326 icon = E5MessageBox.Warning |
|
327 elif self.iconCritical.isChecked(): |
|
328 icon = E5MessageBox.Critical |
|
329 |
|
330 if self.rYesNo.isChecked(): |
|
331 E5MessageBox.yesNo(self, |
|
332 self.eCaption.text(), |
|
333 self.eMessage.toPlainText(), |
|
334 icon = icon, |
|
335 yesDefault = self.yesDefaultCheck.isChecked() |
|
336 ) |
|
337 elif self.rRetryAbort.isChecked(): |
|
338 E5MessageBox.retryAbort(self, |
|
339 self.eCaption.text(), |
|
340 self.eMessage.toPlainText(), |
|
341 icon = icon |
|
342 ) |
|
343 elif self.rOkToClearData.isChecked(): |
|
344 E5MessageBox.okToClearData(self, |
|
345 self.eCaption.text(), |
|
346 self.eMessage.toPlainText(), |
|
347 lambda: True |
|
348 ) |
|
349 |
|
350 def __getStandardButtonCode(self, istring, indString, withIntro = True): |
|
351 """ |
|
352 Private method to generate the button code for the standard buttons. |
|
353 |
|
354 @param istring indentation string (string) |
|
355 @param indString string used for indentation (space or tab) (string) |
|
356 @keyparam withIntro flag indicating to generate a first line |
|
357 with introductory text (boolean) |
|
358 @return the button code (string) |
|
359 """ |
|
360 buttons = [] |
|
361 if self.abortCheck.isChecked(): |
|
362 buttons.append("E5MessageBox.Abort") |
|
363 if self.applyCheck.isChecked(): |
|
364 buttons.append("E5MessageBox.Apply") |
|
365 if self.cancelCheck.isChecked(): |
|
366 buttons.append("E5MessageBox.Cancel") |
|
367 if self.closeCheck.isChecked(): |
|
368 buttons.append("E5MessageBox.Close") |
|
369 if self.discardCheck.isChecked(): |
|
370 buttons.append("E5MessageBox.Discard") |
|
371 if self.helpCheck.isChecked(): |
|
372 buttons.append("E5MessageBox.Help") |
|
373 if self.ignoreCheck.isChecked(): |
|
374 buttons.append("E5MessageBox.Ignore") |
|
375 if self.noCheck.isChecked(): |
|
376 buttons.append("E5MessageBox.No") |
|
377 if self.notoallCheck.isChecked(): |
|
378 buttons.append("E5MessageBox.NoToAll") |
|
379 if self.okCheck.isChecked(): |
|
380 buttons.append("E5MessageBox.Ok") |
|
381 if self.openCheck.isChecked(): |
|
382 buttons.append("E5MessageBox.Open") |
|
383 if self.resetCheck.isChecked(): |
|
384 buttons.append("E5MessageBox.Reset") |
|
385 if self.restoreCheck.isChecked(): |
|
386 buttons.append("E5MessageBox.RestoreDefaults") |
|
387 if self.retryCheck.isChecked(): |
|
388 buttons.append("E5MessageBox.Retry") |
|
389 if self.saveCheck.isChecked(): |
|
390 buttons.append("E5MessageBox.Save") |
|
391 if self.saveallCheck.isChecked(): |
|
392 buttons.append("E5MessageBox.SaveAll") |
|
393 if self.yesCheck.isChecked(): |
|
394 buttons.append("E5MessageBox.Yes") |
|
395 if self.yestoallCheck.isChecked(): |
|
396 buttons.append("E5MessageBox.YesToAll") |
|
397 if len(buttons) == 0: |
|
398 return "" |
|
399 |
|
400 istring2 = istring + indString |
|
401 joinstring = ' | \\{0}{1}'.format(os.linesep, istring2) |
|
402 if withIntro: |
|
403 btnCode = ',{0}{1}E5MessageBox.StandardButtons('.format(os.linesep, istring) |
|
404 else: |
|
405 btnCode = 'E5MessageBox.StandardButtons('.format(os.linesep, istring) |
|
406 btnCode += '{0}{1}{2})'.format(os.linesep, istring2, joinstring.join(buttons)) |
|
407 |
|
408 return btnCode |
|
409 |
|
410 def __getDefaultButtonCode(self, istring): |
|
411 """ |
|
412 Private method to generate the button code for the default button. |
|
413 |
|
414 @param istring indentation string (string) |
|
415 @param indString string used for indentation (space or tab) (string) |
|
416 @return the button code (string) |
|
417 """ |
|
418 btnCode = "" |
|
419 defaultIndex = self.defaultCombo.currentIndex() |
|
420 if defaultIndex: |
|
421 btnCode = ',{0}{1}{2}'.format(os.linesep, istring, |
|
422 self.buttonsCodeListText[defaultIndex]) |
|
423 return btnCode |
|
424 |
|
425 def getCode(self, indLevel, indString): |
|
426 """ |
|
427 Public method to get the source code. |
|
428 |
|
429 @param indLevel indentation level (int) |
|
430 @param indString string used for indentation (space or tab) (string) |
|
431 @return generated code (string) |
|
432 """ |
|
433 # calculate our indentation level and the indentation string |
|
434 il = indLevel + 1 |
|
435 istring = il * indString |
|
436 estring = os.linesep + indLevel * indString |
|
437 |
|
438 # now generate the code |
|
439 if self.parentSelf.isChecked(): |
|
440 parent = "self" |
|
441 elif self.parentNone.isChecked(): |
|
442 parent = "None" |
|
443 elif self.parentOther.isChecked(): |
|
444 parent = self.parentEdit.text() |
|
445 if parent == "": |
|
446 parent = "None" |
|
447 |
|
448 if self.iconInformation.isChecked(): |
|
449 icon = "E5MessageBox.Information" |
|
450 elif self.iconQuestion.isChecked(): |
|
451 icon = "E5MessageBox.Question" |
|
452 elif self.iconWarning.isChecked(): |
|
453 icon = "E5MessageBox.Warning" |
|
454 elif self.iconCritical.isChecked(): |
|
455 icon = "E5MessageBox.Critical" |
|
456 |
|
457 if not self.rStandard.isChecked(): |
|
458 if self.rAbout.isChecked(): |
|
459 msgdlg = "E5MessageBox.about({0},{1}".format(parent, os.linesep) |
|
460 elif self.rAboutQt.isChecked(): |
|
461 msgdlg = "E5MessageBox.aboutQt({0},{1}".format(parent, os.linesep) |
|
462 elif self.rInformation.isChecked(): |
|
463 msgdlg = "res = E5MessageBox.information({0},{1}".format( |
|
464 parent, os.linesep) |
|
465 elif self.rQuestion.isChecked(): |
|
466 msgdlg = "res = E5MessageBox.question({0},{1}".format(parent, os.linesep) |
|
467 elif self.rWarning.isChecked(): |
|
468 msgdlg = "res = E5MessageBox.warning({0},{1}".format(parent, os.linesep) |
|
469 elif self.rCritical.isChecked(): |
|
470 msgdlg ="res = E5MessageBox.critical({0},{1}".format(parent, os.linesep) |
|
471 elif self.rYesNo.isChecked(): |
|
472 msgdlg ="res = E5MessageBox.yesNo({0},{1}".format(parent, os.linesep) |
|
473 elif self.rRetryAbort.isChecked(): |
|
474 msgdlg ="res = E5MessageBox.retryAbort({0},{1}".format(parent, os.linesep) |
|
475 elif self.rOkToClearData.isChecked(): |
|
476 msgdlg ="res = E5MessageBox.okToClearData({0},{1}".format( |
|
477 parent, os.linesep) |
|
478 |
|
479 msgdlg += '{0}self.trUtf8("{1}")'.format(istring, self.eCaption.text()) |
|
480 |
|
481 if not self.rAboutQt.isChecked(): |
|
482 msgdlg += ',{0}{1}self.trUtf8("""{2}""")'.format( |
|
483 os.linesep, istring, self.eMessage.toPlainText()) |
|
484 |
|
485 if self.rInformation.isChecked() or \ |
|
486 self.rQuestion.isChecked() or \ |
|
487 self.rWarning.isChecked() or \ |
|
488 self.rCritical.isChecked(): |
|
489 msgdlg += self.__getStandardButtonCode(istring, indString) |
|
490 msgdlg += self.__getDefaultButtonCode(istring) |
|
491 elif self.rYesNo.isChecked(): |
|
492 if not self.iconQuestion.isChecked(): |
|
493 msgdlg += ',{0}{1}icon = {2}'.format(os.linesep, istring, icon) |
|
494 if self.yesDefaultCheck.isChecked(): |
|
495 msgdlg += ',{0}{1}yesDefault = True'.format(os.linesep, istring) |
|
496 elif self.rRetryAbort.isChecked(): |
|
497 if not self.iconQuestion.isChecked(): |
|
498 msgdlg += ',{0}{1}icon = {2}'.format(os.linesep, istring, icon) |
|
499 elif self.rOkToClearData.isChecked(): |
|
500 saveFunc = self.saveFuncEdit.text() |
|
501 if saveFunc == "": |
|
502 saveFunc = "lambda: True" |
|
503 msgdlg += ',{0}{1}{2}'.format(os.linesep, istring, saveFunc) |
|
504 else: |
|
505 msgdlg ="E5MessageBox.E5MessageBox({0}, {1}".format(icon, os.linesep) |
|
506 msgdlg += '{0}self.trUtf8("{1}")'.format(istring, self.eCaption.text()) |
|
507 msgdlg += ',{0}{1}self.trUtf8("""{2}""")'.format( |
|
508 os.linesep, istring, self.eMessage.toPlainText()) |
|
509 if self.modalCheck.isChecked(): |
|
510 msgdlg += ',{0}{1}modal = True'.format(os.linesep, istring) |
|
511 btnCode = self.__getStandardButtonCode(istring, indString, withIntro = False) |
|
512 if btnCode: |
|
513 msgdlg += ',{0}{1}buttons = {2}'.format(os.linesep, istring, btnCode) |
|
514 if not self.parentNone.isChecked(): |
|
515 msgdlg += ',{0}{1}parent = {2}'.format(os.linesep, istring, parent) |
|
516 |
|
517 msgdlg +='){0}'.format(estring) |
|
518 return msgdlg |