mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
py310: More int->float goodness
This commit is contained in:
parent
67ad530492
commit
65923491f1
@ -5,16 +5,17 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, shutil
|
import os
|
||||||
|
import shutil
|
||||||
from qt.core import (QFontInfo, QFontMetrics, Qt, QFont, QFontDatabase, QPen,
|
from qt.core import (
|
||||||
QStyledItemDelegate, QSize, QStyle, QStringListModel, pyqtSignal,
|
QAbstractItemView, QDialog, QDialogButtonBox, QFont, QFontComboBox,
|
||||||
QDialog, QVBoxLayout, QApplication, QFontComboBox, QPushButton,
|
QFontDatabase, QFontInfo, QFontMetrics, QGridLayout, QHBoxLayout, QIcon, QLabel,
|
||||||
QToolButton, QGridLayout, QListView, QWidget, QDialogButtonBox, QIcon,
|
QLineEdit, QListView, QPen, QPushButton, QSize, QSizePolicy, QStringListModel,
|
||||||
QHBoxLayout, QLabel, QLineEdit, QSizePolicy, QAbstractItemView)
|
QStyle, QStyledItemDelegate, Qt, QToolButton, QVBoxLayout, QWidget, pyqtSignal
|
||||||
|
)
|
||||||
|
|
||||||
from calibre.constants import config_dir
|
from calibre.constants import config_dir
|
||||||
from calibre.gui2 import choose_files, error_dialog, info_dialog, empty_index
|
from calibre.gui2 import choose_files, empty_index, error_dialog, info_dialog
|
||||||
|
|
||||||
|
|
||||||
def add_fonts(parent):
|
def add_fonts(parent):
|
||||||
@ -96,7 +97,7 @@ class FontFamilyDelegate(QStyledItemDelegate):
|
|||||||
def do_size_hint(self, option, index):
|
def do_size_hint(self, option, index):
|
||||||
text = index.data(Qt.ItemDataRole.DisplayRole) or ''
|
text = index.data(Qt.ItemDataRole.DisplayRole) or ''
|
||||||
font = QFont(option.font)
|
font = QFont(option.font)
|
||||||
font.setPointSize(QFontInfo(font).pointSize() * 1.5)
|
font.setPointSizeF(QFontInfo(font).pointSize() * 1.5)
|
||||||
m = QFontMetrics(font)
|
m = QFontMetrics(font)
|
||||||
return QSize(m.width(text), m.height())
|
return QSize(m.width(text), m.height())
|
||||||
|
|
||||||
@ -106,13 +107,14 @@ class FontFamilyDelegate(QStyledItemDelegate):
|
|||||||
try:
|
try:
|
||||||
self.do_paint(painter, option, index)
|
self.do_paint(painter, option, index)
|
||||||
except:
|
except:
|
||||||
pass
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
painter.restore()
|
painter.restore()
|
||||||
|
|
||||||
def do_paint(self, painter, option, index):
|
def do_paint(self, painter, option, index):
|
||||||
text = str(index.data(Qt.ItemDataRole.DisplayRole) or '')
|
text = str(index.data(Qt.ItemDataRole.DisplayRole) or '')
|
||||||
font = QFont(option.font)
|
font = QFont(option.font)
|
||||||
font.setPointSize(QFontInfo(font).pointSize() * 1.5)
|
font.setPointSizeF(QFontInfo(font).pointSize() * 1.5)
|
||||||
font2 = QFont(font)
|
font2 = QFont(font)
|
||||||
font2.setFamily(text)
|
font2.setFamily(text)
|
||||||
|
|
||||||
@ -121,9 +123,11 @@ class FontFamilyDelegate(QStyledItemDelegate):
|
|||||||
font = font2
|
font = font2
|
||||||
|
|
||||||
r = option.rect
|
r = option.rect
|
||||||
|
color = option.palette.text()
|
||||||
|
|
||||||
if option.state & QStyle.StateFlag.State_Selected:
|
if option.state & QStyle.StateFlag.State_Selected:
|
||||||
painter.setPen(QPen(option.palette.highlightedText(), 0))
|
color = option.palette.highlightedText()
|
||||||
|
painter.setPen(QPen(color, 0))
|
||||||
|
|
||||||
if (option.direction == Qt.LayoutDirection.RightToLeft):
|
if (option.direction == Qt.LayoutDirection.RightToLeft):
|
||||||
r.setRight(r.right() - 4)
|
r.setRight(r.right() - 4)
|
||||||
@ -369,7 +373,8 @@ class FontFamilyChooser(QWidget):
|
|||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
app = QApplication([])
|
from calibre.gui2 import Application
|
||||||
|
app = Application([])
|
||||||
app
|
app
|
||||||
d = QDialog()
|
d = QDialog()
|
||||||
d.setLayout(QVBoxLayout())
|
d.setLayout(QVBoxLayout())
|
||||||
|
@ -114,12 +114,12 @@ class TextBrowser(PlainTextEdit): # {{{
|
|||||||
if ff is None:
|
if ff is None:
|
||||||
ff = default_font_family()
|
ff = default_font_family()
|
||||||
font.setFamily(ff)
|
font.setFamily(ff)
|
||||||
font.setPointSize(tprefs['editor_font_size'])
|
font.setPointSizeF(tprefs['editor_font_size'])
|
||||||
self.setFont(font)
|
self.setFont(font)
|
||||||
self.calculate_metrics()
|
self.calculate_metrics()
|
||||||
self.setTabStopWidth(tprefs['editor_tab_stop_width'] * self.space_width)
|
self.setTabStopWidth(tprefs['editor_tab_stop_width'] * self.space_width)
|
||||||
font = self.heading_font = QFont(self.font())
|
font = self.heading_font = QFont(self.font())
|
||||||
font.setPointSize(int(tprefs['editor_font_size'] * 1.5))
|
font.setPointSizeF(tprefs['editor_font_size'] * 1.5)
|
||||||
font.setBold(True)
|
font.setBold(True)
|
||||||
theme = get_theme(tprefs['editor_theme'])
|
theme = get_theme(tprefs['editor_theme'])
|
||||||
pal = self.palette()
|
pal = self.palette()
|
||||||
|
@ -253,9 +253,9 @@ class TextEdit(PlainTextEdit):
|
|||||||
if ff is None:
|
if ff is None:
|
||||||
ff = default_font_family()
|
ff = default_font_family()
|
||||||
font.setFamily(ff)
|
font.setFamily(ff)
|
||||||
font.setPointSize(tprefs['editor_font_size'])
|
font.setPointSizeF(tprefs['editor_font_size'])
|
||||||
self.tooltip_font = QFont(font)
|
self.tooltip_font = QFont(font)
|
||||||
self.tooltip_font.setPointSize(font.pointSize() - 1)
|
self.tooltip_font.setPointSizeF(font.pointSizeF() - 1.)
|
||||||
self.setFont(font)
|
self.setFont(font)
|
||||||
self.highlighter.apply_theme(theme)
|
self.highlighter.apply_theme(theme)
|
||||||
w = self.fontMetrics()
|
w = self.fontMetrics()
|
||||||
|
@ -424,7 +424,7 @@ class LiveCSS(QWidget):
|
|||||||
def apply_theme(self):
|
def apply_theme(self):
|
||||||
f = self.font()
|
f = self.font()
|
||||||
f.setFamily(tprefs['editor_font_family'] or default_font_family())
|
f.setFamily(tprefs['editor_font_family'] or default_font_family())
|
||||||
f.setPointSize(tprefs['editor_font_size'])
|
f.setPointSizeF(tprefs['editor_font_size'])
|
||||||
self.setFont(f)
|
self.setFont(f)
|
||||||
theme = get_theme(tprefs['editor_theme'])
|
theme = get_theme(tprefs['editor_theme'])
|
||||||
pal = self.palette()
|
pal = self.palette()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user