mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
070ad5351e
commit
9805f3a644
@ -8,7 +8,7 @@ from collections import namedtuple
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QAction, QApplication, QColor, QEasingCurve, QFontInfo, QIcon, QLayout, QMenu,
|
QAction, QApplication, QColor, QEasingCurve, QIcon, QLayout, QMenu,
|
||||||
QMimeData, QPainter, QPalette, QPen, QPixmap, QPropertyAnimation, QRect, QSize,
|
QMimeData, QPainter, QPalette, QPen, QPixmap, QPropertyAnimation, QRect, QSize,
|
||||||
QSizePolicy, Qt, QUrl, QWidget, pyqtProperty, pyqtSignal
|
QSizePolicy, Qt, QUrl, QWidget, pyqtProperty, pyqtSignal
|
||||||
)
|
)
|
||||||
@ -118,12 +118,6 @@ def render_html(mi, css, vertical, widget, all_fields=False, render_data_func=No
|
|||||||
ans = unicode_type(col.name())
|
ans = unicode_type(col.name())
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
fi = QFontInfo(QApplication.font(widget))
|
|
||||||
f = fi.pixelSize() + 1 + int(tweaks['change_book_details_font_size_by'])
|
|
||||||
fam = unicode_type(fi.family()).strip().replace('"', '')
|
|
||||||
if not fam:
|
|
||||||
fam = 'sans-serif'
|
|
||||||
|
|
||||||
c = color_to_string(QApplication.palette().color(QPalette.Normal,
|
c = color_to_string(QApplication.palette().color(QPalette.Normal,
|
||||||
QPalette.WindowText))
|
QPalette.WindowText))
|
||||||
templ = '''\
|
templ = '''\
|
||||||
@ -132,8 +126,6 @@ def render_html(mi, css, vertical, widget, all_fields=False, render_data_func=No
|
|||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
body, td {
|
body, td {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
font-size: %dpx;
|
|
||||||
font-family: "%s",sans-serif;
|
|
||||||
color: %s
|
color: %s
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@ -145,10 +137,10 @@ def render_html(mi, css, vertical, widget, all_fields=False, render_data_func=No
|
|||||||
%%s
|
%%s
|
||||||
</body>
|
</body>
|
||||||
<html>
|
<html>
|
||||||
'''%(f, fam, c, css)
|
'''%(c, css)
|
||||||
comments = ''
|
comments = ''
|
||||||
if comment_fields:
|
if comment_fields:
|
||||||
comments = '\n'.join(u'<div>%s</div>' % x for x in comment_fields)
|
comments = '\n'.join('<div>%s</div>' % x for x in comment_fields)
|
||||||
right_pane = '<div id="comments" class="comments">%s</div>'%comments
|
right_pane = '<div id="comments" class="comments">%s</div>'%comments
|
||||||
|
|
||||||
if vertical:
|
if vertical:
|
||||||
|
@ -17,7 +17,7 @@ from io import BytesIO
|
|||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QStyledItemDelegate, QTextDocument, QRectF, QIcon, Qt, QApplication,
|
QStyledItemDelegate, QTextDocument, QRectF, QIcon, Qt, QApplication,
|
||||||
QDialog, QVBoxLayout, QLabel, QDialogButtonBox, QStyle, QStackedWidget,
|
QDialog, QVBoxLayout, QLabel, QDialogButtonBox, QStyle, QStackedWidget,
|
||||||
QWidget, QTableView, QGridLayout, QFontInfo, QPalette, QTimer, pyqtSignal,
|
QWidget, QTableView, QGridLayout, QPalette, QTimer, pyqtSignal,
|
||||||
QAbstractTableModel, QSize, QListView, QPixmap, QModelIndex,
|
QAbstractTableModel, QSize, QListView, QPixmap, QModelIndex,
|
||||||
QAbstractListModel, QRect, QTextBrowser, QStringListModel, QMenu,
|
QAbstractListModel, QRect, QTextBrowser, QStringListModel, QMenu,
|
||||||
QCursor, QHBoxLayout, QPushButton, QSizePolicy)
|
QCursor, QHBoxLayout, QPushButton, QSizePolicy)
|
||||||
@ -35,7 +35,6 @@ from calibre.utils.date import (utcnow, fromordinal, format_date,
|
|||||||
UNDEFINED_DATE, as_utc)
|
UNDEFINED_DATE, as_utc)
|
||||||
from calibre.library.comments import comments_to_html
|
from calibre.library.comments import comments_to_html
|
||||||
from calibre import force_unicode
|
from calibre import force_unicode
|
||||||
from calibre.utils.config import tweaks
|
|
||||||
from calibre.utils.ipc.simple_worker import fork_job, WorkerError
|
from calibre.utils.ipc.simple_worker import fork_job, WorkerError
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from polyglot.builtins import iteritems, itervalues, unicode_type, range, getcwd
|
from polyglot.builtins import iteritems, itervalues, unicode_type, range, getcwd
|
||||||
@ -355,19 +354,13 @@ class Comments(HTMLDisplay): # {{{
|
|||||||
ans = unicode_type(col.name())
|
ans = unicode_type(col.name())
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
fi = QFontInfo(QApplication.font(self.parent()))
|
|
||||||
f = fi.pixelSize()+1+int(tweaks['change_book_details_font_size_by'])
|
|
||||||
fam = unicode_type(fi.family()).strip().replace('"', '')
|
|
||||||
if not fam:
|
|
||||||
fam = 'sans-serif'
|
|
||||||
|
|
||||||
c = color_to_string(QApplication.palette().color(QPalette.Normal,
|
c = color_to_string(QApplication.palette().color(QPalette.Normal,
|
||||||
QPalette.WindowText))
|
QPalette.WindowText))
|
||||||
templ = '''\
|
templ = '''\
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
body, td {background-color: transparent; font-family: "%s"; font-size: %dpx; color: %s }
|
body, td {background-color: transparent; color: %s }
|
||||||
a { text-decoration: none; color: blue }
|
a { text-decoration: none; color: blue }
|
||||||
div.description { margin-top: 0; padding-top: 0; text-indent: 0 }
|
div.description { margin-top: 0; padding-top: 0; text-indent: 0 }
|
||||||
table { margin-bottom: 0; padding-bottom: 0; }
|
table { margin-bottom: 0; padding-bottom: 0; }
|
||||||
@ -379,7 +372,7 @@ class Comments(HTMLDisplay): # {{{
|
|||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<html>
|
<html>
|
||||||
'''%(fam, f, c)
|
'''%(c,)
|
||||||
self.setHtml(templ%html)
|
self.setHtml(templ%html)
|
||||||
|
|
||||||
def sizeHint(self):
|
def sizeHint(self):
|
||||||
|
@ -10,11 +10,12 @@ from PyQt5.Qt import (
|
|||||||
QAbstractListModel, QApplication, QCheckBox, QColor, QColorDialog, QComboBox,
|
QAbstractListModel, QApplication, QCheckBox, QColor, QColorDialog, QComboBox,
|
||||||
QDialog, QDialogButtonBox, QFont, QIcon, QKeySequence, QLabel, QLayout,
|
QDialog, QDialogButtonBox, QFont, QIcon, QKeySequence, QLabel, QLayout,
|
||||||
QModelIndex, QPalette, QPixmap, QPoint, QPushButton, QRect, QSize, QSizePolicy,
|
QModelIndex, QPalette, QPixmap, QPoint, QPushButton, QRect, QSize, QSizePolicy,
|
||||||
QStyle, QStyledItemDelegate, Qt, QTextBrowser, QToolButton, QUndoCommand,
|
QStyle, QStyledItemDelegate, Qt, QTextBrowser, QToolButton, QUndoCommand, QFontInfo,
|
||||||
QUndoStack, QWidget, pyqtSignal
|
QUndoStack, QWidget, pyqtSignal
|
||||||
)
|
)
|
||||||
|
|
||||||
from calibre.ebooks.metadata import rating_to_stars
|
from calibre.ebooks.metadata import rating_to_stars
|
||||||
|
from calibre.utils.config_base import tweaks
|
||||||
from calibre.gui2 import gprefs, rating_font
|
from calibre.gui2 import gprefs, rating_font
|
||||||
from calibre.gui2.complete2 import EditWithComplete, LineEdit
|
from calibre.gui2.complete2 import EditWithComplete, LineEdit
|
||||||
from calibre.gui2.widgets import history
|
from calibre.gui2.widgets import history
|
||||||
@ -433,6 +434,12 @@ class HTMLDisplay(QTextBrowser):
|
|||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QTextBrowser.__init__(self, parent)
|
QTextBrowser.__init__(self, parent)
|
||||||
|
font = self.font()
|
||||||
|
f = QFontInfo(self.font())
|
||||||
|
delta = tweaks['change_book_details_font_size_by'] + 1
|
||||||
|
if delta:
|
||||||
|
font.setPixelSize(f.pixelSize() + delta)
|
||||||
|
self.setFont(font)
|
||||||
self.setFrameShape(self.NoFrame)
|
self.setFrameShape(self.NoFrame)
|
||||||
self.setOpenLinks(False)
|
self.setOpenLinks(False)
|
||||||
self.setAttribute(Qt.WA_OpaquePaintEvent, False)
|
self.setAttribute(Qt.WA_OpaquePaintEvent, False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user