|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2003 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the message box 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 Ui_MessageBoxWizardDialog import Ui_MessageBoxWizardDialog |
|
18 |
|
19 class MessageBoxWizardDialog(QDialog, Ui_MessageBoxWizardDialog): |
|
20 """ |
|
21 Class implementing the message box wizard dialog. |
|
22 |
|
23 It displays a dialog for entering the parameters |
|
24 for the QMessageBox code generator. |
|
25 """ |
|
26 def __init__(self, parent=None): |
|
27 """ |
|
28 Constructor |
|
29 |
|
30 @param parent parent widget (QWidget) |
|
31 """ |
|
32 QDialog.__init__(self, parent) |
|
33 self.setupUi(self) |
|
34 |
|
35 # keep the following three lists in sync |
|
36 self.buttonsList = [ |
|
37 self.trUtf8("No button"), |
|
38 self.trUtf8("Abort"), |
|
39 self.trUtf8("Apply"), |
|
40 self.trUtf8("Cancel"), |
|
41 self.trUtf8("Close"), |
|
42 self.trUtf8("Discard"), |
|
43 self.trUtf8("Help"), |
|
44 self.trUtf8("Ignore"), |
|
45 self.trUtf8("No"), |
|
46 self.trUtf8("No to all"), |
|
47 self.trUtf8("Ok"), |
|
48 self.trUtf8("Open"), |
|
49 self.trUtf8("Reset"), |
|
50 self.trUtf8("Restore defaults"), |
|
51 self.trUtf8("Retry"), |
|
52 self.trUtf8("Save"), |
|
53 self.trUtf8("Save all"), |
|
54 self.trUtf8("Yes"), |
|
55 self.trUtf8("Yes to all"), |
|
56 ] |
|
57 self.buttonsCodeListBinary = [ |
|
58 QMessageBox.NoButton, |
|
59 QMessageBox.Abort, |
|
60 QMessageBox.Apply, |
|
61 QMessageBox.Cancel, |
|
62 QMessageBox.Close, |
|
63 QMessageBox.Discard, |
|
64 QMessageBox.Help, |
|
65 QMessageBox.Ignore, |
|
66 QMessageBox.No, |
|
67 QMessageBox.NoToAll, |
|
68 QMessageBox.Ok, |
|
69 QMessageBox.Open, |
|
70 QMessageBox.Reset, |
|
71 QMessageBox.RestoreDefaults, |
|
72 QMessageBox.Retry, |
|
73 QMessageBox.Save, |
|
74 QMessageBox.SaveAll, |
|
75 QMessageBox.Yes, |
|
76 QMessageBox.YesToAll, |
|
77 ] |
|
78 self.buttonsCodeListText = [ |
|
79 "QMessageBox.NoButton", |
|
80 "QMessageBox.Abort", |
|
81 "QMessageBox.Apply", |
|
82 "QMessageBox.Cancel", |
|
83 "QMessageBox.Close", |
|
84 "QMessageBox.Discard", |
|
85 "QMessageBox.Help", |
|
86 "QMessageBox.Ignore", |
|
87 "QMessageBox.No", |
|
88 "QMessageBox.NoToAll", |
|
89 "QMessageBox.Ok", |
|
90 "QMessageBox.Open", |
|
91 "QMessageBox.Reset", |
|
92 "QMessageBox.RestoreDefaults", |
|
93 "QMessageBox.Retry", |
|
94 "QMessageBox.Save", |
|
95 "QMessageBox.SaveAll", |
|
96 "QMessageBox.Yes", |
|
97 "QMessageBox.YesToAll", |
|
98 ] |
|
99 |
|
100 self.defaultCombo.addItems(self.buttonsList) |
|
101 |
|
102 self.bTest = \ |
|
103 self.buttonBox.addButton(self.trUtf8("Test"), QDialogButtonBox.ActionRole) |
|
104 |
|
105 def __testQt42(self): |
|
106 """ |
|
107 Private method to test the selected options for Qt 4.2.0. |
|
108 """ |
|
109 buttons = QMessageBox.NoButton |
|
110 if self.abortCheck.isChecked(): |
|
111 buttons |= QMessageBox.Abort |
|
112 if self.applyCheck.isChecked(): |
|
113 buttons |= QMessageBox.Apply |
|
114 if self.cancelCheck.isChecked(): |
|
115 buttons |= QMessageBox.Cancel |
|
116 if self.closeCheck.isChecked(): |
|
117 buttons |= QMessageBox.Close |
|
118 if self.discardCheck.isChecked(): |
|
119 buttons |= QMessageBox.Discard |
|
120 if self.helpCheck.isChecked(): |
|
121 buttons |= QMessageBox.Help |
|
122 if self.ignoreCheck.isChecked(): |
|
123 buttons |= QMessageBox.Ignore |
|
124 if self.noCheck.isChecked(): |
|
125 buttons |= QMessageBox.No |
|
126 if self.notoallCheck.isChecked(): |
|
127 buttons |= QMessageBox.NoToAll |
|
128 if self.okCheck.isChecked(): |
|
129 buttons |= QMessageBox.Ok |
|
130 if self.openCheck.isChecked(): |
|
131 buttons |= QMessageBox.Open |
|
132 if self.resetCheck.isChecked(): |
|
133 buttons |= QMessageBox.Reset |
|
134 if self.restoreCheck.isChecked(): |
|
135 buttons |= QMessageBox.RestoreDefaults |
|
136 if self.retryCheck.isChecked(): |
|
137 buttons |= QMessageBox.Retry |
|
138 if self.saveCheck.isChecked(): |
|
139 buttons |= QMessageBox.Save |
|
140 if self.saveallCheck.isChecked(): |
|
141 buttons |= QMessageBox.SaveAll |
|
142 if self.yesCheck.isChecked(): |
|
143 buttons |= QMessageBox.Yes |
|
144 if self.yestoallCheck.isChecked(): |
|
145 buttons |= QMessageBox.YesToAll |
|
146 if buttons == QMessageBox.NoButton: |
|
147 buttons = QMessageBox.Ok |
|
148 |
|
149 defaultButton = self.buttonsCodeListBinary[self.defaultCombo.currentIndex()] |
|
150 |
|
151 if self.rInformation.isChecked(): |
|
152 QMessageBox.information(None, |
|
153 self.eCaption.text(), |
|
154 self.eMessage.toPlainText(), |
|
155 QMessageBox.StandardButtons(buttons), |
|
156 defaultButton |
|
157 ) |
|
158 elif self.rQuestion.isChecked(): |
|
159 QMessageBox.question(None, |
|
160 self.eCaption.text(), |
|
161 self.eMessage.toPlainText(), |
|
162 QMessageBox.StandardButtons(buttons), |
|
163 defaultButton |
|
164 ) |
|
165 elif self.rWarning.isChecked(): |
|
166 QMessageBox.warning(None, |
|
167 self.eCaption.text(), |
|
168 self.eMessage.toPlainText(), |
|
169 QMessageBox.StandardButtons(buttons), |
|
170 defaultButton |
|
171 ) |
|
172 elif self.rCritical.isChecked(): |
|
173 QMessageBox.critical(None, |
|
174 self.eCaption.text(), |
|
175 self.eMessage.toPlainText(), |
|
176 QMessageBox.StandardButtons(buttons), |
|
177 defaultButton |
|
178 ) |
|
179 |
|
180 def on_buttonBox_clicked(self, button): |
|
181 """ |
|
182 Private slot called by a button of the button box clicked. |
|
183 |
|
184 @param button button that was clicked (QAbstractButton) |
|
185 """ |
|
186 if button == self.bTest: |
|
187 self.on_bTest_clicked() |
|
188 |
|
189 @pyqtSlot() |
|
190 def on_bTest_clicked(self): |
|
191 """ |
|
192 Private method to test the selected options. |
|
193 """ |
|
194 if self.rAbout.isChecked(): |
|
195 QMessageBox.about(None, |
|
196 self.eCaption.text(), |
|
197 self.eMessage.toPlainText() |
|
198 ) |
|
199 elif self.rAboutQt.isChecked(): |
|
200 QMessageBox.aboutQt(None, |
|
201 self.eCaption.text() |
|
202 ) |
|
203 else: |
|
204 self.__testQt42() |
|
205 |
|
206 def __enabledGroups(self): |
|
207 """ |
|
208 Private method to enable/disable some group boxes. |
|
209 """ |
|
210 self.standardButtons.setEnabled(not self.rAbout.isChecked() and \ |
|
211 not self.rAboutQt.isChecked() |
|
212 ) |
|
213 |
|
214 def on_rAbout_toggled(self, on): |
|
215 """ |
|
216 Private slot to handle the toggled signal of the rAbout radio button. |
|
217 |
|
218 @param on toggle state (boolean) (ignored) |
|
219 """ |
|
220 self.__enabledGroups() |
|
221 |
|
222 def on_rAboutQt_toggled(self, on): |
|
223 """ |
|
224 Private slot to handle the toggled signal of the rAboutQt radio button. |
|
225 |
|
226 @param on toggle state (boolean) (ignored) |
|
227 """ |
|
228 self.__enabledGroups() |
|
229 |
|
230 def __getQt42ButtonCode(self, istring, indString): |
|
231 """ |
|
232 Private method to generate the button code for Qt 4.2.0. |
|
233 |
|
234 @param istring indentation string (string) |
|
235 @param indString string used for indentation (space or tab) (string) |
|
236 @return the button code (string) |
|
237 """ |
|
238 buttons = [] |
|
239 if self.abortCheck.isChecked(): |
|
240 buttons.append("QMessageBox.Abort") |
|
241 if self.applyCheck.isChecked(): |
|
242 buttons.append("QMessageBox.Apply") |
|
243 if self.cancelCheck.isChecked(): |
|
244 buttons.append("QMessageBox.Cancel") |
|
245 if self.closeCheck.isChecked(): |
|
246 buttons.append("QMessageBox.Close") |
|
247 if self.discardCheck.isChecked(): |
|
248 buttons.append("QMessageBox.Discard") |
|
249 if self.helpCheck.isChecked(): |
|
250 buttons.append("QMessageBox.Help") |
|
251 if self.ignoreCheck.isChecked(): |
|
252 buttons.append("QMessageBox.Ignore") |
|
253 if self.noCheck.isChecked(): |
|
254 buttons.append("QMessageBox.No") |
|
255 if self.notoallCheck.isChecked(): |
|
256 buttons.append("QMessageBox.NoToAll") |
|
257 if self.okCheck.isChecked(): |
|
258 buttons.append("QMessageBox.Ok") |
|
259 if self.openCheck.isChecked(): |
|
260 buttons.append("QMessageBox.Open") |
|
261 if self.resetCheck.isChecked(): |
|
262 buttons.append("QMessageBox.Reset") |
|
263 if self.restoreCheck.isChecked(): |
|
264 buttons.append("QMessageBox.RestoreDefaults") |
|
265 if self.retryCheck.isChecked(): |
|
266 buttons.append("QMessageBox.Retry") |
|
267 if self.saveCheck.isChecked(): |
|
268 buttons.append("QMessageBox.Save") |
|
269 if self.saveallCheck.isChecked(): |
|
270 buttons.append("QMessageBox.SaveAll") |
|
271 if self.yesCheck.isChecked(): |
|
272 buttons.append("QMessageBox.Yes") |
|
273 if self.yestoallCheck.isChecked(): |
|
274 buttons.append("QMessageBox.YesToAll") |
|
275 if len(buttons) == 0: |
|
276 return "" |
|
277 |
|
278 istring2 = istring + indString |
|
279 joinstring = ' | \\%s%s' % (os.linesep, istring2) |
|
280 btnCode = ',%s%sQMessageBox.StandardButtons(\\' % (os.linesep, istring) |
|
281 btnCode += '%s%s%s)' % (os.linesep, istring2, joinstring.join(buttons)) |
|
282 defaultIndex = self.defaultCombo.currentIndex() |
|
283 if defaultIndex: |
|
284 btnCode += ',%s%s%s' % (os.linesep, istring, |
|
285 self.buttonsCodeListText[defaultIndex]) |
|
286 return btnCode |
|
287 |
|
288 def getCode(self, indLevel, indString): |
|
289 """ |
|
290 Public method to get the source code. |
|
291 |
|
292 @param indLevel indentation level (int) |
|
293 @param indString string used for indentation (space or tab) (string) |
|
294 @return generated code (string) |
|
295 """ |
|
296 # calculate our indentation level and the indentation string |
|
297 il = indLevel + 1 |
|
298 istring = il * indString |
|
299 |
|
300 # now generate the code |
|
301 msgdlg = 'QMessageBox.' |
|
302 if self.rAbout.isChecked(): |
|
303 msgdlg += "about(None,%s" % os.linesep |
|
304 elif self.rAboutQt.isChecked(): |
|
305 msgdlg += "aboutQt(None, %s" % os.linesep |
|
306 elif self.rInformation.isChecked(): |
|
307 msgdlg += "information(None,%s" % os.linesep |
|
308 elif self.rQuestion.isChecked(): |
|
309 msgdlg += "question(None,%s" % os.linesep |
|
310 elif self.rWarning.isChecked(): |
|
311 msgdlg += "warning(None,%s" % os.linesep |
|
312 else: |
|
313 msgdlg +="critical(None,%s" % os.linesep |
|
314 msgdlg += '%sself.trUtf8("%s")' % (istring, self.eCaption.text()) |
|
315 if not self.rAboutQt.isChecked(): |
|
316 msgdlg += ',%s%sself.trUtf8("""%s""")' % \ |
|
317 (os.linesep, istring, self.eMessage.toPlainText()) |
|
318 if not self.rAbout.isChecked() and not self.rAboutQt.isChecked(): |
|
319 msgdlg += self.__getQt42ButtonCode(istring, indString) |
|
320 msgdlg +=')%s' % os.linesep |
|
321 return msgdlg |