Quick and dirty restore of browser functionality.

2005-08-02  Manish Singh  <yosh@gimp.org>

        * plug-ins/pygimp/procbrowser.c: Quick and dirty restore of browser
        functionality.
This commit is contained in:
Manish Singh 2005-08-02 18:00:10 +00:00 committed by Manish Singh
parent 40dd411be3
commit 00d1d29902
2 changed files with 69 additions and 45 deletions

View File

@ -1,3 +1,8 @@
2005-08-02 Manish Singh <yosh@gimp.org>
* plug-ins/pygimp/procbrowser.c: Quick and dirty restore of browser
functionality.
2005-08-02 Michael Natterer <mitch@gimp.org>
* libgimp/gimpuitypes.h: added GimpProcBrowserDialog typedef here.

View File

@ -23,7 +23,8 @@
#include <gtk/gtk.h>
#include <libgimpwidgets/gimpwidgets.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include <pygobject.h>
#include <pygtk/pygtk.h>
@ -38,51 +39,57 @@ typedef struct
} ProxyData;
static GimpParamDef *
copy_paramdefs(const GimpParamDef *paramdefs, gint n_params)
{
GimpParamDef *copy;
copy = g_new(GimpParamDef, n_params);
while (n_params--)
{
copy[n_params].type = paramdefs[n_params].type;
copy[n_params].name = g_strdup(paramdefs[n_params].name);
copy[n_params].description = g_strdup(paramdefs[n_params].description);
}
return copy;
}
static void
proxy_apply_callback(const gchar *name,
const gchar *blurb,
const gchar *help,
const gchar *author,
const gchar *copyright,
const gchar *date,
GimpPDBProcType proc_type,
gint n_params,
gint n_return_vals,
const GimpParamDef *params,
const GimpParamDef *return_vals,
gpointer user_data)
proxy_apply_callback(GtkWidget *widget,
gint response_id,
ProxyData *proxy_data)
{
ProxyData *proxy_data = user_data;
GimpParamDef *params_copy, *return_vals_copy;
PyObject *pdb_func, *ret;
PyObject *pdb_func, *ret;
gchar *name;
gchar *blurb;
gchar *help;
gchar *author;
gchar *copyright;
gchar *date;
GimpPDBProcType proc_type;
gint n_params;
gint n_return_vals;
GimpParamDef *params;
GimpParamDef *return_vals;
params_copy = copy_paramdefs(params, n_params);
return_vals_copy = copy_paramdefs(return_vals, n_return_vals);
if (response_id != GTK_RESPONSE_APPLY) {
if (proxy_data)
gtk_widget_destroy (widget);
else
gtk_main_quit ();
return;
}
if (proxy_data == NULL)
return;
name = gimp_proc_browser_dialog_get_selected(GIMP_PROC_BROWSER_DIALOG (widget));
if (name == NULL)
return;
gimp_procedural_db_proc_info(name, &blurb, &help, &author, &copyright,
&date, &proc_type,
&n_params, &n_return_vals,
&params, &return_vals);
pdb_func = pygimp_pdb_function_new(name, blurb, help, author, copyright,
date, proc_type, n_params, n_return_vals,
params_copy, return_vals_copy);
params, return_vals);
if (pdb_func == NULL) {
PyErr_Print();
return;
gimp_destroy_paramdefs(params, n_params);
gimp_destroy_paramdefs(return_vals, n_return_vals);
goto bail;
}
if (proxy_data->data)
@ -97,13 +104,24 @@ proxy_apply_callback(const gchar *name,
PyErr_Print();
Py_DECREF(pdb_func);
bail:
g_free(name);
g_free(blurb);
g_free(help);
g_free(author);
g_free(copyright);
g_free(date);
}
static void
proxy_cleanup(gpointer data, GObject *obj)
proxy_cleanup(gpointer data, GClosure *closure)
{
ProxyData *proxy_data = data;
if (!data)
return;
Py_DECREF(proxy_data->func);
Py_XDECREF(proxy_data->data);
@ -113,11 +131,10 @@ proxy_cleanup(gpointer data, GObject *obj)
static PyObject *
proc_browser_dialog_new(PyObject *self, PyObject *args, PyObject *kwargs)
{
#if 0
PyObject *py_func = Py_None, *py_data = Py_None;
GimpProcBrowserApplyCallback proxy_func = NULL;
ProxyData *proxy_data = NULL;
GObject *dlg;
gboolean has_apply = FALSE;
static char *kwlist[] = { "apply_callback", "data", NULL };
@ -127,7 +144,7 @@ proc_browser_dialog_new(PyObject *self, PyObject *args, PyObject *kwargs)
if (py_func != Py_None) {
if (PyCallable_Check(py_func))
proxy_func = proxy_apply_callback;
has_apply = TRUE;
else {
PyErr_SetString(PyExc_TypeError,
"apply_callback must be a callable object or None");
@ -145,13 +162,15 @@ proc_browser_dialog_new(PyObject *self, PyObject *args, PyObject *kwargs)
}
}
dlg = G_OBJECT(gimp_proc_browser_dialog_new(FALSE, proxy_func, proxy_data));
dlg = G_OBJECT(gimp_proc_browser_dialog_new(FALSE, has_apply));
if (proxy_data)
g_object_weak_ref(dlg, proxy_cleanup, proxy_data);
g_signal_connect_data(dlg, "response",
G_CALLBACK(proxy_apply_callback), proxy_data,
proxy_cleanup, 0);
gtk_widget_show(GTK_WIDGET(dlg));
return pygobject_new(dlg);
#endif
}
/* List of methods defined in the module */