Skip to content

Commit 9e6a1a7

Browse files
committed
FIx color mode handling following changes in guidata
1 parent 3effb65 commit 9e6a1a7

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

plotpy/config.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@
1717
import warnings
1818
from typing import Literal
1919

20-
from guidata import qthelpers
20+
from guidata import qthelpers as qth
2121
from guidata.configtools import add_image_module_path, get_translation
2222
from guidata.userconfig import UserConfig
2323

24-
IS_DARK = qthelpers.is_dark_mode()
25-
2624

2725
def get_main_colors() -> tuple[str, str]:
2826
"""Return main foreground and background colors depending on dark mode"""
29-
global IS_DARK
30-
return "white" if IS_DARK else "black", "#222222" if IS_DARK else "white"
27+
is_dark = qth.is_dark_theme()
28+
return "white" if is_dark else "black", "#222222" if is_dark else "white"
3129

3230

3331
MAIN_FG_COLOR, MAIN_BG_COLOR = get_main_colors()
@@ -45,7 +43,7 @@ def make_title(basename, count):
4543

4644
def get_plotpy_defaults() -> dict[str, int | float | str | bool]:
4745
"""Return default configuration values"""
48-
global IS_DARK, MAIN_FG_COLOR, MAIN_BG_COLOR
46+
global MAIN_FG_COLOR, MAIN_BG_COLOR
4947
return {
5048
"plot": {
5149
"selection/distance": 6,
@@ -101,7 +99,7 @@ def get_plotpy_defaults() -> dict[str, int | float | str | bool]:
10199
"grid/maj_line/style": "DotLine",
102100
"grid/min_xenabled": True,
103101
"grid/min_yenabled": True,
104-
"grid/min_line/color": "#454545" if IS_DARK else "#eaeaea",
102+
"grid/min_line/color": "#454545" if qth.is_dark_theme() else "#eaeaea",
105103
"grid/min_line/width": 1,
106104
"grid/min_line/style": "DotLine",
107105
"marker/curve/symbol/marker": "Rect",
@@ -304,7 +302,7 @@ def get_plotpy_defaults() -> dict[str, int | float | str | bool]:
304302
"shape/imagefilter/sel_symbol/edgecolor": "#0000ff",
305303
"shape/imagefilter/sel_symbol/facecolor": "#00ffff",
306304
"shape/imagefilter/sel_symbol/alpha": 0.8,
307-
# Contour ----------------------------------------------------------------------
305+
# Contour ------------------------------------------------------------------
308306
"shape/contour/line/style": "SolidLine",
309307
"shape/contour/line/color": "#000000",
310308
"shape/contour/line/width": 1,
@@ -317,7 +315,7 @@ def get_plotpy_defaults() -> dict[str, int | float | str | bool]:
317315
"shape/contour/sel_fill/color": MAIN_BG_COLOR,
318316
"shape/contour/sel_fill/alpha": 0.1,
319317
"shape/contour/sel_symbol/marker": "NoSymbol",
320-
# RectZoom ---------------------------------------------------------------------
318+
# RectZoom -----------------------------------------------------------------
321319
"shape/rectzoom/line/style": "SolidLine",
322320
"shape/rectzoom/line/color": "#bbbbbb",
323321
"shape/rectzoom/line/width": 2,
@@ -772,8 +770,7 @@ def get_plotpy_defaults() -> dict[str, int | float | str | bool]:
772770

773771
def update_plotpy_defaults() -> None:
774772
"""Update the defaults with the current configuration"""
775-
global DEFAULTS, IS_DARK, MAIN_BG_COLOR, MAIN_FG_COLOR
776-
IS_DARK = qthelpers.is_dark_mode()
773+
global DEFAULTS, MAIN_BG_COLOR, MAIN_FG_COLOR
777774
MAIN_FG_COLOR, MAIN_BG_COLOR = get_main_colors()
778775
DEFAULTS = get_plotpy_defaults()
779776
CONF.update_defaults(DEFAULTS)
@@ -808,7 +805,7 @@ def set_plotpy_dark_mode(state: bool) -> None:
808805
f"version. Use `set_plotpy_color_mode('{mode}')` instead.",
809806
DeprecationWarning,
810807
)
811-
qthelpers.set_dark_mode(state) # guidata 3.6.0
808+
qth.set_dark_mode(state) # guidata 3.6.0
812809
update_plotpy_color_mode()
813810

814811

@@ -819,5 +816,5 @@ def set_plotpy_color_mode(mode: Literal["light", "dark", "auto"] | None = None):
819816
mode: Color mode ('light', 'dark' or 'auto'). If 'auto', the system color mode
820817
is used. If None, the `QT_COLOR_MODE` environment variable is used.
821818
"""
822-
qthelpers.set_color_mode(mode) # guidata >= 3.6.1
819+
qth.set_color_mode(mode) # guidata >= 3.6.1
823820
update_plotpy_color_mode()

plotpy/panels/contrastadjustment.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import numpy as np
2323
from guidata.configtools import get_icon, get_image_layout
2424
from guidata.dataset import DataSet, FloatItem
25-
from guidata.qthelpers import add_actions, create_action
25+
from guidata.qthelpers import add_actions, create_action, is_dark_theme
2626
from guidata.utils.misc import assert_interfaces_valid
2727
from qtpy import QtCore as QC
2828
from qtpy import QtWidgets as QW
2929

30-
from plotpy.config import CONF, IS_DARK, _
30+
from plotpy.config import CONF, _
3131
from plotpy.constants import ID_CONTRAST, Y_LEFT, Y_RIGHT, PlotType
3232
from plotpy.interfaces import IPanel, IVoiImageItemType
3333
from plotpy.items import HistogramItem, XRangeSelection
@@ -448,7 +448,7 @@ def __init__(self, parent: QWidget | None = None) -> None:
448448
self.min_select_tool = None
449449
self.max_select_tool = None
450450

451-
color = "#444444" if not IS_DARK else "#bbbbbb"
451+
color = "#bbbbbb" if is_dark_theme() else "#444444"
452452
style = "<span style='color: %s'><b>{}</b></span>" % color
453453
layout, _label = get_image_layout(
454454
self.PANEL_ICON, style.format(self.PANEL_TITLE), alignment=QC.Qt.AlignLeft

0 commit comments

Comments
 (0)