eric6/Plugins/WizardPlugins/E5MessageBoxWizard/E5MessageBoxWizardDialog.py

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

eric ide

mercurial