Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
several register by python file ?
#1
I am doing a script that I want to execute very quickly with a shortcut, or more slowly with a option window. Something similar to "save" (quickly executed with ctrl+s) and "save as ..." (with a window to precise options). How should I do ?
  1. Should I do two completely separated plug-ins ?
  2. Or one plug-in with two python files in it (one importing the other I guess) ?
  3. Or can I put several register function in one python script ?
  4. other ?
I would say the third option is the best, but as I can't remember having seen such thing anywhere, I wonder if there are habits or rules about that.
The code would look like that :

Code:
from gimpfu import *

def slow_function(image, layer, other, options):
    #some code

def quick_function(image, layer):
    slow_function(image, layer, defaults, values)

register(
    "python-fu-quick-function",
    "description",
    "description",
    "Your Name",
    "Your Name",
    "2023",
    "<Image>/Filters/quick function",
    "*",
    [],
    [],
   quick_function)

register(
    "python-fu-slow-function",
    "description",
    "description",
    "Your Name",
    "Your Name",
    "2023",
    "<Image>/Filters/slow function ...",
    "*",
    [
        (PF_IMAGE,  'image',            'Image', None),
        (PF_OPTION, 'some option')],
        (PF_OPTION, 'some other option')]
    [],
    slow_function)

main()
Reply
#2
You can register several plugins in a single python file, just call register() once for each. I have plugins that register twenty of more entries. And remember that there is nothing special to the parameters of register(), they can be variables, so you can define values in a single place (author, copyright, maybe root menu or some plugin parameter definition) and reuse them in each register() call.
Reply
#3
Ok, great.
I have an other question :
I would like my quick plug-in to re-use the options last used when calling the slow plug-in. As I noticed that gimp remembers the options of a plug-in when using it several times (instead of falling back to the default values defined in the register), I suppose that they are saved somewhere. I am wandering if I can access those options.
If not, what would be the best way of archiving the same result ? Saving the option's values in a file inside the plug-in folder ? In what format ? CSV ? Json ?
Reply
#4
Using the plugin directory itself is dangerous, because the plugin could be installed for the system and so in a directory which is read-only when the plugin is run. using os.path.join(gimp.directory,'plugin-name' seems to be a popular option.

For the formatt CSV, is a pain. If you read & write from your code, JSON is somewhat easy.
Reply


Forum Jump: