Detected Dark / Light / System mode

“wx.SystemSettings.GetAppearance()” no longer seems to work with “wxpython-4.3.0a16030 and wxWidgets 3.3.0”.

I know this isn’t a final version, but is this normal?
01__wx.SystemAppearance.py (1.8 KB)
02__dark_mode.py (4.2 KB)

If anyone would like to test these scripts on their system and let me know if they work, I would be very grateful (please provide me with the following information: wxPython, wxWidgets, operating system version, etc.).

Also, like many other users, I would like to see an example of using dark mode as soon as possible to begin various tests.

Thanks

Not an answer to the question but:

__IS_DARK_THEME:bool=None   # hash calculation, requires client restart for dark/ligth theme change

def is_probably_dark_theme():
    global __IS_DARK_THEME
    if __IS_DARK_THEME is not None:
        return __IS_DARK_THEME

    bg_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW)
    # detect if light/dark color
    brightness = (bg_colour.Red() * 299 + bg_colour.Green() * 587 + bg_colour.Blue() * 114) / 1000
    __IS_DARK_THEME = (brightness < 128)        # dark background/theme ?
    _log.debug('wx.SYS_COLOUR_WINDOW brightness: %s', brightness)
    _log.debug('considered dark theme: %s (brightness < 128)', __IS_DARK_THEME)
    return __IS_DARK_THEME

might come in handy.

Karsten

#1 works correctly on Fedora 43 (Linux) but #2 does not.

I think for #2 you would want (maybe this is a newer way?):
gsettings get org.gnome.desktop.interface color-scheme

@Zig_Zag you may want to read the wxWidgets documentation for now until wxPython documentation is updated. Note the MSW specifics there about IsDark().

https://docs.wxwidgets.org/latest/classwx_system_appearance.html

Karsten / swt2c,
Thank you for this information.

test__dark_mode.py (5.4 KB)

After consulting the wxWidgets documentation and making a modification for Linux, I tried to enable dark mode on Windows with “w**xpython-4.3.0a16030”, unfortunately without success.

Does darkdetect (Client Challenge) help?

Preferably, I don’t want to use any external packages. As for the best practice for enabling dark mode on Windows, I’ll simply wait until everything is finalized and, if possible, for a concrete example of its use with wxPython. Sorry if I’m being impatient :slight_smile:

Preferably, I don’t want to use any external packages

Do you mean “I don’t want to use any external packages except for the very large and complex external package called wxPython which is the focus of this discussion forum”?

darkdetect is pure python with minimal external dependencies (None on Window/Linux, 1 optional one on Mac), and is independent of the GUI toolkit.

My suggestion here is that wxPython add it as a dependency and use it, or (worse) simply borrow the code (BSD licensed).

As for the best practice for enabling dark mode on Windows, I’ll simply wait until everything is finalized and, if possible, for a concrete example of its use with wxPython.

Over at wxutils (GitHub - newville/wxutils: wxPython utilities and convenience functions · GitHub) (yes, an external package, so you may not be interested), I recently added darkdetect as a dependency and use it to set many colors by “logical name” (‘text’, ‘text_bg’, etc) that will have different values in Light and Dark mode. It also uses darkdetect 'listener" to run a daemon thread to run registered callbacks when the System mode changes. That means the widgets not only get usable colors when an App starts, but they change when the System mode changes. These changes are fairly new, and there may be a some issues, but the results are readable and don’t give dark text on a dark background or light text on a light background. That may be of interest to some readers here.

This is now used in the latest version of wxmplot (again, an external package and with its own external dependencies including matplotlib which you would probably not want to use, but that others might find useful), and in several downstream applications that I support. Some of these have somewhat complex GUI components and context-sensitive text colors, say using validators to color-code invalid values or warning levels. These are working well at both respecting the System mode at startup and adapting when that mode changes.

Those might count as concrete examples.