PIKApp/plug-ins/python/python-eval.py

59 lines
2.0 KiB
Python
Raw Normal View History

2023-09-26 00:35:21 +02:00
#!/usr/bin/env python3
# Pika-Python - allows the writing of Pika 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('Pika', '3.0')
from gi.repository import Pika
from gi.repository import GObject
from gi.repository import GLib
from gi.repository import Gio
import sys
2023-10-30 23:55:30 +01:00
def code_eval(procedure, run_mode, code, config, data):
2023-09-26 00:35:21 +02:00
if code == '-':
code = sys.stdin.read()
exec(code, globals())
return procedure.new_return_values(Pika.PDBStatusType.SUCCESS, GLib.Error())
class PythonEval (Pika.PlugIn):
## PikaPlugIn virtual methods ##
def do_set_i18n(self, procname):
return True, 'pika30-python', None
def do_query_procedures(self):
return ['python-fu-eval']
def do_create_procedure(self, name):
procedure = Pika.BatchProcedure.new(self, name, "Python 3",
Pika.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
Pika.main(PythonEval.__gtype__, sys.argv)