Skip to content

Commit

Permalink
Large refactor of UI Theme Management
Browse files Browse the repository at this point in the history
- ThemeName ENUM (with all theme names)
- ThemeManager Singleton
- Theme Base class (to reset theme)
- Theme classes for each unique UI theme: No Theme, Humanity, Humanity: Dark, and Cosmic Dusk (out new theme)
- Cosmic Dusk theme still needs lots of work
- Known Issue: When changing themes on the Preferences window, some widget styles do not refresh until the window is closed/re-opened
- Renaming some dock widgets in the *.ui file
- Updating translation system to support Theme names
- Apply video widget background from current palette and not a hard-coded color
  • Loading branch information
jonoomph committed Feb 12, 2024
1 parent 633d305 commit a62f223
Show file tree
Hide file tree
Showing 18 changed files with 673 additions and 235 deletions.
40 changes: 10 additions & 30 deletions src/classes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import json

from PyQt5.QtCore import PYQT_VERSION_STR, QT_VERSION_STR, pyqtSlot
from PyQt5.QtWidgets import QApplication, QStyleFactory, QMessageBox
from PyQt5.QtWidgets import QApplication, QMessageBox

# Disable sandbox support for QtWebEngine (required on some Linux distros
# for the QtWebEngineWidgets to be rendered, otherwise no timeline is visible).
Expand Down Expand Up @@ -148,6 +148,9 @@ def __init__(self, *args, **kwargs):
if self.mode == "unittest" or not self.settings.get('send_metrics'):
sentry.disable_tracing()

# Empty window
self.window = None

def show_environment(self, info, openshot):
log = self.log
try:
Expand Down Expand Up @@ -199,8 +202,7 @@ def gui(self):
Initialize GUI and main window.
:return: bool: True if the GUI has no errors, False if we fail to initialize the GUI
"""
from classes import language, sentry, ui_util, logger_libopenshot
from PyQt5.QtGui import QFont, QFontDatabase as QFD
from classes import language, sentry, logger_libopenshot

_ = self._tr
info = self.info
Expand All @@ -210,9 +212,6 @@ def gui(self):
language.init_language()
sentry.set_tag("locale", info.CURRENT_LANGUAGE)

# Load ui theme if not set by OS
ui_util.load_theme()

# Test for permission issues (and display message if needed)
try:
log.debug("Testing write access to user directory")
Expand Down Expand Up @@ -247,35 +246,16 @@ def gui(self):
# Track which dockable window received a context menu
self.context_menu_object = None

# Set Font for any theme
log.debug("Loading UI theme")
if self.settings.get("theme") != "No Theme":
# Load embedded font
font_path = os.path.join(info.IMAGES_PATH, "fonts", "Ubuntu-R.ttf")
if os.path.exists(font_path):
log.info("Setting font to %s", font_path)
try:
font_id = QFD.addApplicationFont(font_path)
font_family = QFD.applicationFontFamilies(font_id)[0]
font = QFont(font_family)
font.setPointSizeF(10.5)
QApplication.setFont(font)
except Exception:
log.warning("Error setting Ubuntu-R.ttf QFont", exc_info=1)

# Set Dark Theme, if selected
if self.settings.get("theme") == "Humanity: Dark":
log.info("Setting custom dark theme")
self.setStyle(QStyleFactory.create("Fusion"))
darkPalette = ui_util.make_dark_palette(self.palette())
self.setPalette(darkPalette)
self.setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 0px solid white; }")

# Create main window
from windows.main_window import MainWindow
log.debug("Creating main interface window")
self.window = MainWindow()

# Instantiate Theme Manager (Singleton)
from themes.manager import ThemeManager, ThemeName
theme_enum = ThemeName.find_by_name(self.settings.get("theme"))
ThemeManager(self).apply_theme(theme_enum)

# Check for gui launch failures
if self.mode == "quit":
self.window.close()
Expand Down
2 changes: 1 addition & 1 deletion src/classes/ui_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
DEFAULT_THEME_NAME = "Humanity"


def load_theme():
def load_icon_theme():
""" Load the current OS theme, or fallback to a default one """

s = get_app().get_settings()
Expand Down
Loading

0 comments on commit a62f223

Please sign in to comment.