Quoting Alan Campbell <gimp-u...@alancampbelllists.ukfsn.org>:

> Hi,
> I'm trying to figure ut if there's any way that choices made by a
> user in dialog widgets can be remembered and used as values of those
> widgets next time dialog runs.

That is precisely how script dialogs currently behave; the last used  
values are presented. These last values will be reset to their  
original default values if 1) Script-fu is refreshed  
("Filters->Script-fu->Refresh Scripts") or 2) GIMP is restarted.

> BUT: if loaded scm contains
>   (define WRF_BIT_WIDTH 17)
> and script-fu-register dialog def includes:
>   SF-ADJUSTMENT "bit width:"   '(WRF_BIT_WIDTH 0 256 0.1 1 1 1)
> the value of WRF_BIT_WIDTH loaeded from test.scm doesn't seem to
> take.

Tick quoting does not result in evaluation of the list elements. Use  
'list' so that WRF_BIT_WIDTH gets evaluated and replaced by its  
numeric value:

    SF-ADJUSTMENT "bit width:" (list WRF_BIT_WIDTH 0 256 0.1 1 1 1)

> Another approach I tried was to begin declaration of dialog
>    (script-fu-register  WRF_DIALOG_FUNCTION
>      (wrf_test_text)   ;menu label
> :
> :
> which also seemed to work; in principle I could write code for
> (wrf_test_text) that interrogated an ini file, retrieved values,
> constructed correct lists, initialised variables used in later
> parameters of script-fu-register.  Rather round-the-houses, but
> works.

Keep in mind that the arguments of 'script-fu-register' only get  
evaluated when the script is registered -- they are not (re-)evaluated  
when the script is executed. While your code works, you have not  
really gained anything other than moving the definitions to a  
different location within the .scm file.

> (b) But: to make this work I need to be able to determine if a file
> exists (error if try to load file that doesn't) and to be well-
> behaved, be able to specify a particular folder in which to look for
> ini files (same folder as running script?  GIMP install folder?  GIMP
> share\gimp\2.0\..?).  Any way to test for file existence or determine
> script folder/install folder in script-fu?

It is unclear to me what exactly you mean by "to make this work"  
because within a GIMP session, the values set in script dialogs are  
indeed retained and used the next time the script is executed.

If you are wishing to have the values derived at the time the script  
is run (i.e., calculated before the dialog is presented), this is not  
readily accomplished. For example, you can't have a size parameter  
default to the run-time width of the image being filtered -- the  
initial size default would be evaluated at registration time, and for  
subsequent executions the previous value entered by the user would be  

If, however, the issue you are attempting to address is having the  
last values retained across sessions (or survive a Script Refresh),  
this would be possible by storing your script's last values in the  
<gimpdir>/parasiterc file:

(define (script-fu-woodrat image drawable bit-width)
   ; Substitute function owing to buggy parasite-attach behavior
   (define (fu-parasite-attach parasite)
     (gimp-parasite-attach parasite)
     (while (not (string=? (caddr parasite)
                           (caddar (gimp-parasite-find (car parasite)))))
       (gimp-parasite-attach parasite)))

   ; Save the user-specified bit-width to an application parasite
   (fu-parasite-attach (list "WRF_BIT_WIDTH" 1 (number->string bit-width)))

(script-fu-register "script-fu-woodrat"
   SF-IMAGE ...
   SF-VALUE "Bit width"
                 17 ; fallback value if first-time run
                 (string->number (caddar (gimp-parasite-find "WRF_BIT_WIDTH")))

Note that 'gimp-parasite-find' is only executed once: when GIMP is  
initially loaded (or if scripts are refreshed). Even though the  
parasite is saved every time the script is executed, it is actually  
GIMP's internally stored last value (not the parasite) that is used in  
determining the value for the 'bit-width' parameter. The only reason  
you'd want to take these steps is to support last values across  
different sessions. The behavior you desired (as expressed in the  
first paragraph of your post) is already supported by GIMP.

Gimp-user mailing list

Reply via email to