214 ################################################################################ |
217 ################################################################################ |
215 ## Additional convenience functions ## |
218 ## Additional convenience functions ## |
216 ################################################################################ |
219 ################################################################################ |
217 |
220 |
218 |
221 |
219 def yesNo(parent, title, text, icon=Question, yesDefault=False): |
222 def yesNo(parent, title, text, icon=Question, yesDefault=False, textFormat=Qt.AutoText): |
220 """ |
223 """ |
221 Function to show a model yes/no message box. |
224 Function to show a model yes/no message box. |
222 |
225 |
223 @param parent parent widget of the message box (QWidget) |
226 @param parent parent widget of the message box (QWidget) |
224 @param title caption of the message box (string) |
227 @param title caption of the message box (string) |
225 @param text text to be shown by the message box (string) |
228 @param text text to be shown by the message box (string) |
226 @keyparam icon icon for the dialog (Critical, Information, Question or Warning) |
229 @keyparam icon icon for the dialog (Critical, Information, Question or Warning) |
227 @keyparam yesDefault flag indicating that the Yes button should be the default |
230 @keyparam yesDefault flag indicating that the Yes button should be the default |
228 button (boolean) |
231 button (boolean) |
|
232 @param textFormat format of the text (Qt.TextFormat) |
229 @return flag indicating the selection of the Yes button (boolean) |
233 @return flag indicating the selection of the Yes button (boolean) |
230 """ |
234 """ |
231 assert icon in [Critical, Information, Question, Warning] |
235 assert icon in [Critical, Information, Question, Warning] |
232 |
236 |
233 res = __messageBox(parent, title, text, icon, |
237 res = __messageBox(parent, title, text, icon, |
234 QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No), |
238 QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No), |
235 yesDefault and QMessageBox.Yes or QMessageBox.No) |
239 yesDefault and QMessageBox.Yes or QMessageBox.No, |
|
240 textFormat) |
236 return res == QMessageBox.Yes |
241 return res == QMessageBox.Yes |
237 |
242 |
238 |
243 |
239 def retryAbort(parent, title, text, icon=Question): |
244 def retryAbort(parent, title, text, icon=Question, textFormat=Qt.AutoText): |
240 """ |
245 """ |
241 Function to show a model abort/retry message box. |
246 Function to show a model abort/retry message box. |
242 |
247 |
243 @param parent parent widget of the message box (QWidget) |
248 @param parent parent widget of the message box (QWidget) |
244 @param title caption of the message box (string) |
249 @param title caption of the message box (string) |
245 @param text text to be shown by the message box (string) |
250 @param text text to be shown by the message box (string) |
246 @keyparam icon icon for the dialog (Critical, Information, Question or Warning) |
251 @keyparam icon icon for the dialog (Critical, Information, Question or Warning) |
|
252 @param textFormat format of the text (Qt.TextFormat) |
247 @return flag indicating the selection of the Retry button (boolean) |
253 @return flag indicating the selection of the Retry button (boolean) |
248 """ |
254 """ |
249 assert icon in [Critical, Information, Question, Warning] |
255 assert icon in [Critical, Information, Question, Warning] |
250 |
256 |
251 res = __messageBox(parent, title, text, icon, |
257 res = __messageBox(parent, title, text, icon, |
252 QMessageBox.StandardButtons(QMessageBox.Retry | QMessageBox.Abort), |
258 QMessageBox.StandardButtons(QMessageBox.Retry | QMessageBox.Abort), |
253 QMessageBox.Retry) |
259 QMessageBox.Retry, |
|
260 textFormat) |
254 return res == QMessageBox.Retry |
261 return res == QMessageBox.Retry |
255 |
262 |
256 |
263 |
257 def okToClearData(parent, title, text, saveFunc): |
264 def okToClearData(parent, title, text, saveFunc, textFormat=Qt.AutoText): |
258 """ |
265 """ |
259 Function to show a model message box to ask for clearing the data. |
266 Function to show a model message box to ask for clearing the data. |
260 |
267 |
261 @param parent parent widget of the message box (QWidget) |
268 @param parent parent widget of the message box (QWidget) |
262 @param title caption of the message box (string) |
269 @param title caption of the message box (string) |
263 @param text text to be shown by the message box (string) |
270 @param text text to be shown by the message box (string) |
264 @param saveFunc reference to a function performing the save action. It |
271 @param saveFunc reference to a function performing the save action. It |
265 must be a parameterless function returning a flag indicating success. |
272 must be a parameterless function returning a flag indicating success. |
|
273 @param textFormat format of the text (Qt.TextFormat) |
266 @return flag indicating that it is ok to clear the data (boolean) |
274 @return flag indicating that it is ok to clear the data (boolean) |
267 """ |
275 """ |
268 res = __messageBox(parent, title, text, QMessageBox.Warning, |
276 res = __messageBox(parent, title, text, QMessageBox.Warning, |
269 QMessageBox.StandardButtons( |
277 QMessageBox.StandardButtons( |
270 QMessageBox.Abort | QMessageBox.Discard | QMessageBox.Save), |
278 QMessageBox.Abort | QMessageBox.Discard | QMessageBox.Save), |
271 QMessageBox.Save) |
279 QMessageBox.Save, |
|
280 textFormat) |
272 if res == QMessageBox.Abort: |
281 if res == QMessageBox.Abort: |
273 return False |
282 return False |
274 if res == QMessageBox.Save: |
283 if res == QMessageBox.Save: |
275 return saveFunc() |
284 return saveFunc() |
276 return True |
285 return True |