From 0b93b02eac640ad66b80d446b4d310fb1e423f7d Mon Sep 17 00:00:00 2001 From: Peter Baintner Date: Tue, 23 Jul 2024 13:27:45 +0200 Subject: [PATCH] Added handling for light and dark themes set by system --- renderrob.py | 10 +++++++++- utils_rr/table_utils.py | 23 +++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/renderrob.py b/renderrob.py index b20f440..edf271d 100644 --- a/renderrob.py +++ b/renderrob.py @@ -46,6 +46,12 @@ def __init__(self) -> None: self.yellow_jobs = [] self.red_jobs = [] + # TODO: Avoid global state with theme colors. + if self.app.styleHints().colorScheme().value == 1: + table_utils.COLORS = table_utils.COLORS_LIGHT + elif self.app.styleHints().colorScheme().value == 2: + table_utils.COLORS = table_utils.COLORS_DARK + def setup(self) -> None: """Provide main function.""" self.app.setStyle("Breeze") @@ -58,6 +64,8 @@ def setup(self) -> None: self.window.setWindowIcon(QIcon("icons/icon.ico")) self.app.setWindowIcon(QIcon("icons/icon.ico")) self.table = self.window.tableWidget + self.table.setStyleSheet( + "QTableWidget {background-color: " + str(table_utils.COLORS["grey_light"]) + "}") self.refresh_recent_files_menu() self.window.progressBar.setValue(0) self.window.progressBar.setMinimum(0) @@ -323,7 +331,7 @@ def _handle_output(self): # Only scroll down if user is at bottom. if self.window.textBrowser.verticalScrollBar().value() > ( self.window.textBrowser.verticalScrollBar().maximum()) - 1500: - self.window.textBrowser.moveCursor(QTextCursor.End) + self.window.textBrowser.moveCursor(QTextCursor.End + 1) self.window.textBrowser.setCurrentCharFormat(color_format) self.window.textBrowser.insertPlainText(line.replace(reset, "") + "\n") diff --git a/utils_rr/table_utils.py b/utils_rr/table_utils.py index 41bc038..5b70599 100644 --- a/utils_rr/table_utils.py +++ b/utils_rr/table_utils.py @@ -6,7 +6,7 @@ QTableWidgetItem, QWidget) from utils_rr import ui_utils, path_utils -COLORS = { +COLORS_LIGHT = { "red": 0x980030, "yellow": 0xffd966, "green": 0x9fd3b6, @@ -15,13 +15,32 @@ "blue_grey": 0x4f7997, "blue_grey_darker": 0x345064, "grey_light": 0xebebeb, - "grey_inactive": 0xf8f8f8, + "grey_inactive": 0xfefefe, "grey_neutral": 0x999999, "black_light": 0x22282b, "black_dark": 0x242a2d, "white": 0xffffff, } +COLORS_DARK = { + "red": 0x980030, + "yellow": 0xffd966, + "green": 0x9fd3b6, + "blue": 0x57a3b4, + "blue_grey_lighter": 0x6397bd, + "blue_grey": 0x4f7997, + "blue_grey_darker": 0x345064, + "grey_light": 0x323639, + "grey_inactive": 0x2d2d2d, + "grey_neutral": 0x222222, + "black_light": 0x22282b, + "black_dark": 0x242a2d, + "white": 0x232323, +} +# NOTE: This variable is being set from renderrob.py since we only know there if a dark or a +# light theme is requested. +COLORS = {} + def fix_active_row_path(item: QTableWidgetItem, blend_folder: str) -> None: """Fix the path of the currently selected row."""