From 1f8924aed8414263464d82f3f4567ed41e3228f4 Mon Sep 17 00:00:00 2001 From: Justin Donofrio Date: Fri, 20 Dec 2024 16:06:32 -0500 Subject: [PATCH] have colorpicker respect application theme --- src/onthespot/gui/mainui.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/onthespot/gui/mainui.py b/src/onthespot/gui/mainui.py index 8d214d5..45e00d3 100644 --- a/src/onthespot/gui/mainui.py +++ b/src/onthespot/gui/mainui.py @@ -140,22 +140,27 @@ def get_icon(self, name): def open_theme_dialog(self): - color = QColorDialog().getColor() + colorpicker = QColorDialog(self) + colorpicker.setStyleSheet(config.get('theme')) + colorpicker.setWindowTitle("OnTheSpot - Notice") - if color.isValid(): - r, g, b = color.red(), color.green(), color.blue() - luminance = (0.299 * r + 0.587 * g + 0.114 * b) + if colorpicker.exec() == QColorDialog.DialogCode.Accepted: + color = colorpicker.selectedColor() - if luminance < 128: - # Dark color, set light font - stylesheet = f'background-color: {color.name()}; color: white;' - else: - # Light color, set dark font - stylesheet = f'background-color: {color.name()}; color: black;' - config.set_('theme', stylesheet) - config.update() - self.centralwidget.setStyleSheet(stylesheet) - self.__splash_dialog.update_theme(stylesheet) + if color.isValid(): + r, g, b = color.red(), color.green(), color.blue() + luminance = (0.299 * r + 0.587 * g + 0.114 * b) + + if luminance < 128: + # Dark color, set light font + stylesheet = f'background-color: {color.name()}; color: white;' + else: + # Light color, set dark font + stylesheet = f'background-color: {color.name()}; color: black;' + config.set_('theme', stylesheet) + config.update() + self.centralwidget.setStyleSheet(stylesheet) + self.__splash_dialog.update_theme(stylesheet) def bind_button_inputs(self):