mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Extend showInfo with the ability to add custom buttons
Grants more flexibility in user prompt design
This commit is contained in:
parent
ce1853167b
commit
00991e8e8e
1 changed files with 19 additions and 3 deletions
|
@ -50,7 +50,15 @@ def showCritical(text, parent=None, help="", title="Anki", textFormat=None):
|
||||||
return showInfo(text, parent, help, "critical", title=title, textFormat=textFormat)
|
return showInfo(text, parent, help, "critical", title=title, textFormat=textFormat)
|
||||||
|
|
||||||
|
|
||||||
def showInfo(text, parent=False, help="", type="info", title="Anki", textFormat=None):
|
def showInfo(
|
||||||
|
text,
|
||||||
|
parent=False,
|
||||||
|
help="",
|
||||||
|
type="info",
|
||||||
|
title="Anki",
|
||||||
|
textFormat=None,
|
||||||
|
customBtns=None
|
||||||
|
):
|
||||||
"Show a small info window with an OK button."
|
"Show a small info window with an OK button."
|
||||||
if parent is False:
|
if parent is False:
|
||||||
parent = aqt.mw.app.activeWindow() or aqt.mw
|
parent = aqt.mw.app.activeWindow() or aqt.mw
|
||||||
|
@ -70,8 +78,16 @@ def showInfo(text, parent=False, help="", type="info", title="Anki", textFormat=
|
||||||
mb.setText(text)
|
mb.setText(text)
|
||||||
mb.setIcon(icon)
|
mb.setIcon(icon)
|
||||||
mb.setWindowTitle(title)
|
mb.setWindowTitle(title)
|
||||||
b = mb.addButton(QMessageBox.Ok)
|
if customBtns:
|
||||||
b.setDefault(True)
|
default = None
|
||||||
|
for btn in customBtns:
|
||||||
|
b = mb.addButton(btn)
|
||||||
|
if not default:
|
||||||
|
default = b
|
||||||
|
mb.setDefaultButton(default)
|
||||||
|
else:
|
||||||
|
b = mb.addButton(QMessageBox.Ok)
|
||||||
|
b.setDefault(True)
|
||||||
if help:
|
if help:
|
||||||
b = mb.addButton(QMessageBox.Help)
|
b = mb.addButton(QMessageBox.Help)
|
||||||
b.clicked.connect(lambda: openHelp(help))
|
b.clicked.connect(lambda: openHelp(help))
|
||||||
|
|
Loading…
Reference in a new issue