mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
cd8af8ca11
commit
60d44baaf5
@ -75,6 +75,16 @@ def css(reset=False):
|
||||
return css.ans
|
||||
|
||||
|
||||
def resolve_colors(css):
|
||||
app = QApplication.instance()
|
||||
col = app.palette().color(QPalette.ColorRole.PlaceholderText).name() if app.is_dark_theme else '#666'
|
||||
return css.replace('palette(placeholder-text)', col)
|
||||
|
||||
|
||||
def resolved_css():
|
||||
return resolve_colors(css())
|
||||
|
||||
|
||||
def copy_all(text_browser):
|
||||
mf = getattr(text_browser, 'details', text_browser)
|
||||
c = QApplication.clipboard()
|
||||
@ -977,8 +987,7 @@ class BookInfo(HTMLDisplay):
|
||||
set_html(mi, html, self)
|
||||
|
||||
def process_external_css(self, css):
|
||||
col = self.palette().color(QPalette.ColorRole.PlaceholderText).name() if QApplication.instance().is_dark_theme else '#666'
|
||||
return css.replace('palette(placeholder-text)', col)
|
||||
return resolve_colors(css)
|
||||
|
||||
def mouseDoubleClickEvent(self, ev):
|
||||
v = self.viewport()
|
||||
|
@ -24,7 +24,7 @@ from calibre.ebooks.chardet import xml_to_unicode
|
||||
from calibre.gui2 import (
|
||||
NO_URL_FORMATTING, choose_dir, choose_files, error_dialog, gprefs, is_dark_theme,
|
||||
)
|
||||
from calibre.gui2.book_details import css
|
||||
from calibre.gui2.book_details import resolved_css
|
||||
from calibre.gui2.flow_toolbar import create_flow_toolbar
|
||||
from calibre.gui2.widgets import LineEditECM
|
||||
from calibre.gui2.widgets2 import to_plain_text
|
||||
@ -288,7 +288,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
||||
def __init__(self, parent=None):
|
||||
QTextEdit.__init__(self, parent)
|
||||
self.setTabChangesFocus(True)
|
||||
self.document().setDefaultStyleSheet(css().replace('palette(placeholder-text)', 'gray') + '\n\nli { margin-top: 0.5ex; margin-bottom: 0.5ex; }')
|
||||
self.document().setDefaultStyleSheet(resolved_css() + '\n\nli { margin-top: 0.5ex; margin-bottom: 0.5ex; }')
|
||||
font = self.font()
|
||||
f = QFontInfo(font)
|
||||
delta = tweaks['change_book_details_font_size_by'] + 1
|
||||
|
@ -8,7 +8,7 @@ from qt.core import (
|
||||
)
|
||||
|
||||
from calibre.gui2 import safe_open_url, gprefs
|
||||
from calibre.gui2.book_details import css
|
||||
from calibre.gui2.book_details import resolved_css
|
||||
from calibre.gui2.widgets2 import HTMLDisplay
|
||||
from calibre.library.comments import markdown as get_markdown
|
||||
|
||||
@ -17,7 +17,7 @@ class Preview(HTMLDisplay):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setDefaultStyleSheet(css().replace('palette(placeholder-text)', 'gray'))
|
||||
self.setDefaultStyleSheet(resolved_css())
|
||||
self.setTabChangesFocus(True)
|
||||
self.base_url = None
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user