checkpoint
This commit is contained in:
75
lib/utils.py
75
lib/utils.py
@@ -1,7 +1,9 @@
|
||||
"""Utility Functions."""
|
||||
from typing import NoReturn
|
||||
from typing import NoReturn, Self
|
||||
|
||||
from PyQt6.QtCore import QCoreApplication
|
||||
from PyQt6.QtCore import QCoreApplication, QDir, QStandardPaths, Qt
|
||||
from PyQt6.QtGui import QColor, QFont, QFontDatabase
|
||||
from PyQt6.QtNetwork import QNetworkAccessManager, QNetworkDiskCache
|
||||
from PyQt6.QtSql import QSqlQuery
|
||||
|
||||
translate = QCoreApplication.translate
|
||||
@@ -19,3 +21,72 @@ def query_error(query: QSqlQuery) -> NoReturn:
|
||||
)
|
||||
)
|
||||
raise Exception(translate("MainWindow", "SQL Error"))
|
||||
|
||||
class Resources:
|
||||
_instance = None
|
||||
nam = QNetworkAccessManager()
|
||||
headerFont: QFont
|
||||
labelFont: QFont
|
||||
boldFont: QFont
|
||||
textFont: QFont
|
||||
italicFont: QFont
|
||||
capsFont: QFont
|
||||
smallCapsFont: QFont
|
||||
phonicFont: QFont
|
||||
|
||||
baseColor: QColor
|
||||
linkColor: QColor
|
||||
subduedColor: QColor
|
||||
|
||||
def __new__(cls: type[Self]) -> Self:
|
||||
if cls._instance:
|
||||
return cls._instance
|
||||
cls._instance = super(Resources, cls).__new__(cls)
|
||||
return cls._instance
|
||||
|
||||
def __init__(self) -> None:
|
||||
super(Resources, self).__init__()
|
||||
#
|
||||
# Fonts
|
||||
#
|
||||
self.headerFont = QFontDatabase.font("OpenDyslexic", None, 10)
|
||||
self.headerFont.setPixelSize(48)
|
||||
self.labelFont = QFont(self.headerFont)
|
||||
self.labelFont.setPixelSize(30)
|
||||
self.boldFont = QFont(self.headerFont)
|
||||
self.boldFont.setPixelSize(20)
|
||||
self.textFont = QFont(self.boldFont)
|
||||
self.italicFont = QFont(self.boldFont)
|
||||
self.capsFont = QFont(self.boldFont)
|
||||
self.smallCapsFont = QFont(self.boldFont)
|
||||
|
||||
self.headerFont.setWeight(QFont.Weight.Bold)
|
||||
self.boldFont.setBold(True)
|
||||
self.italicFont.setItalic(True)
|
||||
self.capsFont.setCapitalization(QFont.Capitalization.AllUppercase)
|
||||
self.smallCapsFont.setCapitalization(QFont.Capitalization.SmallCaps)
|
||||
|
||||
self.phonicFont = QFontDatabase.font("Gentium", None, 10)
|
||||
self.phonicFont.setPixelSize(20)
|
||||
|
||||
#
|
||||
# colors
|
||||
#
|
||||
self.baseColor = QColor(Qt.GlobalColor.white)
|
||||
self.linkColor = QColor("#4a7d95")
|
||||
self.subduedColor = QColor(Qt.GlobalColor.gray)
|
||||
|
||||
#
|
||||
# Setup the Network Manager
|
||||
#
|
||||
cacheDir = QDir(
|
||||
QStandardPaths.writableLocation(
|
||||
QStandardPaths.StandardLocation.GenericCacheLocation
|
||||
)
|
||||
)
|
||||
cacheDir.mkdir("Troglodite")
|
||||
cacheDir = QDir(cacheDir.path() + QDir.separator() + "Troglodite")
|
||||
netCache = QNetworkDiskCache()
|
||||
netCache.setCacheDirectory(cacheDir.path())
|
||||
self.nam.setCache(netCache)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user