Commit 00d1d299 authored by Manish Singh's avatar Manish Singh Committed by Manish Singh

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.
parent 40dd411b
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.
......
......@@ -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)
static void
proxy_apply_callback(GtkWidget *widget,
gint response_id,
ProxyData *proxy_data)
{
GimpParamDef *copy;
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;
if (response_id != GTK_RESPONSE_APPLY) {
if (proxy_data)
gtk_widget_destroy (widget);
else
gtk_main_quit ();
copy = g_new(GimpParamDef, n_params);
return;
}
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);
}
if (proxy_data == NULL)
return;
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)
{
ProxyData *proxy_data = user_data;
GimpParamDef *params_copy, *return_vals_copy;
PyObject *pdb_func, *ret;
name = gimp_proc_browser_dialog_get_selected(GIMP_PROC_BROWSER_DIALOG (widget));
if (name == NULL)
return;
params_copy = copy_paramdefs(params, n_params);
return_vals_copy = copy_paramdefs(return_vals, n_return_vals);
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));
g_signal_connect_data(dlg, "response",
G_CALLBACK(proxy_apply_callback), proxy_data,
proxy_cleanup, 0);
if (proxy_data)
g_object_weak_ref(dlg, proxy_cleanup, proxy_data);
gtk_widget_show(GTK_WIDGET(dlg));
return pygobject_new(dlg);
#endif
}
/* List of methods defined in the module */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment