rework icons, add support for dark / light theme
This commit is contained in:
@@ -1,18 +1,38 @@
|
||||
from PyQt6 import QtCore, QtGui
|
||||
# from src import MyLogger
|
||||
from omegaconf import OmegaConf
|
||||
import darkdetect
|
||||
|
||||
config = OmegaConf.load("config.yaml")
|
||||
config = OmegaConf.load(f"{config.icon_path}/icons.yaml")
|
||||
|
||||
path = config.icon_path
|
||||
dark = darkdetect.isDark()
|
||||
mode = "dark" if dark else "light"
|
||||
path = f"{path}/{mode}"
|
||||
|
||||
# log = MyLogger("Icon")
|
||||
class Icon:
|
||||
def __init__(self, icon_name, extension="svg"):
|
||||
def __init__(self, icon_type, widget=None):
|
||||
|
||||
self.icon = QtGui.QIcon()
|
||||
self.add_icon(icon_type)
|
||||
if widget is not None:
|
||||
widget.setIcon(self.icon)
|
||||
def add_icon(self, icon_type):
|
||||
icon = config[icon_type]
|
||||
print(icon)
|
||||
self.icon.addPixmap(
|
||||
QtGui.QPixmap(f"icons/{icon_name}.{extension}"),
|
||||
QtGui.QPixmap(f"{path}/{icon}"),
|
||||
QtGui.QIcon.Mode.Normal,
|
||||
QtGui.QIcon.State.Off,
|
||||
)
|
||||
|
||||
def set_icon(self, widget):
|
||||
widget.setIcon(self.icon)
|
||||
|
||||
@staticmethod
|
||||
def icondata(self):
|
||||
return self.icon
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("This is a module and can not be executed directly.")
|
||||
Reference in New Issue
Block a user