Skip to content

Draft: Interactivity and basic variable use within scripts

Adrian Knagg-Baugh requested to merge newcommands into master

Description

This MR provides basic interactivity (the ability to ask a user for values to use in scripts), basic control of variables (16 int, 16 float and 16 string variables are allowed, they can be set using setvar (and setvar can handle tinyexpr expressions, so basic manipulation of variable values can be done), also a few additional commands to extend Siril script capabilities.

This is intended as a technical preview to see if this is something we want. In the longer term the aim is to add proper scripting functionality using a proper language such as python or lua, but this addition is small and self-contained and provides greater flexibility for the current scripting capability, especially for scripts that run in GUI mode where it might be desired to allow the user to enter a few values. Also, being more basic, it may be more accessible for users who only want to add a little bit of customisability without learning an entire scripting language. So far it's only 1 day's work, and I don't think there's much more to do to get it into the state I think would be good for 1.4, but equally if everyone thinks it's an awful idea then it's not a huge loss of time.

Changes Made

A few special variables are provided (currently only %%wd%% for the working directory and %%filename%% for the current filename, but I was thinking of adding some stats ones (min, max, median, noise, stdev).

The functionality is only available within scripts, only after the script has encountered the variables command, and only for the duration of the script. The user interactivity aspect of setvar is only available in GUI mode. No changes are made to any other commands, so all existing scripts are unaffected and there is no change to the expectation that individual image processing commands are stateless - this forms a small stateful layer on top of the existing commands, so {setvar plus the variable replacement code} could be considered more as a meta-command than a normal command like the others.

This also adds a couple of extra functions that could be used to write script interfaces to arbitrary external programs - exe and mkdir. For example with exe you could launch gimp to do some image operation, e.g.

savetif32 %%filename%%
exe /usr/bin/gimp -i -b "(simple-unsharp-mask '%%filename%%.tif' 5.0 0.5 0)" -b "(gimp-quit 0)"
load %%filename%%.tif

would save the image as a 32bit tiff, open the file in gimp in batch mode, perform a simple unsharp mask, overwrite the image with the result and load it back into Siril. The functions could equally support basic interfaces to Cosmic Clarity or any other interesting software that may emerge during the 1.4 cycle.

Related Issues

#515 (script parameters) - this would resolve #515 completely. #1307 (creating custom tools) - a step towards resolving this, although the long term solution is still a proper scripting language.

Additional Notes

Include any extra information or considerations for reviewers, such as impacted areas of the codebase.

Merge Request Checklists

  • Code does not follow project coding guidelines and its checklist It doesn't follow the guidelines because of introducing statefulness in the command processor, but this is a straw man to see whether the guidelines can benefit from adjusting.
  • I have submitted a MR in the documentation repository if required
  • I have updated Changelog and NEWS, listing the related issues.
Edited by Adrian Knagg-Baugh

Merge request reports

Loading