mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 17:33:25 +00:00
plug-ins, libgimp: move GimpBatchProcedure's run function to use config objects.
Also port more script-fu procedures to gimp_procedure_new2(), which were sharing some code with the script-fu batch procedure.
This commit is contained in:
parent
af00b66914
commit
5d3112a2f1
10 changed files with 52 additions and 49 deletions
|
@ -124,12 +124,14 @@ static GimpValueArray *
|
|||
gimp_batch_procedure_run (GimpProcedure *procedure,
|
||||
const GimpValueArray *args)
|
||||
{
|
||||
GimpBatchProcedure *batch_proc = GIMP_BATCH_PROCEDURE (procedure);
|
||||
GimpValueArray *remaining;
|
||||
GimpValueArray *return_values;
|
||||
GimpRunMode run_mode;
|
||||
const gchar *cmd;
|
||||
gint i;
|
||||
GimpBatchProcedure *batch_proc = GIMP_BATCH_PROCEDURE (procedure);
|
||||
GimpValueArray *remaining;
|
||||
GimpValueArray *return_values;
|
||||
GimpRunMode run_mode;
|
||||
const gchar *cmd;
|
||||
GimpProcedureConfig *config;
|
||||
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
|
||||
gint i;
|
||||
|
||||
run_mode = GIMP_VALUES_GET_ENUM (args, 0);
|
||||
cmd = GIMP_VALUES_GET_STRING (args, 1);
|
||||
|
@ -143,12 +145,22 @@ gimp_batch_procedure_run (GimpProcedure *procedure,
|
|||
gimp_value_array_append (remaining, value);
|
||||
}
|
||||
|
||||
config = gimp_procedure_create_config (procedure);
|
||||
gimp_procedure_config_begin_run (config, NULL, run_mode, remaining);
|
||||
gimp_value_array_unref (remaining);
|
||||
|
||||
return_values = batch_proc->priv->run_func (procedure,
|
||||
run_mode,
|
||||
cmd,
|
||||
remaining,
|
||||
config,
|
||||
batch_proc->priv->run_data);
|
||||
gimp_value_array_unref (remaining);
|
||||
if (return_values != NULL &&
|
||||
gimp_value_array_length (return_values) > 0 &&
|
||||
G_VALUE_HOLDS_ENUM (gimp_value_array_index (return_values, 0)))
|
||||
status = GIMP_VALUES_GET_ENUM (return_values, 0);
|
||||
|
||||
gimp_procedure_config_end_run (config, status);
|
||||
g_object_unref (config);
|
||||
|
||||
return return_values;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ G_BEGIN_DECLS
|
|||
* GimpBatchFunc:
|
||||
* @procedure: the #GimpProcedure that runs.
|
||||
* @run_mode: the #GimpRunMode.
|
||||
* @args: the @procedure's remaining arguments.
|
||||
* @config: the @procedure's remaining arguments.
|
||||
* @run_data: (closure): the run_data given in gimp_batch_procedure_new().
|
||||
*
|
||||
* The batch function is run during the lifetime of the GIMP session,
|
||||
|
@ -46,7 +46,7 @@ G_BEGIN_DECLS
|
|||
typedef GimpValueArray * (* GimpBatchFunc) (GimpProcedure *procedure,
|
||||
GimpRunMode run_mode,
|
||||
const gchar *command,
|
||||
const GimpValueArray *args,
|
||||
GimpProcedureConfig *config,
|
||||
gpointer run_data);
|
||||
|
||||
|
||||
|
|
|
@ -26,13 +26,12 @@ from gi.repository import Gio
|
|||
import sys
|
||||
|
||||
|
||||
def code_eval(procedure, run_mode, code, args, data):
|
||||
def code_eval(procedure, run_mode, code, config, 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_set_i18n(self, procname):
|
||||
|
|
|
@ -96,8 +96,8 @@ static void script_fu_command_to_history (ConsoleInterface *console,
|
|||
*/
|
||||
|
||||
GimpValueArray *
|
||||
script_fu_console_run (GimpProcedure *procedure,
|
||||
const GimpValueArray *args)
|
||||
script_fu_console_run (GimpProcedure *procedure,
|
||||
GimpProcedureConfig *config)
|
||||
{
|
||||
ConsoleInterface console = { 0, };
|
||||
GtkWidget *vbox;
|
||||
|
@ -105,8 +105,6 @@ script_fu_console_run (GimpProcedure *procedure,
|
|||
GtkWidget *scrolled_window;
|
||||
GtkWidget *hbox;
|
||||
|
||||
GimpProcedureConfig *config;
|
||||
|
||||
script_fu_set_print_flag (1);
|
||||
|
||||
gimp_ui_init ("script-fu");
|
||||
|
@ -116,10 +114,6 @@ script_fu_console_run (GimpProcedure *procedure,
|
|||
console_history_init (&console.history);
|
||||
console_total_append_welcome (console.total_history);
|
||||
|
||||
/* Get previous or default settings into config. */
|
||||
config = gimp_procedure_create_config (procedure);
|
||||
gimp_procedure_config_begin_run (config, NULL, GIMP_RUN_INTERACTIVE, args);
|
||||
|
||||
script_fu_models_from_settings (&console, config);
|
||||
|
||||
console.dialog = gimp_dialog_new (_("Script Console"),
|
||||
|
@ -217,8 +211,6 @@ script_fu_console_run (GimpProcedure *procedure,
|
|||
|
||||
/* Update config with user's change to history */
|
||||
console_history_to_settings (&console.history, config);
|
||||
/* Persist config */
|
||||
gimp_procedure_config_end_run (config, GIMP_PDB_SUCCESS);
|
||||
|
||||
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
|
||||
GimpValueArray * script_fu_console_run (GimpProcedure *procedure,
|
||||
const GimpValueArray *args);
|
||||
GimpProcedureConfig *config);
|
||||
|
||||
|
||||
#endif /* __SCRIPT_FU_CONSOLE_H__ */
|
||||
|
|
|
@ -29,7 +29,7 @@ GimpValueArray *
|
|||
script_fu_eval_run (GimpProcedure *procedure,
|
||||
GimpRunMode run_mode,
|
||||
const gchar *code,
|
||||
const GimpValueArray *args)
|
||||
GimpProcedureConfig *config)
|
||||
{
|
||||
GString *output = g_string_new (NULL);
|
||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
GimpValueArray * script_fu_eval_run (GimpProcedure *procedure,
|
||||
GimpRunMode run_mode,
|
||||
const gchar *code,
|
||||
const GimpValueArray *args);
|
||||
GimpProcedureConfig *config);
|
||||
|
||||
|
||||
#endif /* __SCRIPT_FU_EVAL_H__ */
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
GimpValueArray *
|
||||
script_fu_text_console_run (GimpProcedure *procedure,
|
||||
const GimpValueArray *args)
|
||||
GimpProcedureConfig *config)
|
||||
{
|
||||
script_fu_redirect_output_to_stdout ();
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
|
||||
GimpValueArray * script_fu_text_console_run (GimpProcedure *procedure,
|
||||
const GimpValueArray *args);
|
||||
GimpProcedureConfig *config);
|
||||
|
||||
|
||||
#endif /* __SCRIPT_FU_TEXT_CONSOLE_H__ */
|
||||
|
|
|
@ -42,12 +42,12 @@ static GimpProcedure * script_fu_create_procedure (GimpPlugIn *plug_i
|
|||
const gchar *name);
|
||||
|
||||
static GimpValueArray * script_fu_run (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
GimpProcedureConfig *config,
|
||||
gpointer run_data);
|
||||
static GimpValueArray * script_fu_batch_run (GimpProcedure *procedure,
|
||||
GimpRunMode run_mode,
|
||||
const gchar *code,
|
||||
const GimpValueArray *args,
|
||||
GimpProcedureConfig *config,
|
||||
gpointer run_data);
|
||||
static void script_fu_run_init (GimpProcedure *procedure,
|
||||
GimpRunMode run_mode);
|
||||
|
@ -99,9 +99,9 @@ script_fu_create_procedure (GimpPlugIn *plug_in,
|
|||
|
||||
if (! strcmp (name, "extension-script-fu"))
|
||||
{
|
||||
procedure = gimp_procedure_new (plug_in, name,
|
||||
GIMP_PDB_PROC_TYPE_EXTENSION,
|
||||
script_fu_run, NULL, NULL);
|
||||
procedure = gimp_procedure_new2 (plug_in, name,
|
||||
GIMP_PDB_PROC_TYPE_EXTENSION,
|
||||
script_fu_run, NULL, NULL);
|
||||
|
||||
gimp_procedure_set_documentation (procedure,
|
||||
"A scheme interpreter for scripting "
|
||||
|
@ -115,9 +115,9 @@ script_fu_create_procedure (GimpPlugIn *plug_in,
|
|||
}
|
||||
else if (! strcmp (name, "plug-in-script-fu-console"))
|
||||
{
|
||||
procedure = gimp_procedure_new (plug_in, name,
|
||||
GIMP_PDB_PROC_TYPE_PLUGIN,
|
||||
script_fu_run, NULL, NULL);
|
||||
procedure = gimp_procedure_new2 (plug_in, name,
|
||||
GIMP_PDB_PROC_TYPE_PLUGIN,
|
||||
script_fu_run, NULL, NULL);
|
||||
|
||||
gimp_procedure_set_menu_label (procedure, _("Script-Fu _Console"));
|
||||
gimp_procedure_add_menu_path (procedure,
|
||||
|
@ -147,9 +147,9 @@ script_fu_create_procedure (GimpPlugIn *plug_in,
|
|||
}
|
||||
else if (! strcmp (name, "plug-in-script-fu-text-console"))
|
||||
{
|
||||
procedure = gimp_procedure_new (plug_in, name,
|
||||
GIMP_PDB_PROC_TYPE_PLUGIN,
|
||||
script_fu_run, NULL, NULL);
|
||||
procedure = gimp_procedure_new2 (plug_in, name,
|
||||
GIMP_PDB_PROC_TYPE_PLUGIN,
|
||||
script_fu_run, NULL, NULL);
|
||||
|
||||
gimp_procedure_set_documentation (procedure,
|
||||
"Provides a text console mode for "
|
||||
|
@ -191,17 +191,17 @@ script_fu_create_procedure (GimpPlugIn *plug_in,
|
|||
|
||||
static GimpValueArray *
|
||||
script_fu_run (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
GimpProcedureConfig *config,
|
||||
gpointer run_data)
|
||||
{
|
||||
GimpPlugIn *plug_in = gimp_procedure_get_plug_in (procedure);
|
||||
const gchar *name = gimp_procedure_get_name (procedure);
|
||||
GimpValueArray *return_vals = NULL;
|
||||
GimpRunMode run_mode = GIMP_RUN_NONINTERACTIVE;
|
||||
|
||||
if (gimp_value_array_length (args) > 0)
|
||||
script_fu_run_init (procedure, GIMP_VALUES_GET_ENUM (args, 0));
|
||||
else
|
||||
script_fu_run_init (procedure, GIMP_RUN_NONINTERACTIVE);
|
||||
if (g_object_class_find_property (G_OBJECT_GET_CLASS (config), "run-mode") != NULL)
|
||||
g_object_get (config, "run-mode", &run_mode, NULL);
|
||||
script_fu_run_init (procedure, run_mode);
|
||||
|
||||
if (strcmp (name, "extension-script-fu") == 0)
|
||||
{
|
||||
|
@ -222,7 +222,7 @@ script_fu_run (GimpProcedure *procedure,
|
|||
* The script-fu text console for interactive Scheme development
|
||||
*/
|
||||
|
||||
return_vals = script_fu_text_console_run (procedure, args);
|
||||
return_vals = script_fu_text_console_run (procedure, config);
|
||||
}
|
||||
else if (strcmp (name, "plug-in-script-fu-console") == 0)
|
||||
{
|
||||
|
@ -230,7 +230,7 @@ script_fu_run (GimpProcedure *procedure,
|
|||
* The script-fu console for interactive Scheme development
|
||||
*/
|
||||
|
||||
return_vals = script_fu_console_run (procedure, args);
|
||||
return_vals = script_fu_console_run (procedure, config);
|
||||
}
|
||||
|
||||
if (! return_vals)
|
||||
|
@ -245,7 +245,7 @@ static GimpValueArray *
|
|||
script_fu_batch_run (GimpProcedure *procedure,
|
||||
GimpRunMode run_mode,
|
||||
const gchar *code,
|
||||
const GimpValueArray *args,
|
||||
GimpProcedureConfig *config,
|
||||
gpointer run_data)
|
||||
{
|
||||
const gchar *name = gimp_procedure_get_name (procedure);
|
||||
|
@ -261,9 +261,9 @@ script_fu_batch_run (GimpProcedure *procedure,
|
|||
|
||||
if (g_strcmp0 (code, "-") == 0)
|
||||
/* Redirecting to script-fu text console, for backward compatibility */
|
||||
return_vals = script_fu_text_console_run (procedure, args);
|
||||
return_vals = script_fu_text_console_run (procedure, config);
|
||||
else
|
||||
return_vals = script_fu_eval_run (procedure, run_mode, code, args);
|
||||
return_vals = script_fu_eval_run (procedure, run_mode, code, config);
|
||||
}
|
||||
|
||||
if (! return_vals)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue