gimp python plug in: how to trigger another user input

499 views Asked by At

Situation: My gimp python plug-in shows the user a drop down box with two options [".jpg", ".png"].

Question: How to show a second input window with conditional content based on first input?

  • .jpg --> "Quality" range slider [0 - 100]
  • .png --> "Compression" range slider [0 - 9]

In different words: How to trigger a (registered) plug-in WITH user-input-window from within the main function of a plug-in?

1

There are 1 answers

3
xenoid On BEST ANSWER

Either you build a full GUI with PyGTK (or perhaps tkinter) or you find another way. Typically for this if you stick to the auto-generated dialogs you have the choice between:

  • a somewhat clumsy dialog that asks for both parameters and will ignore one or the other depending of the image format,
  • two menu entries for two different dialogs, one for PNG and one for JPG.

On the other hand, I have always use compression level 9 in my PNGs (AFAIK the only benefit of other levels is CPU time, but this is moot in modern machines) so your dialog could only ask for the JPEG quality which would mak it less clumsy.

However... JPEG quality isn't all there is to it and there are actually many options (chroma sub-sampling being IMHO at least as important as quality), and to satisfy all needs you could end up with a rather complex dialog. So you could either:

  • Just save with the current user's default settings (gimp_file_save())
  • Get these settings from some .ini file (they are less likely to change than other parameters of your script)
  • Not save the image and let the user Save/Export to his/her liking (if this isn't a batch processing script)