Updated with upstream update

This commit is contained in:
2023-10-30 15:55:30 -07:00
parent 098531073c
commit 3bbdd873ef
584 changed files with 91827 additions and 70362 deletions

View File

@ -41,7 +41,7 @@ PROC_NAME = 'python-fu-console'
RESPONSE_BROWSE, RESPONSE_CLEAR, RESPONSE_SAVE = range(3)
def run(procedure, args, data):
def run(procedure, config, data):
PikaUi.init ("python-console.py")
namespace = {'__builtins__': __builtins__,
@ -51,6 +51,7 @@ def run(procedure, args, data):
'Gdk': gi.repository.Gdk,
'Gegl': gi.repository.Gegl,
'Pika': gi.repository.Pika,
'PikaUi': gi.repository.PikaUi,
'Gio': gi.repository.Gio,
'Gtk': gi.repository.Gtk,
'GdkPixbuf': gi.repository.GdkPixbuf,
@ -160,71 +161,30 @@ def run(procedure, args, data):
if proc is None:
return None
cmd = ''
return_values = proc.get_return_values()
# assert is list of GParamSpec
param_specs = proc.get_arguments()
'''
Cat str of variable names to which unpack return values
Variable names same as return value name, mangled
Str like: 'retval_1, ret_val_2 = '
'''
cmd = f"procedure = Pika.get_pdb().lookup_procedure('{proc_name}'); "
cmd += f"config = procedure.create_config(); "
for arg in param_specs:
if arg.name == 'run-mode':
# Special handling for run mode.
cmd += "config.set_property('" + arg.name + "', Pika.RunMode.INTERACTIVE); "
else:
cmd += "config.set_property('" + arg.name + "', " + arg.name.replace('-', '_') + "); "
cmd += f"result = procedure.run(config); "
cmd += f"success = result.index(0)"
if len(return_values) > 0:
cmd += ', '.join(x.name.replace('-', '_') for x in return_values)
cmd += ' = '
# else is a void PDB procedure
'''
Cat prefix of str for a call to procedure name
Prefix like: Pika.get_pdb().run_procedure('<foo>',
Note:
- proc name is quoted, run_procedure wants a string.
- proc name has hyphens. Not a Python name. Matches name in PDB.
- trailing comma, another arg to follow:
run_procedure takes two args: string name, and GValueArray of args
'''
cmd += f"Pika.get_pdb().run_procedure('{proc_name}', "
'''
Assemble argument string.
Using names of formal args, which might not match names already
defined in the browsing environment (the REPL).
Args are passed to a PDB procedure in a GValueArray.
Assemble a string like '[arg_1, arg_2]'.
When eval'd, the Python binding will convert to a GValueArray.
'''
param_specs = proc.get_arguments()
cmd += '[ '
'''
Special handling for run mode.
PIKA v2: PikaFu had different handling for run mode.
Insure run mode interactive, i.e. called procedure may open a GUI.
This assumes that procedures use the same formal name for runmode arg.
There might be rare other cases, especially for third party plugins?
E.G. See formal signature of file-gex-load
There is no other way to distinguish the run mode formal argument,
as its formal type is PikaParamEnum, a generic enum.
'''
if len(param_specs) > 0 and param_specs[0].name == 'run-mode':
cmd += 'Pika.RunMode.INTERACTIVE, '
param_specs = param_specs[1:]
# else doesn't take a run mode arg
# Cat string of arg names to a call
# Like: 'arg_1, arg_2' where formal names arg-1 and arg-2
cmd += ', '.join(x.name.replace('-', '_') for x in param_specs)
# terminate the arg array, and close parens the call
cmd += '])'
i = 1
for retval in return_values:
cmd += '; {} = result.index({})'.format(retval.name.replace('-', '_'), i)
i += 1
return cmd
def browse_response(self, dlg, response_id):
if response_id != Gtk.ResponseType.APPLY:
Gtk.Widget.hide(dlg)