Commit graph

177 commits

Author SHA1 Message Date
Jehan
7dc8fefbfd app, libgimp, pdb, plug-ins: new gimp_resources_loaded() function.
And use the function in script-fu. While we want wrong resource names to
trigger WARNINGs in Script-Fu scripts and plug-ins (because these can be
considered as a bug), we don't want it to happen when the resource is
not loaded on purpose (mostly it means that we run GIMP with --no-data
or --no-fonts). This was happening in our own builds when running GIMP
through the in-build-gimp.py script and that was always very annoying.

Now in such a case, we will only output an INFO message on stderr (it's
still a good idea to warn about this, because if we imagined someone was
running a script non-interactively, which called one of these
procedures, they may have relied on the default value of some arguments.
Therefore they'd want to know about such a behavior change).
2026-04-06 16:29:40 +02:00
Bruno Lopes
f14f9516e2 plug-ins: Fix some problematic Windows functions
The macro should be enough but
on these source files it does not work.
2026-03-31 21:44:51 -03:00
Bruno Lopes
dae02feed3 plug-ins: Use Glib date-time functions 2026-03-31 21:44:51 -03:00
Bruno Lopes
4643f7898f plug-ins: More casting fixes 2026-03-31 21:44:51 -03:00
Bruno Lopes
a146c4ae56 plug-ins: Do not redefine math macros on MSVC 2026-03-30 22:32:01 -03:00
Bruno Lopes
77682518b9 app, plug-ins: Use strcpy_s on Windows to fix CRT_INSECURE_DEPRECATE warnings 2026-03-30 22:32:01 -03:00
Bruno Lopes
2066844166 app, lib*, plug-ins: Use sscanf_s on Windows to fix CRT_INSECURE_DEPRECATE warns 2026-03-30 22:31:57 -03:00
Bruno Lopes
b7d89728c4 app, libgimpthumb, plug-ins, tools: Fix POSIX namespace warnings on MSVC 2026-02-28 10:06:46 -03:00
Jehan
b602a63778 plug-ins: also introspect libgimpui enum values into Script-Fu.
Since libgimpui also use GIMP_ as prefix in C, we won't ever have name
clashing with libgimp, so I also remove this prefix in Script-Fu.

E.g. GIMP_ASPECT_SQUARE is ASPECT-SQUARE in Script-Fu.
2026-02-25 14:49:23 +01:00
lloyd konneker
ed6e9dd6bd Fix #13537: ScriptFu init gimp_ui and Gtk only in INTERACTIVE mode
The code was mistakenly calling gimp_ui_init to init gegl,
and then gtk_init was aborting in headless gimp-console.

Now require GimpPlugin class to init gegl/babl.
See next commit.

Call gimp_ui_init only when run mode INTERACTIVE.
2025-12-05 18:50:23 +01:00
Bruno Lopes
a5d574e6d4
plug-ins: Make script-fu build on MSVC 2025-11-29 20:23:18 -03:00
Alx Sa
705b0527b3 script-fu: Prevent crash when script object is NULL
When interacting with a layer/channel
widget in a plug-in GUI, a temporary
procedure is spawned. Script-fu plug-ins
run a check for translation whenever a new
procedure is run, but there's none available
for "temp-procedure-number-?" which is
spawned by the layer/channel pop-up.
This causes a crash because
script_fu_script_get_i18n () assumes the
script object it receives is always valid.

This patch adds a g_return_if_fail () call
to script_fu_script_get_i18n () to prevent
future crashes, and makes sure the script
object is not NULL after
script_fu_find_script () is called in
script_fu_get_i18n_for_proc () to prevent
the initial call for temporary procedures.
2025-11-04 19:35:13 +00:00
Lukas Oberhuber
06bcef3273 macos plugins: Improves dock icon flashing from #12150
This means additional icons don't stick around. However, this is the easy workaround to turning everything into a proper plugin with .plist files.
2025-09-20 00:10:06 +01:00
Jehan
46143342b4 plug-ins: fix "no previous declaration" warnings. 2025-07-12 20:34:22 +02:00
lloyd konneker
ea238e4e5a ScriptFu: fix #12837 i18n for independent scripts
See /scripts/test/test-i18n.scm,
which has tests and documents use cases.

Some incidental refactoring and editing of comments.
2025-06-09 13:50:12 +00:00
Alx Sa
1f1404dc93 script-fu: Respect no-validate flag in Script-fu
GIMP 3.0 enforces stricter parameter range checks
compared to GIMP 2.10. As a result, scripts that are the
right datatype but go outside the parameter range will
fail. In GimpProcedure, we have checks if a no-validate
flag is set to bypass these constraints.
This patch adds those checks to Script-fu so it also knows
to not check ranges if no-validate is set.
2025-06-07 05:22:48 +00:00
Jehan
51d69fa44b plug-ins: do not warn for invalid font names at startup.
While all other resources are supposed to be already loaded, this is not
the case of fonts which are loaded in a thread, and whose loading may
end after plug-ins are initialized. So ignore unknown font name as an
exception (because we can't know if it is really unknown or just not
loaded yet).

This fixes such WARNINGs:

> (script-fu:33006): scriptfu-WARNING **: 14:35:28.259: script_fu_add_resource_arg declared resource name is invalid Serif
2025-05-15 02:16:10 +02:00
Jehan
39d0925b86 plug-ins: in non-v3, return in fact (0) or (1), not just an integer.
Comparing with other functions returning boolean, this seems to be the
actual "standard" for these in Script-Fu v2.
2025-02-27 17:34:43 +01:00
Jehan
d7cfc441e0 Issue #12948: make (gimp-pdb-procedure-exists) Script-Fu v3 compliant.
In particular, in v3, we want to return #t or #f, not an integer.
2025-02-26 22:31:28 +01:00
Jehan
63e6065197 Issue #12948: only report progression for "extension-script-fu" scripts.
In particular, we want the new Script-Fu plug-in to be able to handle
their progress status themselves, which is possible with
(gimp-progress-set-text) except that it is far too quickly overriden
because each procedure call generates a new progress message.
2025-02-26 15:16:05 +01:00
Jehan
ad136c1ab9 plug-ins: more accurate error message when using named argument syntax for…
… internal procedures.

See #13003.
2025-02-26 14:12:25 +01:00
Jehan
1df9dc5751 Issue #12948: implement (gimp-pdb-procedure-exists) in Script-fu.
I hesitated to make (gimp-pdb-proc-exists) public but I don't think it's
a good idea as it would be redundant with gimp_pdb_procedure_exists() in
the C API.

Instead, just implement (gimp-pdb-procedure-exists) specifically for
Script-Fu, with a name mapped to the C function.
2025-02-25 23:04:00 +01:00
Jehan
6a5fe88e29 plug-ins: fix a forgotten debug test. 2025-02-25 22:40:43 +01:00
Jehan
ad0b02d2b7 app, libgimp, pdb, plug-ins: rename gimp_procedure_is_core() to…
… gimp_procedure_is_internal().

I realized we were already naming these "internal procedures" in the
Procedure Browser and this is in fact a better naming than "core
procedure".
2025-02-25 20:01:29 +01:00
Jehan
4a1dee4651 plug-ins: improve the progress notification for Script-Fu.
First of all, let's init with the main procedure label (stripped of
leading/traling spaces, of mnemonic underscore and of ellipsis) as
progress status for gimp_progress_init().

