Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AI Gimp Plugins
#19
(11-04-2024, 08:13 PM)nchen Wrote: Thank you! That would save me a lot of time copying and pasting. I have been trying to implement this approach but I can't seem to get it to work. 
Do the functions in the 'libmodule.py' have to be registered similar to the GIMP plugins, even though GIMP doesn't check them? 
Also, are the input and output capabilities of functions within libmodule.py limited to GIMP's type codes (PF_INT, PF_FLOAT, etc)?

I have tried both registering them and not registering them to no avail.

For the example structure:
plug-ins
├── bar
│   ├── bar.py
│   └── libmodule.py

If I have a function within libmodule.py:
Code:
def insert_new_layer_with_alpha(image, width, height, name="New Layer"):
    new_layer = pdb.gimp_layer_new(image, width, height, 0, name, 100, 28)
    new_layer.add_alpha()
    pdb.gimp_image_insert_layer(image, new_layer, None, 0)
    return new_layer
register(
    "python_fu_insert-new-layer-with-alpha",     # Function Name
    "Insert new layer with alpha channel",       # Description
    "Insert a new layer with an alpha channel",  # Help
    "user",        # Author
    "user",        # Copyright
    "11/4/2024",   # Date Created
    "insert...",   # Menu label
    "",            # Image types
    [
        (PF_IMAGE, "image", "Image", None),
        (PF_INT, "int", "Width", 0),
        (PF_INT, "int", "Height", 0),
        (PF_STRING, "string", "Layer name", "New Layer")
    ],
    [
        (PF_DRAWABLE, "new_layer", "New layer")
    ],
    insert_new_layer_with_alpha, menu="<Image>/Comfy Tools")
Any time I attempt to import libmodule (with and without the register within libmodule.py), bar.py fails to register.
I have also tried registering and then calling insert_new_layer_with_alpha directly without importing.

I did test if the function within libmodule.py registers successfully to be sure it's not an error within the function.

The only time I've been able to get bar.py to register is when I don't attempt to import or call the functions within libmodule.py.

EDIT:
A kind of funny workaround I've been using sometimes is just installing a newer python version on my machine and calling it from the plugins:

Code:
import subprocess
   input_data = data
    # Run the script and pass the input data
    process = subprocess.Popen(
        ["py", "path/to/script/python3script.py"],
        stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
    )
    stdout, stderr = process.communicate(input=input_data.encode('utf-8'))
    result = stdout if process.returncode == 0 else stderr

If you use the Gimp API in the "libmodule" it should also do the required Gimp imports.
Reply


Messages In This Thread
AI Gimp Plugins - by nchen - 10-10-2024, 05:44 PM
RE: AI Gimp Plugins - by inkdolls - 10-25-2024, 11:39 PM
RE: AI Gimp Plugins - by nchen - 10-26-2024, 11:13 AM
RE: AI Gimp Plugins - by inkdolls - 10-28-2024, 03:16 AM
RE: AI Gimp Plugins - by nchen - 10-29-2024, 07:41 PM
RE: AI Gimp Plugins - by inkdolls - 10-30-2024, 12:51 AM
RE: AI Gimp Plugins - by nchen - 10-30-2024, 03:25 AM
RE: AI Gimp Plugins - by inkdolls - 10-30-2024, 05:27 AM
RE: AI Gimp Plugins - by nchen - 10-30-2024, 06:14 PM
RE: AI Gimp Plugins - by inkdolls - 11-01-2024, 02:53 AM
RE: AI Gimp Plugins - by inkdolls - 11-01-2024, 12:33 AM
RE: AI Gimp Plugins - by nchen - 11-01-2024, 07:59 PM
RE: AI Gimp Plugins - by inkdolls - 11-03-2024, 11:58 PM
RE: AI Gimp Plugins - by nchen - 11-04-2024, 02:48 AM
RE: AI Gimp Plugins - by Ofnuts - 11-04-2024, 08:09 AM
RE: AI Gimp Plugins - by nchen - 11-04-2024, 08:13 PM
RE: AI Gimp Plugins - by Ofnuts - 11-05-2024, 10:34 AM
RE: AI Gimp Plugins - by inkdolls - 11-05-2024, 02:34 AM
RE: AI Gimp Plugins - by nchen - 11-05-2024, 08:43 AM

Forum Jump: