mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-04 01:43:24 +00:00

The CLI options now know which procedures are batch procedures or not. First it means that it won't just randomly try any procedure name one may pass and will properly output an error if you pass a non-existing interpreter procedure. Secondly, there is no default interpreter anymore (unless only one interpreter exists). If you don't set an interpreter procedure with --batch-interpreter or if you pass a wrong one, it will output the list of available batch procedure, thus helping you understanding how to use the --batch option.
59 lines
2.1 KiB
Python
59 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
|
|
# Gimp-Python - allows the writing of Gimp plugins in Python.
|
|
# Copyright (C) 2006 Manish Singh <yosh@gimp.org>
|
|
#
|
|
# 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
|
|
from gi.repository import GObject
|
|
from gi.repository import GLib
|
|
from gi.repository import Gio
|
|
|
|
import sys
|
|
|
|
|
|
def code_eval(procedure, run_mode, code, args, data):
|
|
if code == '-':
|
|
code = sys.stdin.read()
|
|
exec(code, globals())
|
|
return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
|
|
|
|
|
|
class PythonEval (Gimp.PlugIn):
|
|
## GimpPlugIn virtual methods ##
|
|
def do_query_procedures(self):
|
|
self.set_translation_domain("gimp30-python",
|
|
Gio.file_new_for_path(Gimp.locale_directory()))
|
|
|
|
return ['python-fu-eval']
|
|
|
|
def do_create_procedure(self, name):
|
|
procedure = Gimp.BatchProcedure.new(self, name, "Python 3",
|
|
Gimp.PDBProcType.PLUGIN,
|
|
code_eval, None)
|
|
procedure.set_documentation ("Evaluate Python code",
|
|
"Evaluate python code under the python interpreter (primarily for batch mode)",
|
|
name)
|
|
|
|
procedure.set_attribution("Manish Singh",
|
|
"Manish Singh",
|
|
"2006")
|
|
|
|
return procedure
|
|
|
|
|
|
Gimp.main(PythonEval.__gtype__, sys.argv)
|