mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Add support for rich text in details message in info boxes
This commit is contained in:
parent
e8b97d4b70
commit
f9cfc4d6a0
@ -7,12 +7,11 @@ __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QPainter, QDialog, QIcon, QApplication, QSize, QKeySequence,
|
QAction, QApplication, QCheckBox, QDialog, QDialogButtonBox, QGridLayout, QIcon,
|
||||||
QAction, Qt, QTextBrowser, QDialogButtonBox, QVBoxLayout, QGridLayout,
|
QKeySequence, QLabel, QPainter, QPlainTextEdit, QSize, QSizePolicy, Qt,
|
||||||
QLabel, QPlainTextEdit, QTextDocument, QCheckBox, pyqtSignal, QWidget,
|
QTextBrowser, QTextDocument, QVBoxLayout, QWidget, pyqtSignal
|
||||||
QSizePolicy)
|
)
|
||||||
|
|
||||||
from calibre.constants import __version__, isfrozen
|
from calibre.constants import __version__, isfrozen
|
||||||
from calibre.gui2 import gprefs
|
from calibre.gui2 import gprefs
|
||||||
@ -63,7 +62,7 @@ class MessageBox(QDialog): # {{{
|
|||||||
la.setOpenExternalLinks(True)
|
la.setOpenExternalLinks(True)
|
||||||
la.setObjectName("msg")
|
la.setObjectName("msg")
|
||||||
l.addWidget(la, 0, 1, 1, 1)
|
l.addWidget(la, 0, 1, 1, 1)
|
||||||
self.det_msg = dm = QPlainTextEdit(self)
|
self.det_msg = dm = QTextBrowser(self)
|
||||||
dm.setReadOnly(True)
|
dm.setReadOnly(True)
|
||||||
dm.setObjectName("det_msg")
|
dm.setObjectName("det_msg")
|
||||||
l.addWidget(dm, 1, 0, 1, 2)
|
l.addWidget(dm, 1, 0, 1, 2)
|
||||||
@ -106,7 +105,10 @@ class MessageBox(QDialog): # {{{
|
|||||||
self.setWindowIcon(self.icon)
|
self.setWindowIcon(self.icon)
|
||||||
self.icon_widget.set_icon(self.icon)
|
self.icon_widget.set_icon(self.icon)
|
||||||
self.msg.setText(msg)
|
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.det_msg.setVisible(False)
|
||||||
self.toggle_checkbox.setVisible(False)
|
self.toggle_checkbox.setVisible(False)
|
||||||
|
|
||||||
@ -194,7 +196,10 @@ class MessageBox(QDialog): # {{{
|
|||||||
def set_details(self, msg):
|
def set_details(self, msg):
|
||||||
if not msg:
|
if not msg:
|
||||||
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.setText(self.show_det_msg)
|
||||||
self.det_msg_toggle.setVisible(bool(msg))
|
self.det_msg_toggle.setVisible(bool(msg))
|
||||||
self.det_msg.setVisible(False)
|
self.det_msg.setVisible(False)
|
||||||
@ -488,8 +493,8 @@ class JobError(QDialog): # {{{
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from calibre.gui2 import question_dialog, Application
|
from calibre.gui2 import Application, question_dialog
|
||||||
app = Application([])
|
app = Application([])
|
||||||
print(question_dialog(None, 'title', 'msg <a href="http://google.com">goog</a> ',
|
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))
|
show_copy_button=True))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user