[gimp] plug-ins: Port python-eval.py plugin to python 3.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: Port python-eval.py plugin to python 3.
- Date: Sun, 20 Sep 2020 22:34:13 +0000 (UTC)
commit 33085b518226f3c8a7428747a033721b45c82293
Author: Elad Shahar <dawn ever gmail com>
Date: Mon Dec 16 02:11:10 2019 +0200
plug-ins: Port python-eval.py plugin to python 3.
To test that this works, run gimp in batch mode:
% gimp2.99 -i -b -
And then type: (python-fu-eval "print (2)") .
plug-ins/pygimp/plug-ins/python-eval.py | 42 ------------------
plug-ins/python/Makefile.am | 5 ++-
plug-ins/python/meson.build | 2 +-
plug-ins/python/python-eval.py | 78 +++++++++++++++++++++++++++++++++
4 files changed, 83 insertions(+), 44 deletions(-)
---
diff --git a/plug-ins/python/Makefile.am b/plug-ins/python/Makefile.am
index 73f7ce7e93..aad44977e1 100644
--- a/plug-ins/python/Makefile.am
+++ b/plug-ins/python/Makefile.am
@@ -27,12 +27,14 @@ palette_to_gradient_SCRIPTS = palette-to-gradient.py
py_slicedir = $(gimpplugindir)/plug-ins/py-slice
py_slice_SCRIPTS = py-slice.py
+python_evaldir = $(gimpplugindir)/plug-ins/python-eval
+python_eval_SCRIPTS = python-eval.py
+
spyro_plusdir = $(gimpplugindir)/plug-ins/spyro-plus
spyro_plus_SCRIPTS = spyro-plus.py
# TODO: to be ported:
## histogram-export.py
-## python-eval.py
if GIMP_UNSTABLE
benchmark_foreground_extractdir = $(gimpplugindir)/plug-ins/benchmark-foreground-extract
@@ -52,6 +54,7 @@ EXTRA_DIST = \
palette-sort.py \
palette-to-gradient.py \
py-slice.py \
+ python-eval.py \
spyro-plus.py
if GIMP_UNSTABLE
diff --git a/plug-ins/python/meson.build b/plug-ins/python/meson.build
index b21cfbda75..67dd3669fb 100644
--- a/plug-ins/python/meson.build
+++ b/plug-ins/python/meson.build
@@ -11,10 +11,10 @@ plugins = [
{ 'name': 'palette-sort' },
{ 'name': 'palette-to-gradient' },
{ 'name': 'py-slice' },
+ { 'name': 'python-eval' },
{ 'name': 'spyro-plus' },
# { 'name': 'histogram-export' },
- # { 'name': 'python-eval' },
]
if not stable
diff --git a/plug-ins/python/python-eval.py b/plug-ins/python/python-eval.py
new file mode 100644
index 0000000000..966671e7de
--- /dev/null
+++ b/plug-ins/python/python-eval.py
@@ -0,0 +1,78 @@
+#!/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, args, data):
+
+ # Get the parameters
+ if args.length() != 1:
+ error = 'No parameters given'
+ return procedure.new_return_values(Gimp.PDBStatusType.CALLING_ERROR,
+ GLib.Error(error))
+
+ code = args.index(0)
+ if code == '-':
+ code = sys.stdin.read()
+ exec(code, globals())
+ return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
+
+
+class PythonEval (Gimp.PlugIn):
+ ## Parameters ##
+ __gproperties__ = {
+ "code": (str,
+ "Python code to evaluate, or '-' to read from stdin",
+ "Python code to evaluate, or '-' to read from stdin",
+ "",
+ GObject.ParamFlags.READWRITE)
+ }
+
+ ## 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.Procedure.new(self, name,
+ 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")
+
+ procedure.add_argument_from_property(self, "code")
+
+ return procedure
+
+
+Gimp.main(PythonEval.__gtype__, sys.argv)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]