add UI scale preference

This commit is contained in:
Damien Elmes 2019-12-19 09:58:16 +10:00
parent 5ce3de0e98
commit 3a4f94ab86
5 changed files with 86 additions and 41 deletions

View file

@ -12,7 +12,6 @@ import locale
import gettext
from typing import Optional
from aqt.main import AnkiQt
from aqt.qt import *
import anki.lang
from anki.consts import HELP_SITE
@ -26,6 +25,9 @@ appDonate="http://ankisrs.net/support/"
appShared="https://ankiweb.net/shared/"
appUpdate="https://ankiweb.net/update/desktop"
appHelpSite=HELP_SITE
from aqt.main import AnkiQt
mw: Optional[AnkiQt] = None # set on init
moduleDir = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
@ -319,6 +321,9 @@ def _run(argv=None, exec=True):
if os.environ.get("ANKI_SOFTWAREOPENGL"):
QCoreApplication.setAttribute(Qt.AA_UseSoftwareOpenGL)
# apply user-provided scale factor
os.environ["QT_SCALE_FACTOR"] = str(pm.uiScale())
# create the app
QCoreApplication.setApplicationName("Anki")
QGuiApplication.setDesktopFileName("anki.desktop")

View file

@ -13,6 +13,7 @@ from threading import Thread
from typing import Optional
from send2trash import send2trash
from anki.collection import _Collection
from aqt.profiles import ProfileManager
from aqt.qt import *
from anki.storage import Collection
from anki.utils import isWin, isMac, intTime, splitFields, ids2str, \
@ -33,7 +34,7 @@ from aqt.qt import sip
from anki.lang import _, ngettext
class AnkiQt(QMainWindow):
def __init__(self, app, profileManager, opts, args):
def __init__(self, app: QApplication, profileManager: ProfileManager, opts, args):
QMainWindow.__init__(self)
self.state = "startup"
self.opts = opts

View file

@ -3,6 +3,8 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import datetime, time
from aqt import AnkiQt
from aqt.qt import *
import anki.lang
from aqt.utils import openHelp, showInfo, askUser
@ -11,7 +13,7 @@ from anki.lang import _
class Preferences(QDialog):
def __init__(self, mw):
def __init__(self, mw: AnkiQt):
QDialog.__init__(self, mw, Qt.Window)
self.mw = mw
self.prof = self.mw.pm.profile
@ -216,7 +218,11 @@ Not currently enabled; click the sync button in the main window to enable."""))
def setupOptions(self):
self.form.pastePNG.setChecked(self.prof.get("pastePNG", False))
self.form.uiScale.setValue(self.mw.pm.uiScale()*100)
def updateOptions(self):
self.prof['pastePNG'] = self.form.pastePNG.isChecked()
newScale = self.form.uiScale.value()/100
if newScale != self.mw.pm.uiScale():
self.mw.pm.setUiScale(newScale)
showInfo(_("Changes will take effect when you restart Anki."))

View file

@ -465,3 +465,12 @@ please see:
self.setGlMode("software")
elif mode == "angle":
self.setGlMode("software")
# Scale
######################################################################
def uiScale(self) -> float:
return self.meta.get("uiScale", 1.0)
def setUiScale(self, scale: float) -> None:
self.meta["uiScale"] = scale

View file

@ -137,34 +137,35 @@
<property name="spacing">
<number>12</number>
</property>
<item row="0" column="0">
<item row="3" column="1">
<widget class="QSpinBox" name="timeLimit">
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_40">
<property name="text">
<string>hours past midnight</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="label_39">
<property name="text">
<string>mins</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_23">
<property name="text">
<string>Next day starts at</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="dayOffset">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="maximum">
<number>23</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_24">
<property name="text">
<string>Learn ahead limit</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QSpinBox" name="lrnCutoff">
<property name="maximumSize">
<size>
@ -177,38 +178,60 @@
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_29">
<item row="2" column="0">
<widget class="QLabel" name="label_24">
<property name="text">
<string>mins</string>
<string>Learn ahead limit</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="1" column="1">
<widget class="QSpinBox" name="dayOffset">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="maximum">
<number>23</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_30">
<property name="text">
<string>Timebox time limit</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="timeLimit">
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_39">
<widget class="QLabel" name="label_29">
<property name="text">
<string>mins</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_40">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>hours past midnight</string>
<string>User interface size</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="uiScale">
<property name="suffix">
<string>%</string>
</property>
<property name="minimum">
<number>50</number>
</property>
<property name="maximum">
<number>200</number>
</property>
<property name="singleStep">
<number>5</number>
</property>
</widget>
</item>
@ -490,6 +513,7 @@
<tabstop>newSched</tabstop>
<tabstop>useCurrent</tabstop>
<tabstop>newSpread</tabstop>
<tabstop>uiScale</tabstop>
<tabstop>dayOffset</tabstop>
<tabstop>lrnCutoff</tabstop>
<tabstop>timeLimit</tabstop>