Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interrupting a long-running script
#1
Sorry if this question has already been answered, but I couldn't find anything relevant. How can I interrupt a long-running script if for some reason I don't want to wait for it to complete? The only way I've found is to go into Task Manager (on Windows) and kill it, which isn't very elegant and leaves the do/undo stack in an invalid state, so I have to exit Gimp and restart it. Is there a way to poll the keyboard, say once every 100 ms., and test for a keypress? Or is there another way?

Thanks.
Reply
#2
A script (.scm) or a plugin (.py)? Btw when I write my Python scripts/plugin they often crash and yield the "undo stack in an invalid state" message, but this have never been an issue and I don't restart Gimp after that.
Reply
#3
(01-15-2018, 08:36 PM)Ofnuts Wrote: A script (.scm) or a plugin (.py)? Btw when I write my Python scripts/plugin they often crash and yield the "undo stack in an invalid state" message, but this have never been an issue and I don't restart Gimp after that.

Python. Maybe it isn't necessary to restart Gimp, I was just playing it safe. I'm more concerned about halting a run-away script than having to restart Gimp, anyway. Is there a clean way to do it?

Thanks.
Reply
#4
For Python scripts that use an auto-generated parameter dialog, there is a Cancel button, but it is likely that it is only effective if the script uses the progress bar left of the button (but a long-running script ought to do so).
Reply
#5
(01-15-2018, 09:17 PM)Ofnuts Wrote: For Python scripts that use an auto-generated parameter dialog, there is a Cancel button, but it is likely that it is only effective if the script uses the progress bar left of the button (but a long-running script ought to do so).

That sounds like what I'm looking for, and I do have a progress bar in my scripts if they run for more than a few seconds. But I'm not sure what you mean by "auto-generated parameter dialog". Where could I find an example?
Reply
#6
Most Python scripts just declare parameters and Gimp builds a parameter dialog on the fly when they are called. Those that don't either don't take parameters other than image+layer, or have a whole GUI written in Python. For a standard Python script that uses this autogenerated dialog, see Filters>Render>Cloud>Fog... (in your installation as (lib/gimp/2.0/plug-ins/foggify.py).
Reply
#7
(01-15-2018, 10:02 PM)Ofnuts Wrote: Most Python scripts just declare parameters and Gimp builds a parameter dialog on the fly when they are called. Those that don't either don't take parameters other than image+layer, or have a whole GUI written in Python. For a standard Python script that uses this autogenerated dialog, see Filters>Render>Cloud>Fog... (in your installation as (lib/gimp/2.0/plug-ins/foggify.py).

That's what I'm doing, I just never heard it described as "auto-generated". Here's my registration function:

Code:
register(
   "python-fu-folders",
   "Generate an image from directory hierarchy",
   "Generate an image from directory hierarchy",
   "David Kettle", "David Kettle", "2018",
   "Generate from folders ...",
   "", # type of image it works on (*, RGB, RGB*, RGBA etc...)
   [
       (PF_SPINNER, "width", "Width of image in pixels", 600, (1, 262144, 100)),
       (PF_SPINNER, "height", "Height of image in pixels", 480, (1, 262144, 100)),
       (PF_STRING, "dir", "Directory", "/Dropbox/WordPress/Galleries/Guatemala, 2009"),
       (PF_SPINNER, "opacity", "Opacity (0 - 100)", 50, (0, 100, 5)),
       (PF_COLOR, "background", "Background color", (255,255,255))
   ],
   [],
   folders, menu="<Image>/Python-Fu")
At the bottom right corner of the dialog box, there's an "OK" button and a "Cancel" button, but once the script starts running (in other words, when I click on "OK"), they're both grayed-out, I can't cancel the script once it's started running. I'm looking for some way to cancel it after it's started.
Reply


Forum Jump: