E5Gui/E5MessageBox.py

changeset 1366
f2e7957924cb
parent 1131
7781e396c903
child 1509
c0b5e693b0eb
equal deleted inserted replaced
1365:8f8cad8f989e 1366:f2e7957924cb
99 ## Replacements for QMessageBox static methods ## 99 ## Replacements for QMessageBox static methods ##
100 ################################################################################ 100 ################################################################################
101 101
102 102
103 def __messageBox(parent, title, text, icon, 103 def __messageBox(parent, title, text, icon,
104 buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton): 104 buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton,
105 textFormat=Qt.AutoText):
105 """ 106 """
106 Private module function to show a modal message box. 107 Private module function to show a modal message box.
107 108
108 @param parent parent widget of the message box (QWidget) 109 @param parent parent widget of the message box (QWidget)
109 @param title caption of the message box (string) 110 @param title caption of the message box (string)
111 @param icon type of icon to be shown (QMessageBox.Icon) 112 @param icon type of icon to be shown (QMessageBox.Icon)
112 @param buttons flags indicating which buttons to show 113 @param buttons flags indicating which buttons to show
113 (QMessageBox.StandardButtons) 114 (QMessageBox.StandardButtons)
114 @param defaultButton flag indicating the default button 115 @param defaultButton flag indicating the default button
115 (QMessageBox.StandardButton) 116 (QMessageBox.StandardButton)
117 @param textFormat format of the text (Qt.TextFormat)
116 @return button pressed by the user (QMessageBox.StandardButton) 118 @return button pressed by the user (QMessageBox.StandardButton)
117 """ 119 """
118 messageBox = QMessageBox(parent) 120 messageBox = QMessageBox(parent)
119 messageBox.setIcon(icon) 121 messageBox.setIcon(icon)
120 if parent is not None: 122 if parent is not None:
123 messageBox.setWindowTitle("{0}".format( 125 messageBox.setWindowTitle("{0}".format(
124 QApplication.applicationName())) 126 QApplication.applicationName()))
125 else: 127 else:
126 messageBox.setWindowTitle("{0} - {1}".format( 128 messageBox.setWindowTitle("{0} - {1}".format(
127 QApplication.applicationName(), title)) 129 QApplication.applicationName(), title))
130 messageBox.setTextFormat(textFormat)
128 messageBox.setText(text) 131 messageBox.setText(text)
129 messageBox.setStandardButtons(buttons) 132 messageBox.setStandardButtons(buttons)
130 messageBox.setDefaultButton(defaultButton) 133 messageBox.setDefaultButton(defaultButton)
131 messageBox.exec_() 134 messageBox.exec_()
132 clickedButton = messageBox.clickedButton() 135 clickedButton = messageBox.clickedButton()
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

eric ide

mercurial