RSS/Atom feed Twitter
Site is read-only, email is disabled

Undo a Step in Python-Fu

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

4 of 4 messages available
Toggle history

Please log in to manage your subscriptions.

Undo a Step in Python-Fu FierySwordswoman 20 Oct 02:35
  Undo a Step in Python-Fu Joao S. O. Bueno 20 Oct 22:31
   Undo a Step in Python-Fu FierySwordswoman 21 Oct 00:54
    Undo a Step in Python-Fu FierySwordswoman 21 Oct 03:56
FierySwordswoman
2016-10-20 02:35:44 UTC (over 7 years ago)

Undo a Step in Python-Fu

Hi there,

I've just started the task of re-writing all of my scripts in a more professional manner. Hand-made UI, ability to be imported as a module, etc. However, I've come across a problem with managing the plugins' undo groups.

Initially, I put the whole plugin inside of a single undo group, but this would mean you could have a massive multiple-gigabyte undo group if the user ran the functions a lot. I've now frozen the undo group for actions such as temporary Previewing, but the main function has to be in an undo group.

My the current plugin I'm working on operates as such: -The 'Preview' function shows the black&white threshold that the bloom plugin will count as a 'light area'. The preview layer is removed whenever the next action (running main function, previewing again, closing window) is done. This operation will thus never be a part of the final result, and I can freeze it out of the undo-groups.

-The 'Execute' function runs the main script (bloom in this case) *without* closing the window. This allows the user to re-adjust the settings and re-execute very easily. Obviously, this is in an undo-group since it'll be the final result. However, due to the possibility of executing multiple times, it can either A: Creates a lot of undo groups or B: One undo group with a bunch of redundant information depending on where I place the groupings. I've attached the .py file to this post in case you want to see the problem in GIMP first-hand.

TL;DR: I need a way to either go back an undo step (Ctrl-Z) or to clear an undo step from the list in my Python script.

Joao S. O. Bueno
2016-10-20 22:31:31 UTC (over 7 years ago)

Undo a Step in Python-Fu

TL;DR: I need a way to either go back an undo step (Ctrl-Z) or to clear an undo step from the list in my Python script.

There is no API to adding, popping or applying undo steps.

In the past, I've done things like duplicate the image on plug-in start, and disable undo completely
on the copy - and copying the plug-in results back to the originating image on conclusion. That puts a single "paste" operation on your undo-stack (and can be really faster for plug-ins performing, say, lots of brushstrokes).

From your message, it seems like you've tried a lot the existing possibilities, and probably this trick won't help you at all - but, that is only what exists on GIMP.

js -> wrote:

Hi there,

I've just started the task of re-writing all of my scripts in a more professional manner. Hand-made UI, ability to be imported as a module, etc. However, I've come across a problem with managing the plugins' undo groups.

Initially, I put the whole plugin inside of a single undo group, but this would mean you could have a massive multiple-gigabyte undo group if the user ran the functions a lot. I've now frozen the undo group for actions such as temporary Previewing, but the main function has to be in an undo group.

My the current plugin I'm working on operates as such: -The 'Preview' function shows the black&white threshold that the bloom plugin will count as a 'light area'. The preview layer is removed whenever the next action (running main function, previewing again, closing window) is done. This operation will thus never be a part of the final result, and I can freeze it out of the undo-groups.

-The 'Execute' function runs the main script (bloom in this case) *without* closing the window. This allows the user to re-adjust the settings and re-execute very easily. Obviously, this is in an undo-group since it'll be the final result. However, due to the possibility of executing multiple times, it can either A: Creates a lot of undo groups or B: One undo group with a bunch of redundant information depending on where I place the groupings. I've attached the .py file to this post in case you want to see the problem in GIMP first-hand.

TL;DR: I need a way to either go back an undo step (Ctrl-Z) or to clear an undo step from the list in my Python script.

Attachments: * http://www.gimpusers.com/system/attachments/303/original/fsw-bloom.py

-- FierySwordswoman (via www.gimpusers.com/forums) _______________________________________________ gimp-user-list mailing list
List address: gimp-user-list@gnome.org List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list List archives: https://mail.gnome.org/archives/gimp-user-list

FierySwordswoman
2016-10-21 00:54:24 UTC (over 7 years ago)

Undo a Step in Python-Fu

From your message, it seems like you've tried a lot the existing possibilities, and probably this trick won't help you at all - but, that is only what exists on GIMP.

Yes. While I haven't *tried* the possibilities, I've already thought about various half-solutions including: -The program exits, only allowing a single execution while the settings are saved to the gimp shelf for the next time it launches (what GIMP plugins normally do). -The program exits, only allowing a single execution but having a 'Preview Effect' button that runs the main function without saving to the undo group. This would mean you'd always have to run the effect an extra time to finalize it, even if the preview is perfect.

Your solution would work, but that'd involve re-constructing the entire image upon plugin launch. The whole point of not putting everything into a single large undo group is to avoid huge operations and hammering the RAM usage. It'd be fine for touching up an image, but bad for a large project consisting of like 20 layers. However, your solution really inspired me... What *doesn't* take a lot of resources is copying a single layer or two. I could freeze the undo memory for the entire duration the program's up, then at the very end I should be able to cut and re-add the layer into an undo group. In fact, this could allow for potentially faster performance when frequently undoing and redoing steps, as it'd just be a paste or two in the undo group instead of the long process to get there. It should be easy to do since I already have to save all the important layers as a class field so I can check for their existence and manipulate them in other parts of the program. I'll try modifying the code to be as follows and report back if it works:

Class __init__: freeze undo before anything else. Main window's on_destroy: copy and remove (cut if the layer object has it) the final layer(s). Thaw undo. Paste final layer(s).

-Even when I scale things to crazy resolutions in Waifu2x and use a developmental GIMP build, duplicating layers is still typically fast enough to be considered negligible. So, this *should* work absolutely perfectly.

FierySwordswoman
2016-10-21 03:56:52 UTC (over 7 years ago)

Undo a Step in Python-Fu

Alright, I added the 'duplicate final layers' code I described earlier to my plugin and it worked. In fact, it worked even better than I expected. With 2 final layers @2400*1755 in this case, the copying of the layers from frozen 'working' undo memory to a thawed, undo-able group happened instantaneously. To top it off, the size of the group was smaller than the master layer off which the script worked.

So with that and some finishing touches/features, I made a completely perfect Python plugin.