Extend showInfo with ability to copy text to clipboard

Use this in error dialog
This commit is contained in:
Glutanimate 2019-02-16 23:05:06 +01:00
parent 3037bf6ef8
commit 5deb905b27
2 changed files with 8 additions and 2 deletions

View File

@ -130,7 +130,7 @@ add-ons section</a> of our support site.
error = self._supportText() + "\n" + error
txt = txt + "<div style='white-space: pre-wrap'>" + error + "</div>"
showText(txt, type="html")
showText(txt, type="html", copyBtn=True)
def _supportText(self):
import platform

View File

@ -50,7 +50,7 @@ def showInfo(text, parent=False, help="", type="info", title="Anki"):
return mb.exec_()
def showText(txt, parent=None, type="text", run=True, geomKey=None, \
minWidth=500, minHeight=400, title="Anki"):
minWidth=500, minHeight=400, title="Anki", copyBtn=False):
if not parent:
parent = aqt.mw.app.activeWindow() or aqt.mw
diag = QDialog(parent)
@ -66,6 +66,12 @@ def showText(txt, parent=None, type="text", run=True, geomKey=None, \
layout.addWidget(text)
box = QDialogButtonBox(QDialogButtonBox.Close)
layout.addWidget(box)
if copyBtn:
def onCopy():
QApplication.clipboard().setText(text.toPlainText())
btn = QPushButton(_("Copy to Clipboard"))
btn.clicked.connect(onCopy)
box.addButton(btn, QDialogButtonBox.ActionRole)
def onReject():
if geomKey:
saveGeom(diag, geomKey)