1
0

revealer plugin: move font initialisation to earlier

Co-authored-by: SomberNight <somber.night@protonmail.com>
This commit is contained in:
Soren Stoutner
2024-09-17 09:07:59 -07:00
committed by SomberNight
parent 47370d773c
commit 815e18302d

View File

@@ -19,6 +19,7 @@ import traceback
from decimal import Decimal
from functools import partial
import sys
from typing import TYPE_CHECKING
import qrcode
from PyQt5.QtPrintSupport import QPrinter
@@ -39,6 +40,10 @@ from electrum.gui.qt.main_window import StatusBarButton
from .revealer import RevealerPlugin
if TYPE_CHECKING:
from electrum.gui.qt import ElectrumGui
class Plugin(RevealerPlugin):
MAX_PLAINTEXT_LEN = 189 # chars
@@ -63,6 +68,16 @@ class Plugin(RevealerPlugin):
make_dir(self.base_dir)
self.extension = False
self._init_qt_received = False
@hook
def init_qt(self, gui: 'ElectrumGui'):
if self._init_qt_received: # only need/want the first signal
return
self._init_qt_received = True
# load custom fonts (note: here, and not in __init__, as it needs the QApplication to be created)
QFontDatabase.addApplicationFont(os.path.join(os.path.dirname(__file__), 'SourceSans3-Bold.otf'))
QFontDatabase.addApplicationFont(os.path.join(os.path.dirname(__file__), 'DejaVuSansMono-Bold.ttf'))
@hook
def create_status_bar(self, sb):
@@ -402,7 +417,6 @@ class Plugin(RevealerPlugin):
bitmap.fill(Qt.white)
painter = QPainter()
painter.begin(bitmap)
QFontDatabase.addApplicationFont(os.path.join(os.path.dirname(__file__), 'SourceSans3-Bold.otf'))
if len(txt) < 102 :
fontsize = 15
linespace = 15
@@ -548,13 +562,13 @@ class Plugin(RevealerPlugin):
painter = QPainter()
painter.begin(printer)
painter.drawImage(553,533, image)
font = QFont('Source Sans Pro', 10, QFont.Bold)
font = QFont('Source Sans 3', 10, QFont.Bold)
painter.setFont(font)
painter.drawText(254,277, _("Calibration sheet"))
font = QFont('Source Sans Pro', 7, QFont.Bold)
font = QFont('Source Sans 3', 7, QFont.Bold)
painter.setFont(font)
painter.drawText(600,2077, _("Instructions:"))
font = QFont('Source Sans Pro', 7, QFont.Normal)
font = QFont("", 7, QFont.Normal)
painter.setFont(font)
painter.drawText(700, 2177, _("1. Place this paper on a flat and well illuminated surface."))
painter.drawText(700, 2277, _("2. Align your Revealer borderlines to the dashed lines on the top and left."))
@@ -644,7 +658,6 @@ class Plugin(RevealerPlugin):
#print code
f_size = 37
QFontDatabase.addApplicationFont(os.path.join(os.path.dirname(__file__), 'DejaVuSansMono-Bold.ttf'))
font = QFont("DejaVu Sans Mono", f_size-11, QFont.Bold)
font.setPixelSize(35)
painter.setFont(font)