Hello, I would like to write a Lua script that adds four sliders or number input fields to the crop module. The input fields will be labelled as “position x”, “position y”, “size x”, and “size y”. The goal of the script is to add the ability to crop by specifying exact pixel positions and sizes instead of margin percentages. How do I create and insert these custom input fields into the crop module? Thanks.
As far as I know, you can’t. Modules have two sets of parameters, one bound to UI controls like sliders and checkboxes, another is the actual processing parameters, which can be a 1:1 mapping or something more complex, but it’s all done in C, and the GUI framework does not call any Lua script when building the UI or when populating those parameters.
Also, why would you want pixel-precise cropping, to be set for every image?
I have a few crop presets that result in a crop of an exact (and repeatable) size, and I can then move the window around to taste. For me, the size is important, the location doesn’t have to be that exact. So presets work perfectly (for the raw image size they were made with).
Setting up such presets is a bit tedious, but I only had to do that once.
Lua can create it’s own modules, but it can’t modify existing modules.
And you can’t create processing modules in Lua, can you?
Darktable’s Lua API can’t add UI elements to the crop module? If it could, then it would be just a matter of using darktable.gui.action to change the values of the margins percentages in the crop module whenever there is a change in values of the custom UI elements.
Lua can create it’s own modules
Are you sure? I created DCTL support (or equivalent custom programmable modules) · Issue #19662 · darktable-org/darktable · GitHub to ask for programmable modules
Lua can create it’s own modules
There is an example here: lua-scripts/examples/moduleExample.lua at master · darktable-org/lua-scripts · GitHub
Described in the manual: darktable lua documentation - moduleExample
I don’t know how useful it is in your case.
You can create lighttable modules in Lua, and you can manipulate the UI in Lua (e.g. see the initial workflow script), but processing modules? I doubt that. Bill Ferguson is the Lua expert, so you can trust what he says.
You could create a lua module for the darkroom with its own entry fields or widgets and from that calculate the proper values for a processing module, e.g. crop, and set them via gui.action. Unfortunately, you will have to implement a button to actually set the values, because there is no suitable event available. See the demo script gui_action.lua for a simple example.
Not sure, if that would fulfill your needs.
That is asking for a ton of work, it’d seem.
You can use a shortcut and assign a keystroke sequence to it.
Not to mention support…
Sure. What I meant was that changing the value does not automatically trigger the script to write the value to the processing module, at least I am not aware of any way to achieve this.
If you use a slider, then you can have a callback that runs when the value changes and update the values in the crop module