GIMP: How to create 3.0 procedures for context menus and <Layers> vs. top-level <Image>?

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!

BTW, I corrected procedure.set_sensitivity_mask(Gimp.ProcedureSensitivityMask.ALWAYS) to Gimp.ProcedureSensitivityMask.DRAWABLE, that did not help either.
I also think I located the point where the error is caught, the filename is app/plug-in/gimppluginprocedure.c , and the function is gimp_plug_in_procedure_add_menu_path(), around line 670, where the procedure’s arguments are tested.

My current assumption is that the procedure’s third argument, which is supposed to be a GimpLayer or GimpDrawable is missing. I’m not sure how to correct that. Perhaps I need to set the procedure’s properties in a specific order.

Could you open an issue in our issue tracker. That way it won’t be forgotten. We certainly need to have a look at that before 3.0.

I opened an issue myself here since this is definitely not working. Not only for layers, but also for channels and probably others too.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.