I haven't seen this posted before, so here it is.
My initial tests using the gimp-context-get-<parameter>
functions to to set the Script-fu inputs looked good and very easy.Unfortunately
, the values were the active ones when GIMP started or when the scripts were refreshed. They did not reflect the current state.
So here is a revised process, and it is more work. But the default values will be the currently active ones.
Use null strings for the names in the user interface section:
SF-FONT "Font" ""
SF-BRUSH "Brush" '("" 100 10 0)
SF-PALETTE "Palette" ""
SF-PATTERN "Pattern" ""
SF-GRADIENT "Gradient" ""
In the body of the script, set the new values before you use them - but only if they have changed!
(if (> (string-length (car brush)) 0)
(begin ;user selected a brush
(gimp-context-set-brush (car brush))
(gimp-context-set-opacity (cadr brush))
(gimp-context-set-paint-mode (cadddr brush)) ;ignore the spacing - gives error
(if (> (string-length font) 0)
(gimp-context-set-font font) ;font changed, use it
(set! font (car (gimp-context-get-font))) ;get name of current font
(if (> (string-length palette) 0)
(gimp-context-set-palette palette) ;palette changed, make it the active palette
(if (> (string-length pattern) 0)
(gimp-context-set-pattern pattern) ;pattern changed, make it the active pattern
(if (> (string-length gradient) 0)
(gimp-context-set-gradient gradient) ;gradient changed, make it the active gradient
The variable names brush font palette pattern gradient
should be whatever you called those entries in the script declaration.
The font entry is a special case. All of the others are used through calls that use the currently active <whatever>. But the font name is needed for the text procedures so you need to set the variable to the currently active name if the input name is <null>.
Tested in GIMP 2.6.11
I hope this helps you.