is Theme and OS detectable to python?

Hi

Yes, it’s possible… but not easy for my own experience.
I don’t know if the way I’ve implemented it is the best or not.
Maybe a simpler method exists, I don’t know, but it works.

In BuliCommander plugin, I need to load icon set according to theme (dark or light) and solution I found is to check current window background color defined by Qt.

Take a look on BCTheme class.
It detect if current theme is Dark or Light, and allow to return a dictionary of stylesheet according to current theme.

Concerning resources (icons), it’s more tricky.

You need to prepare resource files:

  1. Create SVG files for dark/black
  2. Use the QtDesigner to generate resource file (.qrc), one for Dark theme, on for Light theme (or build it manually if you prefer, QRC file is just an XML file)
  3. Convert the .qcc file to .rcc file (use Qt rcc command line tool)

So now, you have resource files, you need to load them…
The loadResources() method from the BCTheme does it.

Not yet implemented in my plugin, but I need to detect when the theme is changed to reload resource dynamically (currently, theme is properly applied only when plugin is initialised and if theme is modified in Krita, user have to restart Krita to have theme properly applied in plugin)
The signal void Window::themeChanged() might be helpfull for this.

For OS detection, I use sys.platform value, but I think there’s many other way to do it…

Grum999