mirror of
git://github.com/kovidgoyal/calibre.git
synced 2025-12-20 14:14:46 +01:00
Add support for rich text in details message in info boxes
This commit is contained in:
parent
e8b97d4b70
commit
f9cfc4d6a0
1 changed files with 15 additions and 10 deletions
|
|
@ -7,12 +7,11 @@
|
|||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import sys
|
||||
|
||||
from qt.core import (
|
||||
QPainter, QDialog, QIcon, QApplication, QSize, QKeySequence,
|
||||
QAction, Qt, QTextBrowser, QDialogButtonBox, QVBoxLayout, QGridLayout,
|
||||
QLabel, QPlainTextEdit, QTextDocument, QCheckBox, pyqtSignal, QWidget,
|
||||
QSizePolicy)
|
||||
QAction, QApplication, QCheckBox, QDialog, QDialogButtonBox, QGridLayout, QIcon,
|
||||
QKeySequence, QLabel, QPainter, QPlainTextEdit, QSize, QSizePolicy, Qt,
|
||||
QTextBrowser, QTextDocument, QVBoxLayout, QWidget, pyqtSignal
|
||||
)
|
||||
|
||||
from calibre.constants import __version__, isfrozen
|
||||
from calibre.gui2 import gprefs
|
||||
|
|
@ -63,7 +62,7 @@ def setup_ui(self):
|
|||
la.setOpenExternalLinks(True)
|
||||
la.setObjectName("msg")
|
||||
l.addWidget(la, 0, 1, 1, 1)
|
||||
self.det_msg = dm = QPlainTextEdit(self)
|
||||
self.det_msg = dm = QTextBrowser(self)
|
||||
dm.setReadOnly(True)
|
||||
dm.setObjectName("det_msg")
|
||||
l.addWidget(dm, 1, 0, 1, 2)
|
||||
|
|
@ -106,7 +105,10 @@ def __init__(self, type_, title, msg,
|
|||
self.setWindowIcon(self.icon)
|
||||
self.icon_widget.set_icon(self.icon)
|
||||
self.msg.setText(msg)
|
||||
self.det_msg.setPlainText(det_msg)
|
||||
if det_msg and Qt.mightBeRichText(det_msg):
|
||||
self.det_msg.setHtml(det_msg)
|
||||
else:
|
||||
self.det_msg.setPlainText(det_msg)
|
||||
self.det_msg.setVisible(False)
|
||||
self.toggle_checkbox.setVisible(False)
|
||||
|
||||
|
|
@ -194,7 +196,10 @@ def showEvent(self, ev):
|
|||
def set_details(self, msg):
|
||||
if not msg:
|
||||
msg = ''
|
||||
self.det_msg.setPlainText(msg)
|
||||
if Qt.mightBeRichText(msg):
|
||||
self.det_msg.setHtml(msg)
|
||||
else:
|
||||
self.det_msg.setPlainText(msg)
|
||||
self.det_msg_toggle.setText(self.show_det_msg)
|
||||
self.det_msg_toggle.setVisible(bool(msg))
|
||||
self.det_msg.setVisible(False)
|
||||
|
|
@ -488,8 +493,8 @@ def done(self, r):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from calibre.gui2 import question_dialog, Application
|
||||
from calibre.gui2 import Application, question_dialog
|
||||
app = Application([])
|
||||
print(question_dialog(None, 'title', 'msg <a href="http://google.com">goog</a> ',
|
||||
det_msg='det '*1000,
|
||||
det_msg='<p>hi there <b>guy</b> '*1000,
|
||||
show_copy_button=True))
|
||||
|
|
|
|||
Loading…
Reference in a new issue