GIMP3 /Python using gradient in menu crashes GIMP Appimage (original) (raw)

This test plug-in works fine with a flatpak GIMP,
but crashes the official Appimage from gimp.org:

#!/usr/bin/env python3
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <https://www.gnu.org/licenses/>.

import gi
gi.require_version('Gimp', '3.0')
from gi.repository import Gimp
gi.require_version('GimpUi', '3.0')
from gi.repository import GimpUi
gi.require_version('Gegl', '0.4')
from gi.repository import Gegl
from gi.repository import GObject
from gi.repository import GLib
from gi.repository import Gio
import time
import sys

def N_(message): return message
def _(message): return GLib.dgettext(None, message)

# '''
# A Python plugin.
# Tests GimpProcedureDialog.

# Temporarily, just testing widgets for subclasses of GimpResource.
# Temporarily, just testing Brush subclass of Resource.
# FUTURE: For all the parameter types.
# Formerly PF_ constants, now all parameters for which GimpParamSpecs exist.

# Not localized, no i18n
# '''


def process_args(gradient):
    assert gradient is not None
    assert isinstance(gradient, Gimp.Gradient)
    id = gradient.get_id()
    name = gradient.get_name()
    assert id is not None
    msg = "Gradient: {} (ID: {})".format(name, id)
    print(msg)
    Gimp.message(msg)
    return


def test_dialog(procedure, run_mode, image, drawables, config, data):
    '''
    Just a standard shell for a plugin.
    '''
    if run_mode == Gimp.RunMode.INTERACTIVE:
        GimpUi.init('python-fu-test-dialog')
        Gegl.init(None)
        dialog = GimpUi.ProcedureDialog(procedure=procedure, config=config)
        dialog.fill(None)
        if not dialog.run():
            dialog.destroy()
            return procedure.new_return_values(Gimp.PDBStatusType.CANCEL, GLib.Error())
        else:
            dialog.destroy()


    gradient = config.get_property('gradient')
    Gimp.context_push()

    process_args(gradient)

    Gimp.displays_flush()

    Gimp.context_pop()

    return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())


class TestDialogPlugin (Gimp.PlugIn):
    # FUTURE all other Gimp classes that have GimpParamSpecs

    ## GimpPlugIn virtual methods ##
    def do_set_i18n(self, procname):
        return True, 'gimp30-python', None

    def do_query_procedures(self):
        return [ 'python-fu-test-dialog' ]

    def do_create_procedure(self, name):
        procedure = Gimp.ImageProcedure.new(self, name,
                                            Gimp.PDBProcType.PLUGIN,
                                            test_dialog, None)
        procedure.set_sensitivity_mask (Gimp.ProcedureSensitivityMask.NO_IMAGE)
        procedure.set_documentation ("Test dialog",
                                     "Test dialog",
                                     name)
        procedure.set_menu_label("Test dialog X...")
        procedure.set_attribution("nelo",
                                  "nelo",
                                  "2025")
       
        procedure.add_menu_path ("<Image>/Filters/Development/Demos")

        
        procedure.add_gradient_argument ("gradient", "_Gradient",
                                         "Gradient", True,
                                         Gimp.Gradient.get_by_name ("Incandescent"),
                                         False,
                                         GObject.ParamFlags.READWRITE)
        

        return procedure

Gimp.main(TestDialogPlugin.__gtype__, sys.argv)

Tried on Linux Mint LMDE6 /Debian12
It’s an X11 system.
I did not get error messages.

Ofnuts April 18, 2025, 7:37pm 2

Crashes when? When executed or when registering? IIRC I had something like this in the past, due to the last arg of ImageProcedure.new(..?) being None.

nelo April 19, 2025, 6:29am 3

It crashes when executing.
When I execute it in a flatpak GIMP it spits out some info about the chosen gradient.
That’s expected behaviour. Doing the same in an AppImage GIMP tells me the plugin has crashed. I have other plugins with a gradient chooser. They behave the same way. Working fine in flatpaks, crashing in official AppImage.

I can’t test it because it is gray:

image

nelo April 22, 2025, 6:28am 5

Did you have an image open?
Try without.
Interestingly: when I don’t use gradient as a widget, but for example a pattern, it does not crash.