src/eric7/Plugins/WizardPlugins/MessageBoxWizard/MessageBoxWizardDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9433
6df1aeaa4529
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
16 16
17 17
18 class MessageBoxWizardDialog(QDialog, Ui_MessageBoxWizardDialog): 18 class MessageBoxWizardDialog(QDialog, Ui_MessageBoxWizardDialog):
19 """ 19 """
20 Class implementing the message box wizard dialog. 20 Class implementing the message box wizard dialog.
21 21
22 It displays a dialog for entering the parameters 22 It displays a dialog for entering the parameters
23 for the QMessageBox code generator. 23 for the QMessageBox code generator.
24 """ 24 """
25
25 def __init__(self, parent=None): 26 def __init__(self, parent=None):
26 """ 27 """
27 Constructor 28 Constructor
28 29
29 @param parent parent widget (QWidget) 30 @param parent parent widget (QWidget)
30 """ 31 """
31 super().__init__(parent) 32 super().__init__(parent)
32 self.setupUi(self) 33 self.setupUi(self)
33 34
34 # keep the following three lists in sync 35 # keep the following three lists in sync
35 self.buttonsList = [ 36 self.buttonsList = [
36 self.tr("No button"), 37 self.tr("No button"),
37 self.tr("Abort"), 38 self.tr("Abort"),
38 self.tr("Apply"), 39 self.tr("Apply"),
93 "QMessageBox.StandardButton.Save", 94 "QMessageBox.StandardButton.Save",
94 "QMessageBox.StandardButton.SaveAll", 95 "QMessageBox.StandardButton.SaveAll",
95 "QMessageBox.StandardButton.Yes", 96 "QMessageBox.StandardButton.Yes",
96 "QMessageBox.StandardButton.YesToAll", 97 "QMessageBox.StandardButton.YesToAll",
97 ] 98 ]
98 99
99 self.defaultCombo.addItems(self.buttonsList) 100 self.defaultCombo.addItems(self.buttonsList)
100 101
101 self.bTest = self.buttonBox.addButton( 102 self.bTest = self.buttonBox.addButton(
102 self.tr("Test"), QDialogButtonBox.ButtonRole.ActionRole) 103 self.tr("Test"), QDialogButtonBox.ButtonRole.ActionRole
103 104 )
105
104 def __testSelectedOptions(self): 106 def __testSelectedOptions(self):
105 """ 107 """
106 Private method to test the selected options. 108 Private method to test the selected options.
107 """ 109 """
108 buttons = QMessageBox.StandardButton.NoButton 110 buttons = QMessageBox.StandardButton.NoButton
142 buttons |= QMessageBox.StandardButton.Yes 144 buttons |= QMessageBox.StandardButton.Yes
143 if self.yestoallCheck.isChecked(): 145 if self.yestoallCheck.isChecked():
144 buttons |= QMessageBox.StandardButton.YesToAll 146 buttons |= QMessageBox.StandardButton.YesToAll
145 if buttons == QMessageBox.StandardButton.NoButton: 147 if buttons == QMessageBox.StandardButton.NoButton:
146 buttons = QMessageBox.StandardButton.Ok 148 buttons = QMessageBox.StandardButton.Ok
147 149
148 defaultButton = self.buttonsCodeListBinary[ 150 defaultButton = self.buttonsCodeListBinary[self.defaultCombo.currentIndex()]
149 self.defaultCombo.currentIndex()] 151
150
151 if self.rInformation.isChecked(): 152 if self.rInformation.isChecked():
152 QMessageBox.information( 153 QMessageBox.information(
153 self, 154 self,
154 self.eCaption.text(), 155 self.eCaption.text(),
155 self.eMessage.toPlainText(), 156 self.eMessage.toPlainText(),
156 buttons, 157 buttons,
157 defaultButton 158 defaultButton,
158 ) 159 )
159 elif self.rQuestion.isChecked(): 160 elif self.rQuestion.isChecked():
160 QMessageBox.question( 161 QMessageBox.question(
161 self, 162 self,
162 self.eCaption.text(), 163 self.eCaption.text(),
163 self.eMessage.toPlainText(), 164 self.eMessage.toPlainText(),
164 buttons, 165 buttons,
165 defaultButton 166 defaultButton,
166 ) 167 )
167 elif self.rWarning.isChecked(): 168 elif self.rWarning.isChecked():
168 QMessageBox.warning( 169 QMessageBox.warning(
169 self, 170 self,
170 self.eCaption.text(), 171 self.eCaption.text(),
171 self.eMessage.toPlainText(), 172 self.eMessage.toPlainText(),
172 buttons, 173 buttons,
173 defaultButton 174 defaultButton,
174 ) 175 )
175 elif self.rCritical.isChecked(): 176 elif self.rCritical.isChecked():
176 QMessageBox.critical( 177 QMessageBox.critical(
177 self, 178 self,
178 self.eCaption.text(), 179 self.eCaption.text(),
179 self.eMessage.toPlainText(), 180 self.eMessage.toPlainText(),
180 buttons, 181 buttons,
181 defaultButton 182 defaultButton,
182 ) 183 )
183 184
184 def on_buttonBox_clicked(self, button): 185 def on_buttonBox_clicked(self, button):
185 """ 186 """
186 Private slot called by a button of the button box clicked. 187 Private slot called by a button of the button box clicked.
187 188
188 @param button button that was clicked (QAbstractButton) 189 @param button button that was clicked (QAbstractButton)
189 """ 190 """
190 if button == self.bTest: 191 if button == self.bTest:
191 self.on_bTest_clicked() 192 self.on_bTest_clicked()
192 193
193 @pyqtSlot() 194 @pyqtSlot()
194 def on_bTest_clicked(self): 195 def on_bTest_clicked(self):
195 """ 196 """
196 Private method to test the selected options. 197 Private method to test the selected options.
197 """ 198 """
198 if self.rAbout.isChecked(): 199 if self.rAbout.isChecked():
199 QMessageBox.about( 200 QMessageBox.about(None, self.eCaption.text(), self.eMessage.toPlainText())
200 None,
201 self.eCaption.text(),
202 self.eMessage.toPlainText()
203 )
204 elif self.rAboutQt.isChecked(): 201 elif self.rAboutQt.isChecked():
205 QMessageBox.aboutQt( 202 QMessageBox.aboutQt(None, self.eCaption.text())
206 None,
207 self.eCaption.text()
208 )
209 else: 203 else:
210 self.__testSelectedOptions() 204 self.__testSelectedOptions()
211 205
212 def __enabledGroups(self): 206 def __enabledGroups(self):
213 """ 207 """
214 Private method to enable/disable some group boxes. 208 Private method to enable/disable some group boxes.
215 """ 209 """
216 enable = not self.rAbout.isChecked() and not self.rAboutQt.isChecked() 210 enable = not self.rAbout.isChecked() and not self.rAboutQt.isChecked()
217 self.standardButtons.setEnabled(enable) 211 self.standardButtons.setEnabled(enable)
218 self.lResultVar.setEnabled(enable) 212 self.lResultVar.setEnabled(enable)
219 self.eResultVar.setEnabled(enable) 213 self.eResultVar.setEnabled(enable)
220 214
221 self.eMessage.setEnabled(not self.rAboutQt.isChecked()) 215 self.eMessage.setEnabled(not self.rAboutQt.isChecked())
222 216
223 def on_rAbout_toggled(self, on): 217 def on_rAbout_toggled(self, on):
224 """ 218 """
225 Private slot to handle the toggled signal of the rAbout radio button. 219 Private slot to handle the toggled signal of the rAbout radio button.
226 220
227 @param on toggle state (boolean) (ignored) 221 @param on toggle state (boolean) (ignored)
228 """ 222 """
229 self.__enabledGroups() 223 self.__enabledGroups()
230 224
231 def on_rAboutQt_toggled(self, on): 225 def on_rAboutQt_toggled(self, on):
232 """ 226 """
233 Private slot to handle the toggled signal of the rAboutQt radio button. 227 Private slot to handle the toggled signal of the rAboutQt radio button.
234 228
235 @param on toggle state (boolean) (ignored) 229 @param on toggle state (boolean) (ignored)
236 """ 230 """
237 self.__enabledGroups() 231 self.__enabledGroups()
238 232
239 def __getButtonCode(self, istring, indString): 233 def __getButtonCode(self, istring, indString):
240 """ 234 """
241 Private method to generate the button code. 235 Private method to generate the button code.
242 236
243 @param istring indentation string (string) 237 @param istring indentation string (string)
244 @param indString string used for indentation (space or tab) (string) 238 @param indString string used for indentation (space or tab) (string)
245 @return the button code (string) 239 @return the button code (string)
246 """ 240 """
247 buttons = [] 241 buttons = []
281 buttons.append("QMessageBox.StandardButton.Yes") 275 buttons.append("QMessageBox.StandardButton.Yes")
282 if self.yestoallCheck.isChecked(): 276 if self.yestoallCheck.isChecked():
283 buttons.append("QMessageBox.StandardButton.YesToAll") 277 buttons.append("QMessageBox.StandardButton.YesToAll")
284 if len(buttons) == 0: 278 if len(buttons) == 0:
285 return "" 279 return ""
286 280
287 istring2 = istring + indString 281 istring2 = istring + indString
288 joinstring = ' |{0}{1}'.format(os.linesep, istring2) 282 joinstring = " |{0}{1}".format(os.linesep, istring2)
289 btnCode = ',{0}{1}('.format( 283 btnCode = ",{0}{1}(".format(os.linesep, istring)
290 os.linesep, istring) 284 btnCode += "{0}{1}{2})".format(os.linesep, istring2, joinstring.join(buttons))
291 btnCode += '{0}{1}{2})'.format(
292 os.linesep, istring2, joinstring.join(buttons))
293 defaultIndex = self.defaultCombo.currentIndex() 285 defaultIndex = self.defaultCombo.currentIndex()
294 if defaultIndex: 286 if defaultIndex:
295 btnCode += ',{0}{1}{2}'.format( 287 btnCode += ",{0}{1}{2}".format(
296 os.linesep, istring, 288 os.linesep, istring, self.buttonsCodeListText[defaultIndex]
297 self.buttonsCodeListText[defaultIndex]) 289 )
298 return btnCode 290 return btnCode
299 291
300 def getCode(self, indLevel, indString): 292 def getCode(self, indLevel, indString):
301 """ 293 """
302 Public method to get the source code. 294 Public method to get the source code.
303 295
304 @param indLevel indentation level (int) 296 @param indLevel indentation level (int)
305 @param indString string used for indentation (space or tab) (string) 297 @param indString string used for indentation (space or tab) (string)
306 @return generated code (string) 298 @return generated code (string)
307 """ 299 """
308 # calculate our indentation level and the indentation string 300 # calculate our indentation level and the indentation string
309 il = indLevel + 1 301 il = indLevel + 1
310 istring = il * indString 302 istring = il * indString
311 estring = os.linesep + indLevel * indString 303 estring = os.linesep + indLevel * indString
312 304
313 # now generate the code 305 # now generate the code
314 if self.parentSelf.isChecked(): 306 if self.parentSelf.isChecked():
315 parent = "self" 307 parent = "self"
316 elif self.parentNone.isChecked(): 308 elif self.parentNone.isChecked():
317 parent = "None" 309 parent = "None"
318 elif self.parentOther.isChecked(): 310 elif self.parentOther.isChecked():
319 parent = self.parentEdit.text() 311 parent = self.parentEdit.text()
320 if parent == "": 312 if parent == "":
321 parent = "None" 313 parent = "None"
322 314
323 resvar = self.eResultVar.text() 315 resvar = self.eResultVar.text()
324 if not resvar: 316 if not resvar:
325 resvar = "res" 317 resvar = "res"
326 318
327 if self.rAbout.isChecked(): 319 if self.rAbout.isChecked():
328 msgdlg = "QMessageBox.about(" 320 msgdlg = "QMessageBox.about("
329 elif self.rAboutQt.isChecked(): 321 elif self.rAboutQt.isChecked():
330 msgdlg = "QMessageBox.aboutQt(" 322 msgdlg = "QMessageBox.aboutQt("
331 elif self.rInformation.isChecked(): 323 elif self.rInformation.isChecked():
334 msgdlg = "{0} = QMessageBox.question(".format(resvar) 326 msgdlg = "{0} = QMessageBox.question(".format(resvar)
335 elif self.rWarning.isChecked(): 327 elif self.rWarning.isChecked():
336 msgdlg = "{0} = QMessageBox.warning(".format(resvar) 328 msgdlg = "{0} = QMessageBox.warning(".format(resvar)
337 else: 329 else:
338 msgdlg = "{0} = QMessageBox.critical(".format(resvar) 330 msgdlg = "{0} = QMessageBox.critical(".format(resvar)
339 331
340 if self.rAboutQt.isChecked(): 332 if self.rAboutQt.isChecked():
341 if self.eCaption.text(): 333 if self.eCaption.text():
342 msgdlg += '{0}{1}{2}'.format(os.linesep, istring, parent) 334 msgdlg += "{0}{1}{2}".format(os.linesep, istring, parent)
343 msgdlg += ',{0}{1}self.tr("{2}")'.format( 335 msgdlg += ',{0}{1}self.tr("{2}")'.format(
344 os.linesep, istring, self.eCaption.text()) 336 os.linesep, istring, self.eCaption.text()
337 )
345 else: 338 else:
346 msgdlg += parent 339 msgdlg += parent
347 else: 340 else:
348 msgdlg += '{0}{1}{2}'.format(os.linesep, istring, parent) 341 msgdlg += "{0}{1}{2}".format(os.linesep, istring, parent)
349 msgdlg += ',{0}{1}self.tr("{2}")'.format( 342 msgdlg += ',{0}{1}self.tr("{2}")'.format(
350 os.linesep, istring, self.eCaption.text()) 343 os.linesep, istring, self.eCaption.text()
344 )
351 msgdlg += ',{0}{1}self.tr("""{2}""")'.format( 345 msgdlg += ',{0}{1}self.tr("""{2}""")'.format(
352 os.linesep, istring, self.eMessage.toPlainText()) 346 os.linesep, istring, self.eMessage.toPlainText()
347 )
353 if not self.rAbout.isChecked() and not self.rAboutQt.isChecked(): 348 if not self.rAbout.isChecked() and not self.rAboutQt.isChecked():
354 msgdlg += self.__getButtonCode(istring, indString) 349 msgdlg += self.__getButtonCode(istring, indString)
355 msgdlg += '{0}){0}'.format(estring) 350 msgdlg += "{0}){0}".format(estring)
356 return msgdlg 351 return msgdlg

eric ide

mercurial