Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS Dark theme compatibility #1374

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions activity_browser/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ def get_default_project_name() -> Optional[str]:
else:
return None

@property
def theme(self) -> str:
"""Returns the current brightway directory"""
return self.settings.get("theme", "Light theme")

@theme.setter
def theme(self, new_theme: str) -> None:
self.settings.update({"theme": new_theme})


class ProjectSettings(BaseSettings):
"""
Expand Down
40 changes: 24 additions & 16 deletions activity_browser/ui/style.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from PySide2 import QtGui, QtWidgets
from activity_browser import ab_settings

default_font = QtGui.QFont("Arial", 8)

Expand Down Expand Up @@ -68,22 +69,29 @@ class ActivitiesPanel:


class TableItemStyle:
COLOR_CODE = {
"default": (0, 0, 0), # black
# 'product': (0, 132, 130),
"product": (0, 0, 0),
# 'reference product': (0, 132, 130),
"reference product": (0, 0, 0),
"name": (0, 2, 140),
"activity": (0, 72, 216),
"amount": (0, 0, 0),
# 'unit': (51, 153, 255),
"unit": (0, 0, 0),
"location": (72, 0, 140),
"database": (96, 96, 96),
"categories": (0, 0, 0),
"key": (96, 96, 96),
}
if ab_settings.theme == "Dark theme compatibility":
COLOR_CODE = {
"default": (255, 255, 255), # white
"name": (85, 170, 255),
"activity": (85, 170, 255),
"location": (255, 85, 255),
"database": (200, 200, 200),
"key": (200, 200, 200),
}
else: # light theme default
COLOR_CODE = {
"default": (0, 0, 0), # black
"product": (0, 0, 0),
"reference product": (0, 0, 0),
"name": (0, 2, 140),
"activity": (0, 72, 216),
"amount": (0, 0, 0),
"unit": (0, 0, 0),
"location": (72, 0, 140),
"database": (96, 96, 96),
"categories": (0, 0, 0),
"key": (96, 96, 96),
}

def __init__(self):
self.brushes = {}
Expand Down
38 changes: 31 additions & 7 deletions activity_browser/ui/wizards/settings_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from logging import getLogger

from dill import settings
from peewee import SqliteDatabase
from PySide2 import QtCore, QtWidgets

Expand Down Expand Up @@ -60,13 +61,7 @@ def __init__(self, parent=None):
self.wizard = parent
self.complete = False

self.startup_project_combobox = QtWidgets.QComboBox()
self.update_project_combo()

self.registerField(
"startup_project", self.startup_project_combobox, "currentText"
)

# bw dir
self.bwdir_variables = set()
self.bwdir = QtWidgets.QComboBox()

Expand All @@ -77,6 +72,25 @@ def __init__(self, parent=None):
self.bwdir_name = QtWidgets.QLineEdit(self.bwdir.currentText())
self.registerField("current_bw_dir", self.bwdir_name)

# startup project
self.startup_project_combobox = QtWidgets.QComboBox()
self.update_project_combo()

self.registerField(
"startup_project", self.startup_project_combobox, "currentText"
)

# light/dark theme
self.theme_combo = QtWidgets.QComboBox()
self.theme_combo.addItems([
"Light theme",
"Dark theme compatibility"
])
self.theme_combo.setCurrentText(ab_settings.theme)
self.registerField(
"theme_cbox", self.theme_combo, "currentText"
)

# Startup options
self.startup_groupbox = QtWidgets.QGroupBox("Startup Options")
self.startup_layout = QtWidgets.QGridLayout()
Expand All @@ -86,6 +100,9 @@ def __init__(self, parent=None):
self.startup_layout.addWidget(self.bwdir_remove_button, 0, 3)
self.startup_layout.addWidget(QtWidgets.QLabel("Startup Project: "), 1, 0)
self.startup_layout.addWidget(self.startup_project_combobox, 1, 1)
self.startup_layout.addWidget(QtWidgets.QLabel("Theme: "), 2, 0)
self.startup_layout.addWidget(self.theme_combo, 2, 1)
self.startup_layout.addWidget(QtWidgets.QLabel("(Requires restart)"), 2, 2)

self.startup_groupbox.setLayout(self.startup_layout)

Expand All @@ -102,6 +119,7 @@ def __init__(self, parent=None):
self.bwdir_browse_button.clicked.connect(self.bwdir_browse)
self.bwdir_remove_button.clicked.connect(self.bwdir_remove)
self.bwdir.currentTextChanged.connect(self.bwdir_change)
self.theme_combo.currentTextChanged.connect(self.theme_change)
self.restore_defaults_button.clicked.connect(self.restore_defaults)

def bw_projects(self, path: str):
Expand Down Expand Up @@ -156,6 +174,12 @@ def bwdir_change(self, path: str):
"""
self.change_bw_dir(path)

def theme_change(self, theme: str):
"""Change the theme."""
if ab_settings.theme != theme:
ab_settings.theme = theme
self.changed()

def bwdir_browse(self):
"""
Executes on emission of a signal from the browse button
Expand Down
Loading