本文整理汇总了Python中PyQt5.Qt.QMessageBox.addButton方法的典型用法代码示例。如果您正苦于以下问题:Python QMessageBox.addButton方法的具体用法?Python QMessageBox.addButton怎么用?Python QMessageBox.addButton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QMessageBox
的用法示例。
在下文中一共展示了QMessageBox.addButton方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QuestionDialog
# 需要导入模块: from PyQt5.Qt import QMessageBox [as 别名]
# 或者: from PyQt5.Qt.QMessageBox import addButton [as 别名]
def QuestionDialog(title, text, info = None, dontAsk = False):
msgBox = QMessageBox()
buttonYes = msgBox.addButton(_("Yes"), QMessageBox.ActionRole)
buttonNo = msgBox.addButton(_("No"), QMessageBox.ActionRole)
answers = {buttonYes:"yes",
buttonNo :"no"}
if dontAsk:
buttonDontAsk = msgBox.addButton(_("Don't ask again"), QMessageBox.ActionRole)
answers[buttonDontAsk] = "dontask"
msgBox.setText(text)
if not info:
info = _("Do you want to continue?")
msgBox.setInformativeText(info)
dialog = Dialog(_(title), msgBox, closeButton = False, isDialog = True, icon="question")
dialog.resize(300,120)
dialog.exec_()
ctx.mainScreen.processEvents()
if msgBox.clickedButton() in answers.keys():
return answers[msgBox.clickedButton()]
return "no"
示例2: msgbox
# 需要导入模块: from PyQt5.Qt import QMessageBox [as 别名]
# 或者: from PyQt5.Qt.QMessageBox import addButton [as 别名]
def msgbox(cls, typename, text, button0, button1=None, button2=None, title=None, form=None):
if form:
logger.warn("MessageBox: Se intentó usar form, y no está implementado.")
icon = QMessageBox.NoIcon
if not title:
title = "Pineboo"
if typename == "question":
icon = QMessageBox.Question
if not title:
title = "Question"
elif typename == "information":
icon = QMessageBox.Information
if not title:
title = "Information"
elif typename == "warning":
icon = QMessageBox.Warning
if not title:
title = "Warning"
elif typename == "critical":
icon = QMessageBox.Critical
if not title:
title = "Critical"
# title = unicode(title,"UTF-8")
# text = unicode(text,"UTF-8")
msg = QMessageBox(icon, title, text)
msg.addButton(button0)
if button1:
msg.addButton(button1)
if button2:
msg.addButton(button2)
return msg.exec_()
示例3: InfoDialog
# 需要导入模块: from PyQt5.Qt import QMessageBox [as 别名]
# 或者: from PyQt5.Qt.QMessageBox import addButton [as 别名]
def InfoDialog(text, button=None, title=None, icon="info"):
if not title:
title = _("Information")
if not button:
button = _("OK")
msgBox = QMessageBox()
buttonOk = msgBox.addButton(button, QMessageBox.ActionRole)
msgBox.setText(text)
dialog = Dialog(_(title), msgBox, closeButton = False, isDialog = True, icon = icon)
dialog.resize(300,120)
dialog.exec_()
ctx.mainScreen.processEvents()
示例4: __init__
# 需要导入模块: from PyQt5.Qt import QMessageBox [as 别名]
# 或者: from PyQt5.Qt.QMessageBox import addButton [as 别名]
class MessageWindow:
def __init__(self, title, text, type="ok", default=None, customButtons =None, customIcon=None, run=True, destroyAfterRun=True, detailed=False, longText=""):
self.rc = None
self.dialog = None
self.msgBox = QMessageBox()
self.doCustom = False
self.customButtons = customButtons
icon = None
buttons = None
if type == 'ok':
buttons = QMessageBox.Ok
icon = "question"
elif type == 'error':
icon = "error"
buttons = QMessageBox.Ok
elif type == 'warning':
icon = "warning"
buttons = QMessageBox.Ok
elif type == 'okcancel':
icon = "question"
buttons = QMessageBox.Ok | QMessageBox.Cancel
elif type == 'question':
icon = "question"
buttons = QMessageBox.Ok | QMessageBox.Cancel
elif type == 'yesno':
icon = "question"
buttons = QMessageBox.Yes | QMessageBox.No
elif type == 'custom':
self.doCustom = True
if customIcon:
icon = customIcon
else:
icon = "question"
text = "<qt>%s</qt>" % text.replace("\n", " ")
self.msgBox.setText(text)
if detailed:
self.msgBox.setDetailedText(unicode(longText))
if self.doCustom:
button = None
for index, text in enumerate(self.customButtons):
button = self.msgBox.addButton(text, QMessageBox.ActionRole)
if default is not None and default == index:
self.msgBox.setDefaultButton(button)
else:
self.msgBox.setStandardButtons(buttons)
if default == "no":
default = QMessageBox.No
elif default == "yes":
default = QMessageBox.Yes
elif default == "ok":
default = QMessageBox.Ok
else:
default = None
self.msgBox.setDefaultButton(default)
self.dialog = Dialog(_(title), self.msgBox, closeButton=False, isDialog=True, icon=icon)
self.dialog.resize(QSize(0,0))
if run:
self.run(destroyAfterRun)
def run(self, destroyAfterRun=True):
self.rc = self.dialog.exec_()
if self.msgBox.clickedButton():
if not self.doCustom:
if self.msgBox.clickedButton().text() in [_("Ok"), _("Yes")]:
self.rc = 1
elif self.msgBox.clickedButton().text() in [_("Cancel"), _("No")]:
self.rc = 0
else:
if self.msgBox.clickedButton().text() in self.customButtons:
self.rc = self.customButtons.index(self.msgBox.clickedButton().text())
if destroyAfterRun:
self.dialog = None
return self.rc