From c326cea91fbba5254ecd353935dacc3f42c54090 Mon Sep 17 00:00:00 2001 From: rafael Date: Fri, 6 Aug 2021 10:15:35 +0100 Subject: [PATCH] __main__: Implement basic darkmode provisions (#5526) * __main__: Add darkMode property to QApplication * __main__: Set pyqtgraph colors from QPalette * owpalette: Remove pyqtgraph colors set on global import * pylint --- Orange/canvas/__main__.py | 19 ++++++++++++++++++- Orange/widgets/utils/plot/owpalette.py | 2 -- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Orange/canvas/__main__.py b/Orange/canvas/__main__.py index f4c265918bc..809ebf5a1ba 100644 --- a/Orange/canvas/__main__.py +++ b/Orange/canvas/__main__.py @@ -337,7 +337,7 @@ def send_statistics(url): r = requests.post(url, files={'file': json.dumps(data)}) if r.status_code != 200: log.warning("Error communicating with server while attempting to send " - "usage statistics. Status code " + str(r.status_code)) + "usage statistics. Status code %d", r.status_code) return # success - wipe statistics file log.info("Usage statistics sent.") @@ -457,6 +457,20 @@ def main(argv=None): app.setPalette(breeze_dark()) defaultstylesheet = "darkorange.qss" + # set pyqtgraph colors + def onPaletteChange(): + p = app.palette() + bg = p.base().color().name() + fg = p.windowText().color().name() + + log.info('Setting pyqtgraph background to %s', bg) + pyqtgraph.setConfigOption('background', bg) + log.info('Setting pyqtgraph foreground to %s', fg) + pyqtgraph.setConfigOption('foreground', fg) + + app.paletteChanged.connect(onPaletteChange) + onPaletteChange() + palette = app.palette() if style is None and palette.color(QPalette.Window).value() < 127: log.info("Switching default stylesheet to darkorange") @@ -560,6 +574,9 @@ def onrequest(url): stylesheet_string = pattern.sub("", stylesheet_string) + if 'dark' in stylesheet: + app.setProperty('darkMode', True) + else: log.info("%r style sheet not found.", stylesheet) diff --git a/Orange/widgets/utils/plot/owpalette.py b/Orange/widgets/utils/plot/owpalette.py index 9c58c29947c..19112fa1570 100644 --- a/Orange/widgets/utils/plot/owpalette.py +++ b/Orange/widgets/utils/plot/owpalette.py @@ -5,8 +5,6 @@ __all__ = ["create_palette", "OWPalette"] -pg.setConfigOption('background', 'w') -pg.setConfigOption('foreground', 'k') pg.setConfigOptions(antialias=True)