From d8ff4f25fc48b7cecd89996e5205efdab00ee6e3 Mon Sep 17 00:00:00 2001 From: Mike Hendricks Date: Thu, 14 Dec 2023 09:32:00 -0800 Subject: [PATCH] Fix font resizing saving and improve statusTimer Combined the font setting methods into a single setFont method that can report the new font family and size in the status label. statusTimer did not get restarted correctly if called before it expired. --- preditor/gui/loggerwindow.py | 42 +++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/preditor/gui/loggerwindow.py b/preditor/gui/loggerwindow.py index c4b1dae8..415347ae 100644 --- a/preditor/gui/loggerwindow.py +++ b/preditor/gui/loggerwindow.py @@ -64,6 +64,7 @@ def __init__(self, parent, name=None, run_workbox=False): # Create timer to autohide status messages self.statusTimer = QTimer() self.statusTimer.setSingleShot(True) + self.statusTimer.timeout.connect(self.clearStatusText) # Store the previous time a font-resize wheel event was triggered to prevent # rapid-fire WheelEvents. Initialize to the current time. @@ -477,18 +478,12 @@ def wheelEvent(self, event): font = self.console().font() newSize = font.pointSize() + delta newSize = max(min(newSize, maxSize), minSize) + newSize = int(newSize) font.setPointSize(newSize) - self.console().setConsoleFont(font) - - for workbox in self.uiWorkboxTAB.all_widgets(): - marginsFont = workbox.__margins_font__() - marginsFont.setPointSize(newSize) - workbox.__set_margins_font__(marginsFont) - - workbox.__set_font__(font) + self.setFont(font, report=True) else: - Window.wheelEvent(self, event) + super(LoggerWindow, self).wheelEvent(event) def handleMenuHovered(self, action): """Qt4 doesn't have a ToolTipsVisible method, so we fake it""" @@ -533,11 +528,7 @@ def selectFont(self, action): family = action.text() font = self.console().font() font.setFamily(family) - self.console().setConsoleFont(font) - - for workbox in self.uiWorkboxTAB.all_widgets(): - workbox.__set_margins_font__(font) - workbox.__set_font__(font) + self.setFont(font) @classmethod def _genPrefName(cls, baseName, index): @@ -762,7 +753,7 @@ def restorePrefs(self): if _font: font = QFont() if font.fromString(_font): - self.console().setConsoleFont(font) + self.setFont(font) def restoreToolbars(self, pref=None): if pref is None: @@ -808,8 +799,7 @@ def autoHideStatusText(self): """Set timer to automatically clear status text""" if self.statusTimer.isActive(): self.statusTimer.stop() - self.statusTimer.singleShot(2000, self.clearStatusText) - self.statusTimer.start() + self.statusTimer.start(2000) def setStyleSheet(self, stylesheet, recordPrefs=True): """Accepts the name of a stylesheet included with blurdev, or a full @@ -934,6 +924,24 @@ def setFlashWindowInterval(self): if success: self.uiConsoleTXT.flash_time = value + def setFont(self, font, report=False): + """Set the same font for the console and all workbox's margins and text. + + Args: + font (QFont): The font to set. + report (bool, optional): Update status text with the font family and size. + """ + super(LoggerWindow, self).setFont(font) + self.console().setConsoleFont(font) + + for workbox in self.uiWorkboxTAB.all_widgets(): + workbox.__set_margins_font__(font) + workbox.__set_font__(font) + + if report: + self.setStatusText('Font: {}: {}'.format(font.family(), font.pointSize())) + self.autoHideStatusText() + def setWordWrap(self, state): if state: self.uiConsoleTXT.setLineWrapMode(self.uiConsoleTXT.WidgetWidth)