Skip to content

Commit

Permalink
Fix font resizing saving and improve statusTimer
Browse files Browse the repository at this point in the history
- 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.
- New tabs now get the same font as the other tabs.
  • Loading branch information
MHendricks committed Mar 13, 2024
1 parent 7047908 commit a9e46f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
42 changes: 25 additions & 17 deletions preditor/gui/loggerwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(self, parent, name=None, run_workbox=False, standalone=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.
Expand Down Expand Up @@ -507,18 +508,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"""
Expand Down Expand Up @@ -563,11 +558,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):
Expand Down Expand Up @@ -814,7 +805,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:
Expand Down Expand Up @@ -860,8 +851,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
Expand Down Expand Up @@ -986,6 +976,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)
Expand Down
6 changes: 6 additions & 0 deletions preditor/gui/workbox_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def __init__(
self._tempfile = tempfile
self.core_name = core_name

# Ensure the new instance's font settings match the rest of the app.
if "LoggerWindow" in str(type(self.window())):
font = self.window().font()
self.__set_margins_font__(font)
self.__set_font__(font)

def __auto_complete_enabled__(self):
raise NotImplementedError("Mixin method not overridden.")

Expand Down

0 comments on commit a9e46f5

Please sign in to comment.