From 685af710a63887828bd5ccd5d8a301c835e67e06 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sun, 31 May 2020 12:17:34 +0200 Subject: [PATCH] Remove monospace fonts from main GUI --- nw/gui/elements/docdetails.py | 14 +++++--------- nw/gui/elements/doctree.py | 7 ------- nw/gui/statusbar.py | 7 +------ nw/gui/theme.py | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/nw/gui/elements/docdetails.py b/nw/gui/elements/docdetails.py index 84418802..2905a00e 100644 --- a/nw/gui/elements/docdetails.py +++ b/nw/gui/elements/docdetails.py @@ -29,7 +29,7 @@ import logging import nw from PyQt5.QtCore import Qt -from PyQt5.QtGui import QFont, QIcon, QPixmap, QFontMetrics +from PyQt5.QtGui import QFont, QIcon, QPixmap from PyQt5.QtWidgets import QFrame, QGridLayout, QLabel from nw.constants import ( @@ -65,10 +65,6 @@ class GuiDocDetails(QFrame): self.fntLabel.setBold(True) self.fntLabel.setPointSizeF(self.pS) - self.fntFixed = QFont() - self.fntFixed.setFamily("Monospace") - self.fntFixed.setPointSizeF(self.pS) - self.fntValue = QFont() self.fntValue.setPointSizeF(self.pS) @@ -103,7 +99,7 @@ class GuiDocDetails(QFrame): self.className.setAlignment(Qt.AlignLeft) self.classFlag = QLabel("") - self.classFlag.setFont(self.fntFixed) + self.classFlag.setFont(self.fntValue) self.classFlag.setAlignment(Qt.AlignRight) self.classData = QLabel("") @@ -116,7 +112,7 @@ class GuiDocDetails(QFrame): self.layoutName.setAlignment(Qt.AlignLeft) self.layoutFlag = QLabel("") - self.layoutFlag.setFont(self.fntFixed) + self.layoutFlag.setFont(self.fntValue) self.layoutFlag.setAlignment(Qt.AlignRight) self.layoutData = QLabel("") @@ -180,8 +176,8 @@ class GuiDocDetails(QFrame): self.mainBox.setColumnStretch(4,0) # Make sure the columns for flags and counts don't resize too often - flagWidth = QFontMetrics(self.fntFixed).boundingRect("Mm").width() - countWidth = QFontMetrics(self.fntValue).boundingRect("99,999").width() + flagWidth = self.theTheme.getTextWidth("Mm", self.fntValue) + countWidth = self.theTheme.getTextWidth("99,999", self.fntValue) self.mainBox.setColumnMinimumWidth(1, flagWidth) self.mainBox.setColumnMinimumWidth(4, countWidth) diff --git a/nw/gui/elements/doctree.py b/nw/gui/elements/doctree.py index 5fbfc83d..62d5fd2f 100644 --- a/nw/gui/elements/doctree.py +++ b/nw/gui/elements/doctree.py @@ -99,10 +99,6 @@ class GuiDocTree(QTreeWidget): self.resizeColumnToContents(self.C_EXPORT) self.resizeColumnToContents(self.C_FLAGS) - self.fntFixed = QFont() - self.fntFixed.setFamily("Monospace") - self.fntFixed.setPointSizeF(0.9*self.theTheme.fontPointSize) - logger.debug("DocTree initialisation complete") # Internal Mapping @@ -582,10 +578,7 @@ class GuiDocTree(QTreeWidget): newItem.setText(self.C_FLAGS, "") newItem.setText(self.C_HANDLE, tHandle) - # newItem.setForeground(self.C_COUNT,QColor(*self.theParent.theTheme.treeWCount)) newItem.setTextAlignment(self.C_COUNT, Qt.AlignRight) - # newItem.setTextAlignment(self.C_EXPORT, Qt.AlignHCenter) - newItem.setFont(self.C_FLAGS, self.fntFixed) self.theMap[tHandle] = newItem if pHandle is None: diff --git a/nw/gui/statusbar.py b/nw/gui/statusbar.py index 5fc4c873..20677766 100644 --- a/nw/gui/statusbar.py +++ b/nw/gui/statusbar.py @@ -57,10 +57,6 @@ class GuiMainStatus(QStatusBar): self.projWords = 0 self.sessWords = 0 - self.fntFixed = QFont() - self.fntFixed.setFamily("Monospace") - self.fntFixed.setPointSizeF(0.95*self.theTheme.fontPointSize) - colNone = QColor(*self.theTheme.statNone) colTrue = QColor(*self.theTheme.statUnsaved) colFalse = QColor(*self.theTheme.statSaved) @@ -109,8 +105,7 @@ class GuiMainStatus(QStatusBar): self.timeText = QLabel("") self.timeIcon.setPixmap(self.theTheme.getPixmap("status_time", (iPx, iPx))) self.timeText.setToolTip("Session Time") - self.timeText.setAlignment(Qt.AlignVCenter | Qt.AlignRight) - self.timeText.setFont(self.fntFixed) + self.timeText.setFixedWidth(self.theTheme.getTextWidth("00:00:00.")) self.timeIcon.setContentsMargins(0, 0, 0, 0) self.timeText.setContentsMargins(0, 0, 0, 0) self.addPermanentWidget(self.timeIcon) diff --git a/nw/gui/theme.py b/nw/gui/theme.py index 2d4bff15..a376e1b1 100644 --- a/nw/gui/theme.py +++ b/nw/gui/theme.py @@ -30,6 +30,7 @@ import configparser import nw from os import path, listdir +from math import ceil from PyQt5.QtWidgets import qApp from PyQt5.QtGui import ( @@ -141,6 +142,19 @@ class GuiTheme: return + ## + # Methods + ## + + def getTextWidth(self, theText, theFont=None): + """Returns the width needed to contain a given piece of text. + """ + if isinstance(theFont, QFont): + qMetrics = QFontMetrics(theFont) + else: + qMetrics = QFontMetrics(self.guiFont) + return int(ceil(qMetrics.boundingRect(theText).width())) + ## # Actions ##