E5Gui/E5MessageBox.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 1131
7781e396c903
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
13 ################################################################################ 13 ################################################################################
14 ## Mappings to standard QMessageBox ## 14 ## Mappings to standard QMessageBox ##
15 ################################################################################ 15 ################################################################################
16 16
17 # QMessageBox.Icon 17 # QMessageBox.Icon
18 Critical = QMessageBox.Critical 18 Critical = QMessageBox.Critical
19 Information = QMessageBox.Information 19 Information = QMessageBox.Information
20 Question = QMessageBox.Question 20 Question = QMessageBox.Question
21 Warning = QMessageBox.Warning 21 Warning = QMessageBox.Warning
22 22
23 StandardButtons = QMessageBox.StandardButtons 23 StandardButtons = QMessageBox.StandardButtons
24 24
25 # QMessageBox.StandardButton 25 # QMessageBox.StandardButton
26 Abort = QMessageBox.Abort 26 Abort = QMessageBox.Abort
27 Apply = QMessageBox.Apply 27 Apply = QMessageBox.Apply
28 Cancel = QMessageBox.Cancel 28 Cancel = QMessageBox.Cancel
29 Close = QMessageBox.Close 29 Close = QMessageBox.Close
30 Discard = QMessageBox.Discard 30 Discard = QMessageBox.Discard
31 Help = QMessageBox.Help 31 Help = QMessageBox.Help
32 Ignore = QMessageBox.Ignore 32 Ignore = QMessageBox.Ignore
33 No = QMessageBox.No 33 No = QMessageBox.No
34 NoToAll = QMessageBox.NoToAll 34 NoToAll = QMessageBox.NoToAll
35 Ok = QMessageBox.Ok 35 Ok = QMessageBox.Ok
36 Open = QMessageBox.Open 36 Open = QMessageBox.Open
37 Reset = QMessageBox.Reset 37 Reset = QMessageBox.Reset
38 RestoreDefaults = QMessageBox.RestoreDefaults 38 RestoreDefaults = QMessageBox.RestoreDefaults
39 Retry = QMessageBox.Retry 39 Retry = QMessageBox.Retry
40 Save = QMessageBox.Save 40 Save = QMessageBox.Save
41 SaveAll = QMessageBox.SaveAll 41 SaveAll = QMessageBox.SaveAll
42 Yes = QMessageBox.Yes 42 Yes = QMessageBox.Yes
43 YesToAll = QMessageBox.YesToAll 43 YesToAll = QMessageBox.YesToAll
44 NoButton = QMessageBox.NoButton 44 NoButton = QMessageBox.NoButton
45 45
46 # QMessageBox.ButtonRole 46 # QMessageBox.ButtonRole
47 AcceptRole = QMessageBox.AcceptRole 47 AcceptRole = QMessageBox.AcceptRole
48 ActionRole = QMessageBox.ActionRole 48 ActionRole = QMessageBox.ActionRole
49 ApplyRole = QMessageBox.ApplyRole 49 ApplyRole = QMessageBox.ApplyRole
50 DestructiveRole = QMessageBox.DestructiveRole 50 DestructiveRole = QMessageBox.DestructiveRole
51 InvalidRole = QMessageBox.InvalidRole 51 InvalidRole = QMessageBox.InvalidRole
52 HelpRole = QMessageBox.HelpRole 52 HelpRole = QMessageBox.HelpRole
53 NoRole = QMessageBox.NoRole 53 NoRole = QMessageBox.NoRole
54 RejectRole = QMessageBox.RejectRole 54 RejectRole = QMessageBox.RejectRole
55 ResetRole = QMessageBox.ResetRole 55 ResetRole = QMessageBox.ResetRole
56 YesRole = QMessageBox.YesRole 56 YesRole = QMessageBox.YesRole
57 57
58 ################################################################################ 58 ################################################################################
59 ## Replacement for the QMessageBox class ## 59 ## Replacement for the QMessageBox class ##
60 ################################################################################ 60 ################################################################################
61 61
62
62 class E5MessageBox(QMessageBox): 63 class E5MessageBox(QMessageBox):
63 """ 64 """
64 Class implementing a replacement for QMessageBox. 65 Class implementing a replacement for QMessageBox.
65 """ 66 """
66 def __init__(self, icon, title, text, modal = False, 67 def __init__(self, icon, title, text, modal=False,
67 buttons = QMessageBox.StandardButtons(QMessageBox.NoButton), 68 buttons=QMessageBox.StandardButtons(QMessageBox.NoButton),
68 parent = None): 69 parent=None):
69 """ 70 """
70 Constructor 71 Constructor
71 72
72 @param icon type of icon to be shown (QMessageBox.Icon) 73 @param icon type of icon to be shown (QMessageBox.Icon)
73 @param title caption of the message box (string) 74 @param title caption of the message box (string)
96 97
97 ################################################################################ 98 ################################################################################
98 ## Replacements for QMessageBox static methods ## 99 ## Replacements for QMessageBox static methods ##
99 ################################################################################ 100 ################################################################################
100 101
101 def __messageBox(parent, title, text, icon, 102
102 buttons = QMessageBox.Ok, defaultButton = QMessageBox.NoButton): 103 def __messageBox(parent, title, text, icon,
104 buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton):
103 """ 105 """
104 Private module function to show a modal message box. 106 Private module function to show a modal message box.
105 107
106 @param parent parent widget of the message box (QWidget) 108 @param parent parent widget of the message box (QWidget)
107 @param title caption of the message box (string) 109 @param title caption of the message box (string)
108 @param text text to be shown by the message box (string) 110 @param text text to be shown by the message box (string)
109 @param icon type of icon to be shown (QMessageBox.Icon) 111 @param icon type of icon to be shown (QMessageBox.Icon)
110 @param buttons flags indicating which buttons to show 112 @param buttons flags indicating which buttons to show
111 (QMessageBox.StandardButtons) 113 (QMessageBox.StandardButtons)
112 @param defaultButton flag indicating the default button 114 @param defaultButton flag indicating the default button
113 (QMessageBox.StandardButton) 115 (QMessageBox.StandardButton)
114 @return button pressed by the user (QMessageBox.StandardButton) 116 @return button pressed by the user (QMessageBox.StandardButton)
115 """ 117 """
135 137
136 # the about functions are here for consistancy 138 # the about functions are here for consistancy
137 about = QMessageBox.about 139 about = QMessageBox.about
138 aboutQt = QMessageBox.aboutQt 140 aboutQt = QMessageBox.aboutQt
139 141
140 def critical(parent, title, text, 142
141 buttons = QMessageBox.Ok, defaultButton = QMessageBox.NoButton): 143 def critical(parent, title, text,
144 buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton):
142 """ 145 """
143 Function to show a modal critical message box. 146 Function to show a modal critical message box.
144 147
145 @param parent parent widget of the message box (QWidget) 148 @param parent parent widget of the message box (QWidget)
146 @param title caption of the message box (string) 149 @param title caption of the message box (string)
147 @param text text to be shown by the message box (string) 150 @param text text to be shown by the message box (string)
148 @param buttons flags indicating which buttons to show 151 @param buttons flags indicating which buttons to show
149 (QMessageBox.StandardButtons) 152 (QMessageBox.StandardButtons)
150 @param defaultButton flag indicating the default button 153 @param defaultButton flag indicating the default button
151 (QMessageBox.StandardButton) 154 (QMessageBox.StandardButton)
152 @return button pressed by the user (QMessageBox.StandardButton) 155 @return button pressed by the user (QMessageBox.StandardButton)
153 """ 156 """
154 return __messageBox(parent, title, text, QMessageBox.Critical, 157 return __messageBox(parent, title, text, QMessageBox.Critical,
155 buttons, defaultButton) 158 buttons, defaultButton)
156 159
157 def information(parent, title, text, 160
158 buttons = QMessageBox.Ok, defaultButton = QMessageBox.NoButton): 161 def information(parent, title, text,
162 buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton):
159 """ 163 """
160 Function to show a modal information message box. 164 Function to show a modal information message box.
161 165
162 @param parent parent widget of the message box (QWidget) 166 @param parent parent widget of the message box (QWidget)
163 @param title caption of the message box (string) 167 @param title caption of the message box (string)
164 @param text text to be shown by the message box (string) 168 @param text text to be shown by the message box (string)
165 @param buttons flags indicating which buttons to show 169 @param buttons flags indicating which buttons to show
166 (QMessageBox.StandardButtons) 170 (QMessageBox.StandardButtons)
167 @param defaultButton flag indicating the default button 171 @param defaultButton flag indicating the default button
168 (QMessageBox.StandardButton) 172 (QMessageBox.StandardButton)
169 @return button pressed by the user (QMessageBox.StandardButton) 173 @return button pressed by the user (QMessageBox.StandardButton)
170 """ 174 """
171 return __messageBox(parent, title, text, QMessageBox.Information, 175 return __messageBox(parent, title, text, QMessageBox.Information,
172 buttons, defaultButton) 176 buttons, defaultButton)
173 177
174 def question(parent, title, text, 178
175 buttons = QMessageBox.Ok, defaultButton = QMessageBox.NoButton): 179 def question(parent, title, text,
180 buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton):
176 """ 181 """
177 Function to show a modal question message box. 182 Function to show a modal question message box.
178 183
179 @param parent parent widget of the message box (QWidget) 184 @param parent parent widget of the message box (QWidget)
180 @param title caption of the message box (string) 185 @param title caption of the message box (string)
181 @param text text to be shown by the message box (string) 186 @param text text to be shown by the message box (string)
182 @param buttons flags indicating which buttons to show 187 @param buttons flags indicating which buttons to show
183 (QMessageBox.StandardButtons) 188 (QMessageBox.StandardButtons)
184 @param defaultButton flag indicating the default button 189 @param defaultButton flag indicating the default button
185 (QMessageBox.StandardButton) 190 (QMessageBox.StandardButton)
186 @return button pressed by the user (QMessageBox.StandardButton) 191 @return button pressed by the user (QMessageBox.StandardButton)
187 """ 192 """
188 return __messageBox(parent, title, text, QMessageBox.Question, 193 return __messageBox(parent, title, text, QMessageBox.Question,
189 buttons, defaultButton) 194 buttons, defaultButton)
190 195
191 def warning(parent, title, text, 196
192 buttons = QMessageBox.Ok, defaultButton = QMessageBox.NoButton): 197 def warning(parent, title, text,
198 buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton):
193 """ 199 """
194 Function to show a modal warning message box. 200 Function to show a modal warning message box.
195 201
196 @param parent parent widget of the message box (QWidget) 202 @param parent parent widget of the message box (QWidget)
197 @param title caption of the message box (string) 203 @param title caption of the message box (string)
198 @param text text to be shown by the message box (string) 204 @param text text to be shown by the message box (string)
199 @param buttons flags indicating which buttons to show 205 @param buttons flags indicating which buttons to show
200 (QMessageBox.StandardButtons) 206 (QMessageBox.StandardButtons)
201 @param defaultButton flag indicating the default button 207 @param defaultButton flag indicating the default button
202 (QMessageBox.StandardButton) 208 (QMessageBox.StandardButton)
203 @return button pressed by the user (QMessageBox.StandardButton) 209 @return button pressed by the user (QMessageBox.StandardButton)
204 """ 210 """
205 return __messageBox(parent, title, text, QMessageBox.Warning, 211 return __messageBox(parent, title, text, QMessageBox.Warning,
206 buttons, defaultButton) 212 buttons, defaultButton)
207 213
208 ################################################################################ 214 ################################################################################
209 ## Additional convenience functions ## 215 ## Additional convenience functions ##
210 ################################################################################ 216 ################################################################################
211 217
212 def yesNo(parent, title, text, icon = Question, yesDefault = False): 218
219 def yesNo(parent, title, text, icon=Question, yesDefault=False):
213 """ 220 """
214 Function to show a model yes/no message box. 221 Function to show a model yes/no message box.
215 222
216 @param parent parent widget of the message box (QWidget) 223 @param parent parent widget of the message box (QWidget)
217 @param title caption of the message box (string) 224 @param title caption of the message box (string)
221 button (boolean) 228 button (boolean)
222 @return flag indicating the selection of the Yes button (boolean) 229 @return flag indicating the selection of the Yes button (boolean)
223 """ 230 """
224 assert icon in [Critical, Information, Question, Warning] 231 assert icon in [Critical, Information, Question, Warning]
225 232
226 res = __messageBox(parent, title, text, icon, 233 res = __messageBox(parent, title, text, icon,
227 QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No), 234 QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No),
228 yesDefault and QMessageBox.Yes or QMessageBox.No) 235 yesDefault and QMessageBox.Yes or QMessageBox.No)
229 return res == QMessageBox.Yes 236 return res == QMessageBox.Yes
230 237
231 def retryAbort(parent, title, text, icon = Question): 238
239 def retryAbort(parent, title, text, icon=Question):
232 """ 240 """
233 Function to show a model abort/retry message box. 241 Function to show a model abort/retry message box.
234 242
235 @param parent parent widget of the message box (QWidget) 243 @param parent parent widget of the message box (QWidget)
236 @param title caption of the message box (string) 244 @param title caption of the message box (string)
238 @keyparam icon icon for the dialog (Critical, Information, Question or Warning) 246 @keyparam icon icon for the dialog (Critical, Information, Question or Warning)
239 @return flag indicating the selection of the Retry button (boolean) 247 @return flag indicating the selection of the Retry button (boolean)
240 """ 248 """
241 assert icon in [Critical, Information, Question, Warning] 249 assert icon in [Critical, Information, Question, Warning]
242 250
243 res = __messageBox(parent, title, text, icon, 251 res = __messageBox(parent, title, text, icon,
244 QMessageBox.StandardButtons(QMessageBox.Retry | QMessageBox.Abort), 252 QMessageBox.StandardButtons(QMessageBox.Retry | QMessageBox.Abort),
245 QMessageBox.Retry) 253 QMessageBox.Retry)
246 return res == QMessageBox.Retry 254 return res == QMessageBox.Retry
255
247 256
248 def okToClearData(parent, title, text, saveFunc): 257 def okToClearData(parent, title, text, saveFunc):
249 """ 258 """
250 Function to show a model message box to ask for clearing the data. 259 Function to show a model message box to ask for clearing the data.
251 260
254 @param text text to be shown by the message box (string) 263 @param text text to be shown by the message box (string)
255 @param saveFunc reference to a function performing the save action. It 264 @param saveFunc reference to a function performing the save action. It
256 must be a parameterless function returning a flag indicating success. 265 must be a parameterless function returning a flag indicating success.
257 @return flag indicating that it is ok to clear the data (boolean) 266 @return flag indicating that it is ok to clear the data (boolean)
258 """ 267 """
259 res = __messageBox(parent, title, text, QMessageBox.Warning, 268 res = __messageBox(parent, title, text, QMessageBox.Warning,
260 QMessageBox.StandardButtons( 269 QMessageBox.StandardButtons(
261 QMessageBox.Abort | QMessageBox.Discard | QMessageBox.Save), 270 QMessageBox.Abort | QMessageBox.Discard | QMessageBox.Save),
262 QMessageBox.Save) 271 QMessageBox.Save)
263 if res == QMessageBox.Abort: 272 if res == QMessageBox.Abort:
264 return False 273 return False
265 if res == QMessageBox.Save: 274 if res == QMessageBox.Save:
266 return saveFunc() 275 return saveFunc()

eric ide

mercurial