1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
#!/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('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(brush, font, gradient, palette, pattern):
'''
Test the args are sane.
'''
assert brush is not None
assert isinstance(brush, Gimp.Brush)
id = brush.get_id()
name = brush.get_name()
assert id is not None
msg = "Brush: {} (ID: {})".format(name, id)
print(msg)
Gimp.message(msg)
assert font is not None
assert isinstance(font, Gimp.Font)
id = font.get_id()
name = font.get_name()
assert id is not None
msg = "Font: {} (ID: {})".format(name, id)
print(msg)
Gimp.message(msg)
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)
assert palette is not None
assert isinstance(palette, Gimp.Palette)
id = palette.get_id()
name = palette.get_name()
assert id is not None
msg = "Palette: {} (ID: {})".format(name, id)
print(msg)
Gimp.message(msg)
assert pattern is not None
assert isinstance(pattern, Gimp.Pattern)
id = pattern.get_id()
name = pattern.get_name()
assert id is not None
msg = "Pattern: {} (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:
gi.require_version('GimpUi', '3.0')
from gi.repository import GimpUi
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()
brush = config.get_property('brush')
font = config.get_property('font')
gradient = config.get_property('gradient')
palette = config.get_property('palette')
pattern = config.get_property('pattern')
Gimp.context_push()
process_args(brush, font, gradient, palette, pattern)
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...")
procedure.set_attribution("Lloyd Konneker",
"Lloyd Konneker",
"2022")
# Top level menu "Test"
procedure.add_menu_path ("<Image>/Filters/Development/Demos")
procedure.add_brush_argument ("brush", "_Brush", "Brush", True,
Gimp.Brush.get_by_name ("2. Hardness 025"),
False,
GObject.ParamFlags.READWRITE)
procedure.add_font_argument ("font", "_Font", "Font", True,
Gimp.Font.get_by_name ("Serif"),
False,
GObject.ParamFlags.READWRITE)
procedure.add_gradient_argument ("gradient", "_Gradient",
"Gradient", True,
Gimp.Gradient.get_by_name ("Incandescent"),
False,
GObject.ParamFlags.READWRITE)
procedure.add_palette_argument ("palette", "_Palette",
"Palette", True,
Gimp.Palette.get_by_name ("Default"),
False,
GObject.ParamFlags.READWRITE)
procedure.add_pattern_argument ("pattern", "Pa_ttern",
"Pattern", True,
Gimp.Pattern.get_by_name ("Paper"),
False,
GObject.ParamFlags.READWRITE)
return procedure
Gimp.main(TestDialogPlugin.__gtype__, sys.argv)
|