Proof-of-concept:
A plugin that applies a GEGL Gaussian blur vertically or horizontally after showing this:
The whole plugin code (everything else is in a gimphelpers
Python module:
#!/usr/bin/env python3
# Demo for gimphelpers
# Demo of the choice arg with values
import gi
gi.require_version('Gimp', '3.0')
from gi.repository import Gimp
gi.require_version('Gegl', '0.4')
from gi.repository import Gegl
from gi.repository import GLib
import sys
from gimphelpers import *
def _(message): return GLib.dgettext(None, message)
# Direction choice. This is both the object used to generate the dialog
# and the one from which values are retrieved. Here we use functions
# just to show how powerful this can be
directions=Choice('direction','Direction','Choice of direction','H',
[
Option('H','Horizontal',help='Up and down',value=lambda v: (v,0.)),
Option('V','Vertical', value=lambda v: (0.,v)),
])
#
# The actual plugin code, doest a vertical or horizontal blur, given a size and a dierction
#
def executeChoice(procedure, run_mode, image, drawables, config, data):
trace(f'entering executeChoice({procedure=!r}, {run_mode=!r}, {image=!r}, {drawables=!r}, {config=!r}, {data=!r})')
direction=config.get_property('direction')
size=config.get_property('size')
sizeX,sizeY=directions[direction](size)
Gegl.init()
layer=drawables[0]
selected,x,y,w,h=layer.mask_intersect()
if selected:
applyGeglOnBuffers(layer.get_buffer(),layer.get_shadow_buffer(),'gegl:gaussian-blur',std_dev_x=sizeX,std_dev_y=sizeY)
layer.merge_shadow(True)
layer.update(x,y,w,h)
return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
#
# The "registration" code
#
class ChoiceDemo(HelpedPlugin):
def __init__(self):
super().__init__(
[
ProcedureDescription(
'choice-demo',
'RGB*, GRAY*',Gimp.ProcedureSensitivityMask.DRAWABLE,
executeChoice,
menuLabel=_('Choice demo'), # I18N is can be used
menuPath='<Image>/'+_('Test'),
args= [
Double('size',_('Blur size'),'',0.,1500.,5.), # using order
directions,
],
)
])
Gimp.main(ChoiceDemo.__gtype__, sys.argv)
For the curious, the code (pretty much a WIP right now) is here.