It is currently Mon Aug 17, 2026 10:52 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Undo in pythonfu
PostPosted: Sun Sep 07, 2014 10:38 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jan 15, 2013
Posts: 133
This is just an inquiry for something I've wondered about for a long time. I've only ever scripted in scheme and am not familiar with the internal workings of pythonfu.

In regular scm files, it seems to be standard practice to set up a full undo for the script, but I don't see this done in plugins, aka pythonfu. I did look over the documentation a bit and found this.
image.enable_undo()
Enables undo for image. You might use these commands round a plugin, so that the plug-in's actions can be undone in a single step.


I guess I'm more focused on plugins dealing with paths, but they all seem to require a zillion undo steps if you decide to try that, and some will never remove the path it created. Of course you can manually remove the path which is the same thing, but it just made me wonder if there was something about pythonfu, or in particular plugins dealing with paths, that there isn't a way to do a full undo?

Anyway, on another note, I downloaded a plugin today that had the coolest feature I've ever seen! When you start gimp after installing this plugin, it prompts you for a menu location, plugin name, and it's defaults. (Only one default setting in this plugin, but of course it could be more.)

This is just fantastic and wish this could be incorporated as standard practice for every script or plugin. The only problem with it, is if you make a mistake, it directs you to delete the generated menu_path file so you can adjust it again. Unfortunately this doesn't work because it has been registered in the pluginrc file. The only way I was able to fully reset it's menu location is to remove it from the pluginrc file. Of course most people could just delete their pluginrc file, but mine is customized to to get the menu structure I want for binary plugins that the menu location can't be changed.

Anyway, this seems to be a huge leap forward in what gimp scripts and plugins could be like in the future. It would be great if more people could use this code and make it standard practice. I've personally spent days getting my menus the way I want and it would be trivial if you could answer a few questions upon first run of the script to have it exactly the way you want.

Cheers,
akovia

_________________
Gimp 2.8.16
Arch Linux - XFCE 4.12
Some of my work.


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Undo in pythonfu
PostPosted: Sun Sep 07, 2014 11:20 am  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
Undo:

All the PDB calls used by script-fu are also usable by python-fu. In addition the gimp.Image class has convenience methods: undo_freeze, undo_thaw, undo_group_start, undo_group_end, enable_undo, disable_undo. There is nothing in python-fu that prevents a proper handling of the undo stack, and if reported to the authors any such problems can be fixed.

Registration:

My add-on manager plugin does something similar (instead of asking the user it looks in a configuration file...).

But this dynamic registration has two problems:
  1. A bit of standardization across users does a lot of good in forums. At least we are all discussing about the same things. And when the menu is in a foreign language, we can still trust the order of the menu items. And at least you can expect the plugin author to have a somewhat deeper understanding of the menu structure, and not overwrite some standard menu entry. The only thing I would advocate is a end-user-enabled way to translate the menu entries (and field descriptions in dialogs). Individual script authors cannot manage 35 languages.
  2. Gimp doesn't run the registration code of plug-ins it already knows. The pluginrc file contains the timestamp of the executable from the last execution of the registration, and if this hasn't changed the registration step is skipped. So this dynamic registration is a one shot unless you erase pluginrc (and rerun all the registrations), edit pluginrc to remove only the right registrations, or change the timestamp on the executable file. These things can be beyond the abilities of some users.

_________________
Image


Top
 Post subject: Re: Undo in pythonfu
PostPosted: Sun Sep 07, 2014 3:56 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: Jan 15, 2013
Posts: 133
ofnuts wrote:
All the PDB calls used by script-fu are also usable by python-fu. In addition the gimp.Image class has convenience methods: undo_freeze, undo_thaw, undo_group_start, undo_group_end, enable_undo, disable_undo. There is nothing in python-fu that prevents a proper handling of the undo stack, and if reported to the authors any such problems can be fixed.


I figured if it could be done that it might just be more trouble than it's worth to the authors. For some reason it just doesn't get used very much for plugins. I would never report it unless I knew something was broken. Otherwise the author would have added it in the first place.

ofnuts wrote:
My add-on manager plugin does something similar (instead of asking the user it looks in a configuration file...).

But this dynamic registration has two problems:
  1. A bit of standardization across users does a lot of good in forums. At least we are all discussing about the same things. And when the menu is in a foreign language, we can still trust the order of the menu items. And at least you can expect the plugin author to have a somewhat deeper understanding of the menu structure, and not overwrite some standard menu entry. The only thing I would advocate is a end-user-enabled way to translate the menu entries (and field descriptions in dialogs). Individual script authors cannot manage 35 languages.
  2. Gimp doesn't run the registration code of plug-ins it already knows. The pluginrc file contains the timestamp of the executable from the last execution of the registration, and if this hasn't changed the registration step is skipped. So this dynamic registration is a one shot unless you erase pluginrc (and rerun all the registrations), edit pluginrc to remove only the right registrations, or change the timestamp on the executable file. These things can be beyond the abilities of some users.


I admit that I always forget about localization. I guess that's why I'm not a developer. :P

Well I found that bug myself when I typo'd where I wanted it. Regardless, I think it's a functionality that should be explored more in the core of gimp to support something similar, if it's done this exact way or not. These are the exact 3 things I hand edit on all scripts/plugins, though having the ability to reset the defaults from the UI would be much more useful, as you learn to use a plugin or script, or want defaults for a certain project.

Thank you for the detailed explanation of undo, and your thoughts on dynamic registration. Another perspective is always useful.
Cheers

_________________
Gimp 2.8.16
Arch Linux - XFCE 4.12
Some of my work.


Top
 Post subject: Re: Undo in pythonfu
PostPosted: Sun Sep 07, 2014 4:25 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
akovia wrote:
ofnuts wrote:
All the PDB calls used by script-fu are also usable by python-fu. In addition the gimp.Image class has convenience methods: undo_freeze, undo_thaw, undo_group_start, undo_group_end, enable_undo, disable_undo. There is nothing in python-fu that prevents a proper handling of the undo stack, and if reported to the authors any such problems can be fixed.


I figured if it could be done that it might just be more trouble than it's worth to the authors. For some reason it just doesn't get used very much for plugins. I would never report it unless I knew something was broken. Otherwise the author would have added it in the first place.

Never be shy to report a bug.

All is needed is to bracket the code with image.undo_group_start() and image.undo_group_end(). Since you can catch exceptions in Python you can make sure that the image.undo_group_end() is run even if something unexpected happens.

If the plugin creates a path, then
- if the path is added to the image once it is complete, this adds only one item to the undo stack and the undo grouping isn't necessary.
- If the path is added to the image before being populated with strokes, then you get an undo item for each additional stroke, unless undo grouping is set. However this method is considerably slower that the method above...

_________________
Image


Top
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group