Then reuse this main label for all subsequent progress updates by the
same top procedure.

Finally "pulse" the progress at each update to make it more like
progression actually happens.

This is a first experiment to see if not having progress API in
Script-Fu is fine (#12948), by having better progression defaults.
2025-02-18 21:09:22 +01:00
Jehan
5861be8d2b plug-ins: support GimpUnit type in Script-Fu.
Since the move of GimpUnit from some weird int/enum mixed type into a
proper object type, this was not usable anymore in Script-Fu.

Functions like (gimp-text-layer-new) were therefore broken. It now works
again.
2025-02-17 22:21:24 +01:00
lloyd konneker
3ee7ca9d56 ScriptFu: delete extra copies of init.scm
Cleanup cruft, unused files.

script-fu/scripts/init/init.scm
is the only copy that GIMP uses.
It is more or less upstream TinyScheme init.scm v1.42,
that K. Cozens occasionally patches with upstream changes.
But upstream has been at 1.42 for several years.

/scripts/script-fu.init is an unused copy of upstream TinyScheme init.scm v1.40
It should have been deleted on the earlier commit
that moved the file in the repo to /scripts/init/init.scm
and the installed init files to /scripts/scriptfu-init.

/tinyscheme/init.scm is an unused copy of upstream TinySche init.scm 1.41
Deleting it means that the tinyscheme dir can no longer be built by itself
into TinyScheme standalone binary, but we don't support that anyway.
2025-02-05 18:49:40 +00:00
Jacob Boerema
af5fc77a24 script-fu: fix crash when incorrectly using named parameters
The array of strings representing the Scheme types wasn't updated
after adding named parameters. This caused a crash when trying to
use named parameters where that isn't possible.
2025-02-05 13:33:46 -05:00
Jehan
10808f2830 libgimp, plug-ins: create automatically a GimpFileChooser for GimpParamSpecFile arguments.
This new widget is much nicer, with proper label to document the GUI and
also with support to save files or create folders. It also has mnemonic
support and the label is put into the same size group as other so that
it's nicely aligned.

As a consequence, I remove bad support of object arguments with a GFile
value. People should just create proper GimpParamSpecFile arguments
(also GimpProcedure API now has a function only for such type of file
argument).

I also remove gimp_procedure_dialog_get_file_chooser() which was only
useful when we didn't know what action a file argument was for. Now it's
part of the param spec definition.

libscriptfu was updated too because SF-DIRNAME arguments don't need
special casing anymore.

Finally I change gradients-save-as-css to just make use of the new
automatic widget creation (more than 60 lines of plug-in code replaced
by… 0 lines because it's automatic!).

This whole commit is mostly a lot of code removal now that we have
proper automatization for file arguments! \o/
2025-01-26 18:13:55 +01:00
Jehan
161b3c5331 Issue #12045: no defaults for plugin args of type File.
libgimpbase:

  - Mew GimpFileChooserAction enum type: basically a near-mapping of
    GtkFileChooserAction (GTK is not accessible from libgimpbase) with
    an added GIMP_FILE_CHOOSER_ACTION_ANY.
  - New GimpParamSpecFile param spec type: based off
    GimpParamSpecObject, it has a default value, but also a none_ok and
    action argument. This way, we can also know from the argument type
    if this is a file argument meant for selecting a normal file or a
    folder, or for saving into a file, or for creating a directory.

libgimp, plug-ins:

  - All existing file arguments (until now using a standard
    GParamSpecObject param with GFile value type) were moved to the new
    GimpParamSpecFile.
  - Script-Fu in particular will now generate the appropriate param type
    depending on whether it is an SF-FILENAME or SF-DIRNAME.
  - File arguments are now stored between runs as a URI rather than as a
    path. As far as I can tell, a GFile always has a URI, but not always
    a path (in particular remote file won't have a path).
2025-01-22 17:53:21 +01:00
Jehan
f17a42be75 plug-ins: add type check for the argument names in filter configuration too.
After the few specific args (drawable/filter ID, opacity, blend mode, op
name…), the op argument names can be passed either as string or with the
new argument name syntax. The error message though focus on argument
name type.

Also fix the argument count for the various possible cases (when
configuring with (gimp-drawable-filter-configure) or
(gimp-drawable-merge|append-new-filter), the start arg count is
different).
2025-01-20 15:28:15 +01:00
Jehan
f92f7d425c plug-ins: new named argument syntax in Script-Fu.
This syntax is now the official syntax for non-core PDB procedures.

I.e. that while core procedures will still use ordered arguments (e.g.:
`(gimp-image-get-layers 1)`), plug-in PDB procedures called from
Script-Fu will have named arguments in any order.

Say for instance that you want to call python-fu-foggify from Script-Fu.
Whereas we used to run:

> (python-fu-foggify RUN-NONINTERACTIVE 1 (car (gimp-image-get-layers 1)) "Clouds" '(50 4 4) 1.0 50.0)

Now we should call:

> (python-fu-foggify #:image 1 #:drawables (car (gimp-image-get-layers 1)) #:opacity 50.0 #:color '(50 4 4))

Now we can note:

* Every argument is preceded by a #:label which is the argument name.
  This makes these calls much more readable (some plug-in procedures can
  have dozen of arguments and these end up as list of integers, floats
  and strings, which are hard to read and hard to debug) and semantic.
* Order doesn't matter anymore. For instance here, I put #:opacity
  before #:color.
* As a direct consequence, we can drop any argument which we wish to
  keep with default value. E.g. in the old style, we had to put the
  #:run-mode, #:name ("Clouds") and #:turbulence (1.0) because we were
  changing the last argument #:opacity (50.0). Now we can drop all 3
  default arguments.

Having non-ordered argument is in fact the starter of this feature,
because it is already the case for calling PDB procedures in the libgimp
API (and therefore in all GIR bindings). By saying that the order of PDB
procedures is not part of the API, we actually allow to add arguments
and even to reorder them in the future without breaking existing scripts
in the 3.0 series.

This became even more serious when I was considering to make the generic
metadata arguments public. Since they are appended to the end, after all
plug-in-specific arguments, if I do this, adding any argument in an
export plug-in would break order. It won't matter anymore!

Note that it doesn't matter for core PDB procedures (where this syntax
is not used) because these are also C functions and therefore order and
number of arguments matter anyway. Also these don't have dozens of
arguments.

As a helper for Script-Fu developer, in particular as we already
released 2 RCs and therefore some people already started to port their
scripts, the old syntax will still work yet will produce a warning
showing how to call the same thing with the new syntax. For instance,
with the above first call, the warning will be:

> (script-fu:2059912): scriptfu-WARNING **: 22:54:47.507: Calling Plug-In PDB procedures with arguments as an ordered list is deprecated.
> Please use named arguments: (python-fu-foggify #:run-mode 1 #:image 1 #:drawables (2) #:name "Clouds" #:color '(50 4 4) #:turbulence 1.000000 #:opacity 50.000000)

Note that the argument name syntax is coming from the Racket scheme
variant: https://docs.racket-lang.org/arguments/index.html

Common Lisp has a similar syntax, either with just a colon, or also a
sharp + colon (it's unclear to me the difference, something about
interned vs. uninterned symbols).
After discussion with Liam on IRC, we decided to go with the #: syntax
of Racket.
2025-01-20 00:01:23 +01:00
Jehan
4448b1054a plug-ins: remove GIMP_PARAM_NO_VALIDATE for resource arguments.
We validate arguments for a reason. This special flag must only be used
in special cases (when it's harder/not possible or not implemented yet
to validate properly).

In fact #12039 would have been much simpler to diagnose and debug if
this flag had not been there from the start, because we would have had
an error earlier, on core side, which we could have traced back much
more simply!
2025-01-14 00:49:33 +01:00
lloyd konneker
b14b17fa53 ScriptFu: fix relay error when marshalling args
Broken in previous commit to this file.
An error return from script_fu_marshal_arg_to_value must be relayed.
2025-01-09 16:43:48 -05:00
lloyd konneker
caf007b22c ScriptFu: fix #12696 improper reffing of object proxies
For old-style scripts calling script-fu-register.

Test case Demo>Clothify v2
2025-01-08 08:11:59 -05:00
Daniele Forsi
994137a82e Fix spelling errors found with codespell 2025-01-04 15:11:03 +00:00
Jehan
c663c8cd2d plug-ins: Script-fu (gimp-drawable-filter-set-aux-input) procedure.
This is a wrapper to the C function of the same name. It is now possible
to merge filters with auxiliary input pads!
2024-12-17 16:24:54 +00:00
Jehan
a6392ed84a app, libgimp, pdb, plug-ins: add a few Script-fu wrapper of libgimp filter API.
In particular (gimp-drawable-filter-configure),
(gimp-drawable-merge-filter) and (gimp-drawable-append-filter) are
proper Script-fu methods.

I had to rename the PDB procedures for the 2 latter because they were
clashing with these wrapper. I had not realized that private PDB
procedures are still visible by Script-fu. This is not so glop. :-/

Right now, it doesn't look so useful compared to the -new- one-liner
variant procedures. But it will make sense when I will add aux input C
procedure wrappers.
2024-12-17 16:24:54 +00:00
Jehan
e5134e67aa libgimp*, plug-ins: filter ID are now usable in script-fu.
Marshalled PDB procedures into script-fu can now convert a filter ID
into the proper object. For instance, here would be the code to append a
new gaussian blur filter to the drawable with ID 2 (with specific
settings), then making invisible:

```script-fu
(define filter (gimp-drawable-append-new-filter 2 "gegl:gaussian-blur" "hello" LAYER-MODE-COLOR-ERASE 1.0 "std-dev-x" 20 "abyss-policy" "none"))
(gimp-drawable-filter-set-visible filter FALSE)
(gimp-drawable-update 2 0 0 -1 -1)
```
2024-12-17 16:24:54 +00:00
Jehan
39df978c2c plug-ins: implement (gimp-drawable-append-new-filter) script-fu procedure. 2024-12-17 16:24:54 +00:00
Jehan
dc91fe6ccd plug-ins: implement gimp-drawable-merge-new-filter for script-fu.
I moved the code to transform scheme values into GValues depending on a
GParamSpec out of script_fu_marshal_procedure_call() into a shared
function script_fu_marshal_arg_to_value().
2024-12-17 16:24:54 +00:00
lloyd konneker
e56f2b1c54 ScriptFu: show and hide Dock icon for extension-script-fu
Makes the Dock icon only appear when a script plugin has a dialog.
Unfortunately, on MacOS where "transient for" doesn't work,
we need a Dock icon for the separate process so user can "Show window."
See #12150

Done at runtime.
A build-time alternative is: package script-fu binary in a bundle, and set properties.

Fixes both the new-style dialog (GimpProcedureDialog) and the old-style dialog (deprecated.)
2024-12-17 15:18:50 +00:00
lloyd konneker
078e283f4b ScriptFu: fix #12150, activate apps (extension-script-fu and gimp) properly on MacOS
The gimp app and extension-script-fu (long-running)
are separate processes and "apps."
An app can be "active": in front and receiving GUI events.

As reported, on MacOS, when an extension-script-fu plugin yields,
the gimp app did not become active.
Also, on the second invocation of a plugin served by extension-script-fu,
the dialog could be hidden or require an extra click
because extension-script-fu was not active.
(Independently interpreted plugins did become active,
because it was a new process and gimpui_init activates on MacOS.)

On MacOS:
1. after the first dialog shown by extension-script-fu,
ensure subsequent calls to plugin make extension-script-fu active.
2. After a plugin yields, plugin manager ensure the Gimp app is active.

Note that this is done whenever a TEMPORARY procedure returns.
Most are calls to extension-script-fu plugins.
But some are also callbacks from Resource choosers running in the gimp app.
When they return, the gimp app remains active, and user must first click in
the plugin dialog to continue working.
Especially when the user clicks OK in a Resource Chooser, closing the chooser,
it would be nice if the plugin dialog became active.
That requires more, FUTURE development.

Special to MacOS: on Linux, "transient for foreign window" ensures this,
but that doesn't work on MacOS.

The fix is somewhat brute force and as simple as possible.
There is a more cooperative API for app activation on MacOS.
An app yields, and apps request, not force, self or other app be activated.
The fix does not use the cooperative API.
To do so would require a platform abstraction layer, in GIMP or Gtk.

The fix also sprinkles the code with #ifdefs.
That could be hidden if there were a platform abstraction layer PAL
The layer would be the greatest common denominator across platforms.
PAL methods would always be called in GIMP code,
but not do anything when the effect was accomplished another way.
For example "gimp_platform_request_app_active"
would request the app was active,
but do nothing on Linux where that is ensured by "transient for."
2024-12-17 15:18:50 +00:00
lloyd konneker
500ef62cc4 ScriptFu: change warning to info for lenient wrong arg count to PDB
It is like a compiler warning, and should not be a full g_warning,
which should mean something will probably fail.
Passing fewer args is a feature since 3.0: the PDB will use defaults.
2024-12-15 14:04:16 +00:00
lloyd konneker
059a6990e9 ScriptFu: cleanup some debug statements
Condense a few, eliminate a few.

Turn off the debugging of args in a Config.
2024-12-15 14:04:16 +00:00
lloyd konneker
9d444038a5 ScriptFu: fix #10741 tooltip and PDB description have underscore
Elide the underscore char from the blurb of the GParamSpec.
The tooltip remains redundant with the menu label.
We can't use an empty string (omit the tooltip)
because the blurb is also the description in the PDB Browser,
and the generated name of the arg is not descriptive.

FUTURE: let script author also declare a tooltip,
and a non-generated but unique name of the arg.
2024-11-20 12:48:10 +00:00
lloyd konneker
da5dc1e303 ScriptFu: Fix #9286 gimp-image-reorder-fails
Make ScriptFu not check for invalid item ID, instead marshall to NULL
since gimp-image-reorder-item has a nullable arg.
2024-11-19 09:21:09 -05:00
Jehan
dc3e815ff0 app, libgimp*, pdb, plug-ins: rename various public API name s/float/double/.
Several types functions were using the wording "float" historically to
mean double-precision, e.g. the float array type (which was in fact a
double array). Or the scanner function gimp_scanner_parse_float() was in
fact returning a double value. What if we wanted someday to actually add
float (usually this naming means in C the single-precision IEEE 754
floating point representation) support? How would we name this?

Now technically it's not entirely wrong (a double is still a floating
point). So I've been wondering if that is because maybe we never planned
to have float and double precision may be good enough for all usage in a
plug-in API (which doesn't have to be as generic so the higher precision
is enough)? But how can we be sure? Also we already had some functions
using the wording double (e.g. gimp_procedure_add_double_argument()), so
let's just go the safe route and use the accurate wording.

The additional change in PDB is internal, but there too, I was also
finding very confusing that we were naming double-precision float as
'float' type. So I took the opportunity to update this. It doesn't
change any signature.

In fact the whole commit doesn't change any type or code logic, only
naming, except for one bug fix in the middle which I encountered while
renaming: in gimp_scanner_parse_deprecated_color(), I discovered a
hidden bug in scanning (color-hsv*) values, which was mistakenly using a
double type for an array of float.
2024-11-02 15:00:03 +01:00
Jehan
8900967a81 extensions, libgimp, plug-ins: remove n_drawables arg from GimpImageProcedure's…
… run() function.

This is more consistent with recent changes in PDB, and now the
drawables argument is NULL-terminated.
2024-10-28 22:08:45 +01:00
Jehan
92ae145e0d plug-ins: warning cleanup.
Fixing:

> plug-ins/script-fu/libscriptfu/tinyscheme/scheme.c:134:1: warning: no previous declaration for ‘set_outport’ [-Wmissing-declarations]
2024-10-27 23:44:50 +01:00