Programmatically change darktable gui theme?

Hello. I have been trying to figure out if there is any way to programmatically change the darktable theme. Obligatory, I know the default theme is middle grey for a reason, I use it the vast majority of the time. I made a script to change my system theme when I am in a dark environment, and my end goal is to hook darktable into that as well. My “dark environment” darktable theme is only slightly darker then the default. Currently, I only have so much control over my editing environment, and unfortunately I cannot control the sun.

All that said, my first hope was to use the darktables dbus interface, something like:

dbus-send --type=method_call --dest=org.darktable.service /darktable org.darktable.service.Remote.Lua string:"local dt = require('darktable') dt.preferences.write('gtk', 'theme', 'string', 'darktable-slightly-darker')" 

But as the documentation for dt.preferences notes:

Lua has its own namespace for preferences and you can’t write normal darktable preferences.

As far as I understand, this will not set the correct key in darktablerc. Even if it did, I think this would require a restart to take effect, which I want to avoid.

My next idea was using dt.gui.action, but with further reading I concluded it’s not possible to set preferences this way.

Running out of ideas I grepped through darktables source code and see dt_gui_load_theme(theme) quite a bit, I am not a programmer, I do not know c, but I do wonder if there is a method to call said function via lua?

In summary, if any of you have ideas on how to programmatically change darktables gui theme (during runtime, no restart) I would very much appreciate your thoughts!

Thanks for your time.

Just make the necessary changes in the css… add them in the preferences section and then enable or disable them…no restart required and likely you can automate that action ie the css edits applied or not…

Like a more elegant way but this is quick and easy

1 Like

That’s not a bad idea. But I would think if there is a way to automate save CSS and apply, then there is probably a way to automate just setting and applying a theme. With your approach I could echo foobar > user.css or mv day/night.css user.css, the hard part is an action to save CSS and apply.

I’m going to read the documenation and source code more, very possible I have skimmed past what I am looking for.

1 Like

Yes

dt.gui.action won’t control themes

Not at the present time, but we might be able to add it to the API

1 Like

Much appreciate the clarification.

If possible, that would be great. I really wish I knew c well enough to implement it myself.

I think there are two relevant functions in preferences.c, reload_ui_last_theme() and theme_callback(). In gtk.c there is dt_gui_theme_init() and dt_gui_load_theme()