Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug script-fu scripts for gimp in scheme?

I try to make some script for gimp, using script-fu, scheme.

Naturally, as a beginner, there are lots of errors and misunderstandings.

Now I'm looking for a way to debug those scripts.

I found (gimp-message), but the result does not show up. I'm not aware if there is a possibility to print debug messages to anywhere I could check them.

Generating new images filled with text would probably work ;-) but looks a bit like an overkill.

What ways to debug a script in gimp are there?

like image 744
Gyro Gearloose Avatar asked Oct 28 '18 12:10

Gyro Gearloose


2 Answers

There may be a better way, but, the way I do it is to:

  1. open the script fu console (Filters -> Script Fu -> Console)
  2. edit a file (say for example: /Users/jamesanderson/code/scheme/gimp/learn1.scm
  3. type: (load "/Users/jamesanderson/code/scheme/gimp/learn1.scm") into the console
  4. hit enter
  5. edit file for changes
  6. keyboard arrow up (to get get the load function call again without typing)
  7. hit enter

enter image description here

enter image description here

Note this is an extension of my answer based on the comment. When going beyond the simple proof of concept scripts like the above, its important to know that that console retains state between calls. So for instance, if we run this scheme script:

(define jea-test-img-id nil)

(define (jea-find-test-img)
  (car (gimp-image-list)))

and then go to the console and type:

jea-test-img-id

we get as a result:

> jea-test-img-id
()

which is good, the script initiated the variable as needed and we see the result. So var set in script, console retains state change from script. Now lets change the state in the console:

(set! jea-test-img-id (jea-find-test-img))

we call a convenience function that grabs the first image ID in the active image list and store it in the variable we previously declared (which was then nil). Now lets examine the question again:

jea-test-img-id

then the result:

> jea-test-img-id
1

so high level: when you are working on a script, create working variables that hold the things you want to work on, like image, pxiels, widths etc then piece by piece get the functions working. In the end you may collapse it into one clean function once you have the short snippet pieces.

like image 112
James Anderson Avatar answered Sep 29 '22 19:09

James Anderson


The output of gimp-message goes to the "Error console" (if you have this dockable dialog setup), otherwise in a warning dialog.

If you are in Linux or OSX, you can also start Gimp from a terminal and use (print ...) calls, they will show in the terminal.

You can make your life easier and write your scripts in Python (easier to learn, and more powerful...). See here for the doc, here for some examples, and here for some debug tricks for Windows.

like image 35
xenoid Avatar answered Sep 29 '22 19:09

xenoid