I’m trying to port someone else’s GIMP 2.10 python plugin to GIMP 3.0. I am creating multiple procedures for the same plugin. I have successfully added empty stubs for Image procedures, but now I am getting errors for Layers context-menu procedures. The error is
attempted to install <Layers> procedure "StabDifAuto1111-controlnet-layer-context" which does not take the standard <Layers> plug-in's arguments: (GimpRunMode, GimpImage, (GimpLayer | GimpDrawable)).
I’m trying to use the following code, which works for creating procedures under the top-level menu , but does not work for context menus under Layers
def do_create_procedure(self, name):
procedure = Gimp.ImageProcedure.new(self,
name,
Gimp.PDBProcType.PLUGIN,
self.run_with_image,
None)
procedure.set_menu_label(_(name))
procedure.add_menu_path(StabDifAuto1111.LIMB_LAYERS_MENU_NAME)
procedure.set_documentation("Configure checkpoint model of Automatic1111 api",
"Select a submenu.",
name)
procedure.set_image_types("")
procedure.set_icon_name(GimpUi.ICON_GEGL)
procedure.set_sensitivity_mask(Gimp.ProcedureSensitivityMask.ALWAYS)
procedure.set_attribution("Hymerfania", "Hymerfania", "2024")
return procedure
def run_with_image(self, procedure, run_mode, image, n_drawables, drawables, args, run_data):
GimpUi.init(StabDifAuto1111.PYTHON_PLUGIN_NAME)
retval = procedure.new_return_values(Gimp.PDBStatusType.CANCEL, GLib.Error())
return retval
The original GIMP 2.10 registration looked like this:
PLUGIN_FIELDS_LAYERS = [
(gimpfu.PF_IMAGE, "image", "Image", None),
(gimpfu.PF_LAYER, "layer", "Layer", None),
]
PLUGIN_FIELDS_CONTROLNET = [] + [
(gimpfu.PF_OPTION, "module", "Module", 0, CONTROLNET_MODULES),
(gimpfu.PF_OPTION, "model", "Model", 0, settings.get("cn_models", ["none"])),
(gimpfu.PF_SLIDER, "weight", "Weight", 1, (0, 2, 0.05)),
(gimpfu.PF_OPTION, "resize_mode", "Resize Mode", 1, CONTROLNET_RESIZE_MODES),
(gimpfu.PF_BOOL, "lowvram", "Low VRAM", False),
(gimpfu.PF_OPTION, "control_mode", "Control Mode", 0, tuple(CONTROL_MODES.keys())),
(gimpfu.PF_SLIDER, "guidance_start", "Guidance Start (T)", 0, (0, 1, 0.01)),
(gimpfu.PF_SLIDER, "guidance_end", "Guidance End (T)", 1, (0, 1, 0.01)),
(gimpfu.PF_SLIDER, "guidance", "Guidance", 1, (0, 1, 0.01)),
(gimpfu.PF_SLIDER, "processor_res", "Processor Resolution", 512, (64, 2048, 1)),
(gimpfu.PF_SLIDER, "threshold_a", "Threshold A", 64, (100, 2048, 1)),
(gimpfu.PF_SLIDER, "threshold_b", "Threshold B", 64, (200, 2048, 1)),
]
gimpfu.register(
"stable-gimpfusion-config-controlnet-layer-context",
"Convert current layer to ControlNet layer or edit ControlNet Layer's options",
"ControlNet Layer",
"ArtBIT",
"ArtBIT",
"2023",
"Use as ControlNet",
"*",
[] + PLUGIN_FIELDS_LAYERS + PLUGIN_FIELDS_CONTROLNET,
[],
handleControlNetLayerConfigFromLayersContext, menu="<Layers>/GimpFusion"
)
I have searched the 3.0 API docs tarball but I have not found a class for “Layers plug-in”. I tried replacing run_with_images() with a run_with_layers() function with only the parameters mentioned in the error message, but that did not make any difference.
What is the difference between creating a top-level procedure, and a contextual procedure?
Thanks!