Remove computed GUI scaling

This commit is contained in:
Veronica Berglyd Olsen
2025-01-12 15:39:10 +01:00
parent a1d94d63a3
commit 60130f067b
3 changed files with 15 additions and 86 deletions
+15 -20
View File
@@ -115,7 +115,6 @@ class Config:
self.guiTheme = "default" # GUI theme self.guiTheme = "default" # GUI theme
self.guiSyntax = "default_light" # Syntax theme self.guiSyntax = "default_light" # Syntax theme
self.guiFont = QFont() # Main GUI font self.guiFont = QFont() # Main GUI font
self.guiScale = 1.0 # Set automatically by Theme class
self.hideVScroll = False # Hide vertical scroll bars on main widgets self.hideVScroll = False # Hide vertical scroll bars on main widgets
self.hideHScroll = False # Hide horizontal scroll bars on main widgets self.hideHScroll = False # Hide horizontal scroll bars on main widgets
self.lastNotes = "0x0" # The latest release notes that have been shown self.lastNotes = "0x0" # The latest release notes that have been shown
@@ -272,27 +271,27 @@ class Config:
@property @property
def mainWinSize(self) -> list[int]: def mainWinSize(self) -> list[int]:
return [int(x*self.guiScale) for x in self._mainWinSize] return self._mainWinSize
@property @property
def welcomeWinSize(self) -> list[int]: def welcomeWinSize(self) -> list[int]:
return [int(x*self.guiScale) for x in self._welcomeSize] return self._welcomeSize
@property @property
def preferencesWinSize(self) -> list[int]: def preferencesWinSize(self) -> list[int]:
return [int(x*self.guiScale) for x in self._prefsWinSize] return self._prefsWinSize
@property @property
def mainPanePos(self) -> list[int]: def mainPanePos(self) -> list[int]:
return [int(x*self.guiScale) for x in self._mainPanePos] return self._mainPanePos
@property @property
def viewPanePos(self) -> list[int]: def viewPanePos(self) -> list[int]:
return [int(x*self.guiScale) for x in self._viewPanePos] return self._viewPanePos
@property @property
def outlinePanePos(self) -> list[int]: def outlinePanePos(self) -> list[int]:
return [int(x*self.guiScale) for x in self._outlnPanePos] return self._outlnPanePos
## ##
# Getters # Getters
@@ -323,8 +322,6 @@ class Config:
adjust it a bit, and we don't want the main window to shrink or adjust it a bit, and we don't want the main window to shrink or
grow each time the app is opened. grow each time the app is opened.
""" """
width = int(width/self.guiScale)
height = int(height/self.guiScale)
if abs(self._mainWinSize[0] - width) > 5: if abs(self._mainWinSize[0] - width) > 5:
self._mainWinSize[0] = width self._mainWinSize[0] = width
if abs(self._mainWinSize[1] - height) > 5: if abs(self._mainWinSize[1] - height) > 5:
@@ -333,29 +330,27 @@ class Config:
def setWelcomeWinSize(self, width: int, height: int) -> None: def setWelcomeWinSize(self, width: int, height: int) -> None:
"""Set the size of the Preferences dialog window.""" """Set the size of the Preferences dialog window."""
self._welcomeSize[0] = int(width/self.guiScale) self._welcomeSize = [width, height]
self._welcomeSize[1] = int(height/self.guiScale)
return return
def setPreferencesWinSize(self, width: int, height: int) -> None: def setPreferencesWinSize(self, width: int, height: int) -> None:
"""Set the size of the Preferences dialog window.""" """Set the size of the Preferences dialog window."""
self._prefsWinSize[0] = int(width/self.guiScale) self._prefsWinSize = [width, height]
self._prefsWinSize[1] = int(height/self.guiScale)
return return
def setMainPanePos(self, pos: list[int]) -> None: def setMainPanePos(self, pos: list[int]) -> None:
"""Set the position of the main GUI splitter.""" """Set the position of the main GUI splitter."""
self._mainPanePos = [int(x/self.guiScale) for x in pos] self._mainPanePos = pos
return return
def setViewPanePos(self, pos: list[int]) -> None: def setViewPanePos(self, pos: list[int]) -> None:
"""Set the position of the viewer meta data splitter.""" """Set the position of the viewer meta data splitter."""
self._viewPanePos = [int(x/self.guiScale) for x in pos] self._viewPanePos = pos
return return
def setOutlinePanePos(self, pos: list[int]) -> None: def setOutlinePanePos(self, pos: list[int]) -> None:
"""Set the position of the outline details splitter.""" """Set the position of the outline details splitter."""
self._outlnPanePos = [int(x/self.guiScale) for x in pos] self._outlnPanePos = pos
return return
def setLastPath(self, key: str, path: str | Path) -> None: def setLastPath(self, key: str, path: str | Path) -> None:
@@ -427,12 +422,12 @@ class Config:
## ##
def pxInt(self, value: int) -> int: def pxInt(self, value: int) -> int:
"""Scale fixed gui sizes by the screen scale factor.""" """Deprecated. Do not use."""
return int(value*self.guiScale) return value
def rpxInt(self, value: int) -> int: def rpxInt(self, value: int) -> int:
"""Un-scale fixed gui sizes by the screen scale factor.""" """Deprecated. Do not use."""
return int(value/self.guiScale) return value
def homePath(self) -> Path: def homePath(self) -> Path:
"""The user's home folder.""" """The user's home folder."""
-7
View File
@@ -143,13 +143,6 @@ class GuiTheme:
self.getHeaderDecoration = self.iconCache.getHeaderDecoration self.getHeaderDecoration = self.iconCache.getHeaderDecoration
self.getHeaderDecorationNarrow = self.iconCache.getHeaderDecorationNarrow self.getHeaderDecorationNarrow = self.iconCache.getHeaderDecorationNarrow
# Extract Other Info
self.guiDPI = QApplication.primaryScreen().logicalDotsPerInchX()
self.guiScale = QApplication.primaryScreen().logicalDotsPerInchX()/96.0
CONFIG.guiScale = self.guiScale
logger.debug("GUI DPI: %.1f", self.guiDPI)
logger.debug("GUI Scale: %.2f", self.guiScale)
# Fonts # Fonts
self.guiFont = QApplication.font() self.guiFont = QApplication.font()
self.guiFontB = QApplication.font() self.guiFontB = QApplication.font()
-59
View File
@@ -245,35 +245,13 @@ def testBaseConfig_SettersGetters(fncPath):
tstConf = Config() tstConf = Config()
tstConf.initConfig(confPath=fncPath, dataPath=fncPath) tstConf.initConfig(confPath=fncPath, dataPath=fncPath)
# GUI Scaling
# ===========
tstConf.guiScale = 1.0
assert tstConf.pxInt(10) == 10
assert tstConf.pxInt(13) == 13
assert tstConf.rpxInt(10) == 10
assert tstConf.rpxInt(13) == 13
tstConf.guiScale = 2.0
assert tstConf.pxInt(10) == 20
assert tstConf.pxInt(13) == 26
assert tstConf.rpxInt(10) == 5
assert tstConf.rpxInt(13) == 6
# Setter + Getter Combos # Setter + Getter Combos
# ====================== # ======================
# Window Size # Window Size
tstConf.guiScale = 1.0
tstConf.setMainWinSize(1205, 655) tstConf.setMainWinSize(1205, 655)
assert tstConf.mainWinSize == [1200, 650] assert tstConf.mainWinSize == [1200, 650]
tstConf.guiScale = 2.0
tstConf.setMainWinSize(70, 70)
assert tstConf.mainWinSize == [70, 70]
assert tstConf._mainWinSize == [35, 35]
tstConf.guiScale = 1.0
tstConf.setMainWinSize(70, 70) tstConf.setMainWinSize(70, 70)
assert tstConf.mainWinSize == [70, 70] assert tstConf.mainWinSize == [70, 70]
assert tstConf._mainWinSize == [70, 70] assert tstConf._mainWinSize == [70, 70]
@@ -281,12 +259,6 @@ def testBaseConfig_SettersGetters(fncPath):
tstConf.setMainWinSize(1200, 650) tstConf.setMainWinSize(1200, 650)
# Welcome Window Size # Welcome Window Size
tstConf.guiScale = 2.0
tstConf.setWelcomeWinSize(70, 70)
assert tstConf.welcomeWinSize == [70, 70]
assert tstConf._welcomeSize == [35, 35]
tstConf.guiScale = 1.0
tstConf.setWelcomeWinSize(70, 70) tstConf.setWelcomeWinSize(70, 70)
assert tstConf.welcomeWinSize == [70, 70] assert tstConf.welcomeWinSize == [70, 70]
assert tstConf._welcomeSize == [70, 70] assert tstConf._welcomeSize == [70, 70]
@@ -294,12 +266,6 @@ def testBaseConfig_SettersGetters(fncPath):
tstConf.setWelcomeWinSize(800, 500) tstConf.setWelcomeWinSize(800, 500)
# Preferences Size # Preferences Size
tstConf.guiScale = 2.0
tstConf.setPreferencesWinSize(70, 70)
assert tstConf.preferencesWinSize == [70, 70]
assert tstConf._prefsWinSize == [35, 35]
tstConf.guiScale = 1.0
tstConf.setPreferencesWinSize(70, 70) tstConf.setPreferencesWinSize(70, 70)
assert tstConf.preferencesWinSize == [70, 70] assert tstConf.preferencesWinSize == [70, 70]
assert tstConf._prefsWinSize == [70, 70] assert tstConf._prefsWinSize == [70, 70]
@@ -307,12 +273,6 @@ def testBaseConfig_SettersGetters(fncPath):
tstConf.setPreferencesWinSize(700, 615) tstConf.setPreferencesWinSize(700, 615)
# Main Pane Splitter # Main Pane Splitter
tstConf.guiScale = 2.0
tstConf.setMainPanePos([200, 700])
assert tstConf.mainPanePos == [200, 700]
assert tstConf._mainPanePos == [100, 350]
tstConf.guiScale = 1.0
tstConf.setMainPanePos([200, 700]) tstConf.setMainPanePos([200, 700])
assert tstConf.mainPanePos == [200, 700] assert tstConf.mainPanePos == [200, 700]
assert tstConf._mainPanePos == [200, 700] assert tstConf._mainPanePos == [200, 700]
@@ -320,12 +280,6 @@ def testBaseConfig_SettersGetters(fncPath):
tstConf.setMainPanePos([300, 800]) tstConf.setMainPanePos([300, 800])
# View Pane Splitter # View Pane Splitter
tstConf.guiScale = 2.0
tstConf.setViewPanePos([400, 250])
assert tstConf.viewPanePos == [400, 250]
assert tstConf._viewPanePos == [200, 125]
tstConf.guiScale = 1.0
tstConf.setViewPanePos([400, 250]) tstConf.setViewPanePos([400, 250])
assert tstConf.viewPanePos == [400, 250] assert tstConf.viewPanePos == [400, 250]
assert tstConf._viewPanePos == [400, 250] assert tstConf._viewPanePos == [400, 250]
@@ -333,12 +287,6 @@ def testBaseConfig_SettersGetters(fncPath):
tstConf.setViewPanePos([500, 150]) tstConf.setViewPanePos([500, 150])
# Outline Pane Splitter # Outline Pane Splitter
tstConf.guiScale = 2.0
tstConf.setOutlinePanePos([400, 250])
assert tstConf.outlinePanePos == [400, 250]
assert tstConf._outlnPanePos == [200, 125]
tstConf.guiScale = 1.0
tstConf.setOutlinePanePos([400, 250]) tstConf.setOutlinePanePos([400, 250])
assert tstConf.outlinePanePos == [400, 250] assert tstConf.outlinePanePos == [400, 250]
assert tstConf._outlnPanePos == [400, 250] assert tstConf._outlnPanePos == [400, 250]
@@ -348,18 +296,11 @@ def testBaseConfig_SettersGetters(fncPath):
# Getters Only # Getters Only
# ============ # ============
tstConf.guiScale = 1.0
assert tstConf.getTextWidth(False) == 700 assert tstConf.getTextWidth(False) == 700
assert tstConf.getTextWidth(True) == 800 assert tstConf.getTextWidth(True) == 800
assert tstConf.getTextMargin() == 40 assert tstConf.getTextMargin() == 40
assert tstConf.getTabWidth() == 40 assert tstConf.getTabWidth() == 40
tstConf.guiScale = 2.0
assert tstConf.getTextWidth(False) == 1400
assert tstConf.getTextWidth(True) == 1600
assert tstConf.getTextMargin() == 80
assert tstConf.getTabWidth() == 80
@pytest.mark.base @pytest.mark.base
def testBaseConfig_Internal(monkeypatch, fncPath): def testBaseConfig_Internal(monkeypatch, fncPath):