rework logging, add more dataclasses, reworked config
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from .blob import create_blob
|
||||
from .icon import Icon
|
||||
from .pickles import dump_pickle, load_pickle
|
||||
from .sortgenerator import app_sort, name_sort
|
||||
from .richtext import SemesterDocument
|
||||
@@ -2,28 +2,51 @@ import darkdetect
|
||||
from omegaconf import OmegaConf
|
||||
from PyQt6 import QtGui
|
||||
import re
|
||||
from src import settings
|
||||
|
||||
from config import Config
|
||||
|
||||
settings = Config("config/config.yaml")
|
||||
config = settings.icons
|
||||
|
||||
config = OmegaConf.load(f"{settings.icon_path}/icons.yaml")
|
||||
|
||||
path = config.icon_path
|
||||
path = config.path
|
||||
|
||||
|
||||
class Icon:
|
||||
def __init__(self, icon_type, widget=None,recolor=False):
|
||||
def __init__(self, icon_type, widget=None, recolor=True, color=None):
|
||||
"""Set an icon to a widget or window. Recolors the icon if needed
|
||||
|
||||
Args:
|
||||
icon_type (str): Name of the icon in the config file
|
||||
widget (Any, optional): Object the icon will be added to. Defaults to None.
|
||||
recolor (bool, optional): If Icon should be recolored. Defaults to True.
|
||||
color (str, optional): Color type to use. Configured in config file. Defaults to None.
|
||||
"""
|
||||
assert (
|
||||
icon_type in settings.icons.icons.keys()
|
||||
), f"Icon {icon_type} not in config file"
|
||||
assert (
|
||||
color in settings.icons.colors.keys() or color is None
|
||||
), f"Color {color} not in config file"
|
||||
icon = settings.icons.get(icon_type)
|
||||
dark = darkdetect.isDark()
|
||||
if dark:
|
||||
self.color = config.dark_color
|
||||
self.color = config.colors.dark
|
||||
else:
|
||||
self.color = config.light_color
|
||||
self.color = config.colors.light
|
||||
if color:
|
||||
self.color = config.colors[color]
|
||||
self.icon = QtGui.QIcon()
|
||||
self.icon_path = path + config["icons"][icon_type]
|
||||
self.add_icon(self.icon_path,recolor)
|
||||
self.icon_path = path + icon
|
||||
recolor = (
|
||||
False
|
||||
if icon_type.endswith(".ico") or icon_type.endswith(".png")
|
||||
else recolor
|
||||
)
|
||||
self.add_icon(self.icon_path, recolor)
|
||||
if widget is not None:
|
||||
widget.setIcon(self.icon)
|
||||
try:
|
||||
widget.setIcon(self.icon)
|
||||
except AttributeError:
|
||||
widget.setWindowIcon(self.icon)
|
||||
|
||||
def add_icon(self, icon_path,recolor=False):
|
||||
icon = self.changeColor(icon_path,recolor)
|
||||
@@ -38,7 +61,7 @@ class Icon:
|
||||
QtGui.QIcon.State.Off,
|
||||
)
|
||||
|
||||
def overwriteColor(self, color):
|
||||
def overwriteColor(self):
|
||||
# take the icon, read it as bytes and change the color in fill
|
||||
icon = self.changeColor(self.icon_path)
|
||||
cicon = str(icon)
|
||||
@@ -49,9 +72,9 @@ class Icon:
|
||||
|
||||
if fill and stroke:
|
||||
# replace stroke
|
||||
newicon = icon.replace(stroke.encode(), color.encode())
|
||||
newicon = icon.replace(stroke.encode(), config.color.encode())
|
||||
else:
|
||||
newicon = icon.replace(fill.encode(), color.encode())
|
||||
newicon = icon.replace(fill.encode(), config.color.encode())
|
||||
|
||||
pixmap = QtGui.QPixmap()
|
||||
pixmap.loadFromData(newicon)
|
||||
|
||||
Reference in New Issue
Block a user