void
script_fu_text_console_run (const gchar      *name,
                            gint              nparams,
                            const GimpParam  *params,
                            gint             *nreturn_vals,
                            GimpParam       **return_vals)
{
  static GimpParam  values[1];

  /*  Enable Script-Fu output  */
  ts_register_output_func (ts_stdout_output_func, NULL);

  ts_print_welcome ();

  gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_PLUGIN);

  /*  Run the interface  */
  ts_interpret_stdin ();

  gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_INTERNAL);

  values[0].type          = GIMP_PDB_STATUS;
  values[0].data.d_status = GIMP_PDB_SUCCESS;

  *nreturn_vals = 1;
  *return_vals  = values;
}
Exemplo n.º 2
0
static GimpPDBStatusType
page_setup (gint32 image_ID)
{
  GtkPrintOperation  *operation;
  GimpParam          *return_vals;
  gchar              *name;
  gint                n_return_vals;

  gimp_ui_init (PLUG_IN_BINARY, FALSE);

  operation = gtk_print_operation_new ();

  print_page_setup_load (operation, image_ID);
  print_page_setup_dialog (operation);
  print_page_setup_save (operation, image_ID);

  g_object_unref (operation);

  /* now notify a running print procedure about this change */
  name = print_temp_proc_name (image_ID);

  /* we don't want the core to show an error message if the
   * temporary procedure does not exist
   */
  gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_PLUGIN);

  return_vals = gimp_run_procedure (name,
                                    &n_return_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_END);
  gimp_destroy_params (return_vals, n_return_vals);

  g_free (name);

  return GIMP_PDB_SUCCESS;
}
Exemplo n.º 3
0
static void
run (const gchar      *name,
     gint              nparams,
     const GimpParam  *param,
     gint             *nreturn_vals,
     GimpParam       **return_vals)
{
  static GimpParam   values[2];
  GimpRunMode        run_mode;
  GimpPDBStatusType  status = GIMP_PDB_EXECUTION_ERROR;
  gint32             image_ID;
  GError            *error = NULL;

  run_mode = param[0].data.d_int32;

  *nreturn_vals = 1;
  *return_vals  = values;

  values[0].type          = GIMP_PDB_STATUS;
  values[0].data.d_status = status;

  if (! uri_backend_init (PLUG_IN_BINARY, TRUE, run_mode, &error))
    {
      if (error)
        {
          *nreturn_vals = 2;
          values[1].type          = GIMP_PDB_STRING;
          values[1].data.d_string = error->message;
        }

      return;
    }

  /*  We handle PDB errors by forwarding them to the caller in
   *  our return values.
   */
  gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_PLUGIN);

  if (! strcmp (name, LOAD_PROC) && uri_backend_get_load_protocols ())
    {
      image_ID = load_image (param[2].data.d_string, run_mode, &error);

      if (image_ID != -1)
        {
          status = GIMP_PDB_SUCCESS;

	  *nreturn_vals = 2;
	  values[1].type         = GIMP_PDB_IMAGE;
	  values[1].data.d_image = image_ID;
	}
    }
  else if (! strcmp (name, SAVE_PROC) && uri_backend_get_save_protocols ())
    {
      status = save_image (param[3].data.d_string,
                           param[1].data.d_int32,
                           param[2].data.d_int32,
                           run_mode, &error);
    }
  else
    {
      status = GIMP_PDB_CALLING_ERROR;
    }

  uri_backend_shutdown ();

  if (status != GIMP_PDB_SUCCESS && error)
    {
      *nreturn_vals = 2;
      values[1].type          = GIMP_PDB_STRING;
      values[1].data.d_string = error->message;
    }

  values[0].data.d_status = status;
}
Exemplo n.º 4
0
static gboolean
script_fu_cc_key_function (GtkWidget        *widget,
                           GdkEventKey      *event,
                           ConsoleInterface *console)
{
  GList       *list;
  gint         direction = 0;
  GtkTextIter  cursor;
  GString     *output;

  switch (event->keyval)
    {
    case GDK_KEY_Return:
    case GDK_KEY_KP_Enter:
    case GDK_KEY_ISO_Enter:
      if (script_fu_cc_is_empty (console))
        return TRUE;

      list = g_list_nth (console->history,
                         (g_list_length (console->history) - 1));

      if (list->data)
        g_free (list->data);

      list->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (console->cc)));

      gtk_text_buffer_get_end_iter (console->console, &cursor);

      gtk_text_buffer_insert (console->console, &cursor, "\n", 1);
      gtk_text_buffer_insert_with_tags_by_name (console->console, &cursor,
                                                "> ", 2,
                                                "strong",
                                                NULL);

      gtk_text_buffer_insert (console->console, &cursor,
                              gtk_entry_get_text (GTK_ENTRY (console->cc)), -1);
      gtk_text_buffer_insert (console->console, &cursor, "\n", 1);

      script_fu_console_scroll_end (console->text_view);

      gtk_entry_set_text (GTK_ENTRY (console->cc), "");

      output = g_string_new (NULL);
      ts_register_output_func (ts_gstring_output_func, output);

      gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_PLUGIN);

      if (ts_interpret_string (list->data) != 0)
        {
          script_fu_output_to_console (TS_OUTPUT_ERROR,
                                       output->str,
                                       output->len,
                                       console);
        }
      else
        {
          script_fu_output_to_console (TS_OUTPUT_NORMAL,
                                       output->str,
                                       output->len,
                                       console);
        }

      gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_INTERNAL);

      g_string_free (output, TRUE);

      gimp_displays_flush ();

      console->history = g_list_append (console->history, NULL);

      if (console->history_len == console->history_max)
        {
          console->history = g_list_remove (console->history,
                                            console->history->data);
          if (console->history->data)
            g_free (console->history->data);
        }
      else
        {
          console->history_len++;
        }

      console->history_cur = g_list_length (console->history) - 1;

      return TRUE;
      break;

    case GDK_KEY_KP_Up:
    case GDK_KEY_Up:
      direction = -1;
      break;

    case GDK_KEY_KP_Down:
    case GDK_KEY_Down:
      direction = 1;
      break;

    case GDK_KEY_P:
    case GDK_KEY_p:
      if (event->state & GDK_CONTROL_MASK)
        direction = -1;
      break;

    case GDK_KEY_N:
    case GDK_KEY_n:
      if (event->state & GDK_CONTROL_MASK)
        direction = 1;
      break;

    default:
      break;
    }

  if (direction)
    {
      /*  Make sure we keep track of the current one  */
      if (console->history_cur == g_list_length (console->history) - 1)
        {
          list = g_list_nth (console->history, console->history_cur);

          g_free (list->data);
          list->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (console->cc)));
        }

      console->history_cur += direction;

      if (console->history_cur < 0)
        console->history_cur = 0;

      if (console->history_cur >= console->history_len)
        console->history_cur = console->history_len - 1;

      gtk_entry_set_text (GTK_ENTRY (console->cc),
                          (gchar *) (g_list_nth (console->history,
                                                 console->history_cur))->data);

      gtk_editable_set_position (GTK_EDITABLE (console->cc), -1);

      return TRUE;
    }

  return FALSE;
}
static void
script_fu_ok (SFScript *script)
{
  GString *output;
  gchar   *command;
  gint     i;

  for (i = 0; i < script->n_args; i++)
    {
      SFArgValue *arg_value = &script->args[i].value;
      GtkWidget  *widget    = sf_interface->widgets[i];

      switch (script->args[i].type)
        {
        case SF_IMAGE:
        case SF_DRAWABLE:
        case SF_LAYER:
        case SF_CHANNEL:
        case SF_VECTORS:
        case SF_DISPLAY:
        case SF_COLOR:
        case SF_TOGGLE:
          break;

        case SF_VALUE:
        case SF_STRING:
          g_free (arg_value->sfa_value);
          arg_value->sfa_value =
            g_strdup (gtk_entry_get_text (GTK_ENTRY (widget)));
          break;

        case SF_TEXT:
          {
            GtkWidget     *view;
            GtkTextBuffer *buffer;
            GtkTextIter    start, end;

            view = gtk_bin_get_child (GTK_BIN (widget));
            buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));

            gtk_text_buffer_get_start_iter (buffer, &start);
            gtk_text_buffer_get_end_iter (buffer, &end);

            g_free (arg_value->sfa_value);
            arg_value->sfa_value = gtk_text_buffer_get_text (buffer,
                                                             &start, &end,
                                                             FALSE);
          }
          break;

        case SF_ADJUSTMENT:
        case SF_FILENAME:
        case SF_DIRNAME:
        case SF_FONT:
        case SF_PALETTE:
        case SF_PATTERN:
        case SF_GRADIENT:
        case SF_BRUSH:
        case SF_OPTION:
        case SF_ENUM:
          break;
        }
    }

  command = script_fu_script_get_command (script);

  /*  run the command through the interpreter  */
  output = g_string_new (NULL);
  ts_register_output_func (ts_gstring_output_func, output);

  gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_PLUGIN);

  if (ts_interpret_string (command))
    {
      gchar *message = g_strdup_printf (_("Error while executing %s:"),
                                        script->name);

      g_message ("%s\n\n%s", message, output->str);
      g_free (message);
    }

  gimp_plugin_set_pdb_error_handler (GIMP_PDB_ERROR_HANDLER_INTERNAL);

  g_string_free (output, TRUE);

  g_free (command);
}