Commit b91a3dd2 authored by Manish Singh's avatar Manish Singh Committed by Manish Singh

make libgimpprocbrowser a libtooled library.

2004-11-17  Manish Singh  <yosh@gimp.org>

        * plug-ins/dbbrowser/Makefile.am: make libgimpprocbrowser a libtooled
        library.

        * plug-ins/dbbrowser/gimpprocbrowser.[ch]: add a user_data pointer
        for GimpProcBrowserApplyCallback.

        * plug-ins/dbbrowser/gimpprocbrowser.c: only convert the name to
        scheme style if scheme_names in the proc info pane too.

        * plug-ins/dbbrowser/procedure-browser.c
        * plug-ins/script-fu/script-fu-console.c: pass NULL as user_data.

        * plug-ins/script-fu/Makefile.am: reference libgimpprocbrowser.la.

        * plug-ins/pygimp/Makefile.am
        * plug-ins/pygimp/procbrowser.c: new module, which wraps
        libgimprocbrowser.

        * plug-ins/pygimp/gimpmodule.c
        * plug-ins/pygimp/pygimp.h
        * plug-ins/pygimp/pygimp-pdb.c: export GimpPDBFunction so other
        modules can use it.

        * plug-ins/pygimp/plug-ins/pdbbrowse.py
        * plug-ins/pygimp/plug-ins/gimpcons.py: use gimpprocbrowser.
parent 235bb408
2004-11-17 Manish Singh <yosh@gimp.org>
* plug-ins/dbbrowser/Makefile.am: make libgimpprocbrowser a libtooled
library.
* plug-ins/dbbrowser/gimpprocbrowser.[ch]: add a user_data pointer
for GimpProcBrowserApplyCallback.
* plug-ins/dbbrowser/gimpprocbrowser.c: only convert the name to
scheme style if scheme_names in the proc info pane too.
* plug-ins/dbbrowser/procedure-browser.c
* plug-ins/script-fu/script-fu-console.c: pass NULL as user_data.
* plug-ins/script-fu/Makefile.am: reference libgimpprocbrowser.la.
* plug-ins/pygimp/Makefile.am
* plug-ins/pygimp/procbrowser.c: new module, which wraps
libgimprocbrowser.
* plug-ins/pygimp/gimpmodule.c
* plug-ins/pygimp/pygimp.h
* plug-ins/pygimp/pygimp-pdb.c: export GimpPDBFunction so other
modules can use it.
* plug-ins/pygimp/plug-ins/pdbbrowse.py
* plug-ins/pygimp/plug-ins/gimpcons.py: use gimpprocbrowser.
2004-11-17 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/script-fu-interface.c: added a utility
......
......@@ -81,6 +81,7 @@ typedef struct
gboolean scheme_names;
GimpProcBrowserApplyCallback apply_callback;
gpointer user_data;
} GimpDBBrowser;
......@@ -104,7 +105,8 @@ static void browser_convert_string (gchar *str);
GtkWidget *
gimp_proc_browser_dialog_new (gboolean scheme_names,
GimpProcBrowserApplyCallback apply_callback)
GimpProcBrowserApplyCallback apply_callback,
gpointer user_data)
{
GimpDBBrowser *browser;
GtkWidget *paned;
......@@ -118,6 +120,7 @@ gimp_proc_browser_dialog_new (gboolean scheme_names,
browser->scheme_names = scheme_names ? TRUE : FALSE;
browser->apply_callback = apply_callback;
browser->user_data = user_data;
if (apply_callback)
{
......@@ -357,7 +360,8 @@ browser_response (GtkWidget *widget,
browser->n_params,
browser->n_return_vals,
browser->params,
browser->return_vals);
browser->return_vals,
browser->user_data);
break;
case RESPONSE_SEARCH:
......@@ -440,7 +444,9 @@ browser_response (GtkWidget *widget,
gchar *label;
label = g_strdup (proc_list[i]);
browser_convert_string (label);
if (browser->scheme_names)
browser_convert_string (label);
gtk_list_store_append (browser->store, &iter);
gtk_list_store_set (browser->store, &iter,
......
......@@ -121,7 +121,7 @@ run (const gchar *name,
gimp_ui_init ("dbbrowser", FALSE);
gtk_quit_add_destroy (1, (GtkObject *)
gimp_proc_browser_dialog_new (FALSE, NULL));
gimp_proc_browser_dialog_new (FALSE, NULL, NULL));
gtk_main ();
gdk_flush ();
......
......@@ -14,10 +14,10 @@ AM_LDFLAGS = $(mwindows)
libexecdir = $(gimpplugindir)/plug-ins
noinst_LIBRARIES = libgimpprocbrowser.a
noinst_LTLIBRARIES = libgimpprocbrowser.la
libexec_PROGRAMS = plugin-browser procedure-browser
libgimpprocbrowser_a_SOURCES = \
libgimpprocbrowser_la_SOURCES = \
gimpprocbox.c \
gimpprocbox.h \
gimpprocbrowser.c \
......@@ -40,7 +40,7 @@ INCLUDES = \
-I$(includedir)
LDADD = \
libgimpprocbrowser.a \
libgimpprocbrowser.la \
$(libgimpui) \
$(libgimpwidgets) \
$(libgimp) \
......
......@@ -81,6 +81,7 @@ typedef struct
gboolean scheme_names;
GimpProcBrowserApplyCallback apply_callback;
gpointer user_data;
} GimpDBBrowser;
......@@ -104,7 +105,8 @@ static void browser_convert_string (gchar *str);
GtkWidget *
gimp_proc_browser_dialog_new (gboolean scheme_names,
GimpProcBrowserApplyCallback apply_callback)
GimpProcBrowserApplyCallback apply_callback,
gpointer user_data)
{
GimpDBBrowser *browser;
GtkWidget *paned;
......@@ -118,6 +120,7 @@ gimp_proc_browser_dialog_new (gboolean scheme_names,
browser->scheme_names = scheme_names ? TRUE : FALSE;
browser->apply_callback = apply_callback;
browser->user_data = user_data;
if (apply_callback)
{
......@@ -357,7 +360,8 @@ browser_response (GtkWidget *widget,
browser->n_params,
browser->n_return_vals,
browser->params,
browser->return_vals);
browser->return_vals,
browser->user_data);
break;
case RESPONSE_SEARCH:
......@@ -440,7 +444,9 @@ browser_response (GtkWidget *widget,
gchar *label;
label = g_strdup (proc_list[i]);
browser_convert_string (label);
if (browser->scheme_names)
browser_convert_string (label);
gtk_list_store_append (browser->store, &iter);
gtk_list_store_set (browser->store, &iter,
......
......@@ -35,11 +35,13 @@ typedef void (* GimpProcBrowserApplyCallback) (const gchar *proc_name,
gint n_params,
gint n_return_vals,
const GimpParamDef *params,
const GimpParamDef *return_vals);
const GimpParamDef *return_vals,
gpointer user_data);
GtkWidget * gimp_proc_browser_dialog_new (gboolean scheme_names,
GimpProcBrowserApplyCallback apply_callback);
GimpProcBrowserApplyCallback apply_callback,
gpointer user_data);
#endif /* __GIMP_PROC_BROWSER_H__ */
......@@ -121,7 +121,7 @@ run (const gchar *name,
gimp_ui_init ("dbbrowser", FALSE);
gtk_quit_add_destroy (1, (GtkObject *)
gimp_proc_browser_dialog_new (FALSE, NULL));
gimp_proc_browser_dialog_new (FALSE, NULL, NULL));
gtk_main ();
gdk_flush ();
......
......@@ -5,16 +5,17 @@ libgimpwidgets = $(top_builddir)/libgimpwidgets/libgimpwidgets-$(GIMP_API_VERSIO
libgimp = $(top_builddir)/libgimp/libgimp-$(GIMP_API_VERSION).la
libgimpcolor = $(top_builddir)/libgimpcolor/libgimpcolor-$(GIMP_API_VERSION).la
libgimpbase = $(top_builddir)/libgimpbase/libgimpbase-$(GIMP_API_VERSION).la
libgimpprocbrowser = $(top_builddir)/plug-ins/dbbrowser/libgimpprocbrowser.la
SUBDIRS = doc plug-ins
AM_CFLAGS = $(PYGIMP_EXTRA_CFLAGS)
INCLUDES = -I$(top_srcdir) $(PYTHON_INCLUDES) $(GLIB_CFLAGS)
INCLUDES = -I$(top_srcdir) $(PYTHON_INCLUDES) $(PYGTK_CFLAGS) $(GTK_CFLAGS)
pygimpdir = $(gimpplugindir)/python
pygimp_LTLIBRARIES = gimpmodule.la
pygimp_LTLIBRARIES = gimpmodule.la gimpprocbrowsermodule.la
gimpmodule_la_SOURCES = \
gimpmodule.c \
......@@ -36,6 +37,22 @@ gimpmodule_la_LIBADD = \
$(GLIB_LIBS) \
$(RT_LIBS)
gimpprocbrowsermodule_la_SOURCES = \
procbrowser.c
gimpprocbrowsermodule_la_LDFLAGS = -module -avoid-version
gimpprocbrowsermodule_la_LIBADD = \
$(libgimpprocbrowser) \
$(libgimpui) \
$(libgimpwidgets) \
$(libgimp) \
$(libgimpcolor) \
$(libgimpbase) \
$(GTK_LIBS) \
$(RT_LIBS) \
$(INTLLIBS)
pygimp_PYTHON = \
gimpplugin.py \
gimpenums.py \
......
......@@ -1259,6 +1259,12 @@ initgimp()
PyDict_SetItemString(d, "PixelRgn", (PyObject *)&PyGimpPixelRgn_Type);
PyDict_SetItemString(d, "Parasite", (PyObject *)&PyGimpParasite_Type);
/* these are private, for use in gimpprocbrowser */
PyDict_SetItemString(d, "_PDBFunction",
(PyObject *)&PyGimpPDBFunction_Type);
PyDict_SetItemString(d, "_pdb_function_new",
PyCObject_FromVoidPtr(pygimp_pdb_function_new, NULL));
PyDict_SetItemString(d, "version",
i=Py_BuildValue("(iii)",
gimp_major_version,
......
......@@ -47,29 +47,42 @@ def plug_in_python_fu_console():
cons = gtkcons.Console(namespace=namespace, quit_cb=bye)
def browse(button, cons):
import pygtk
pygtk.require('2.0')
import gimpprocbrowser
import gtk, pdbbrowse
def on_apply(proc):
cmd = ''
def ok_clicked(button, browse, cons=cons):
cons.line.set_text(browse.cmd)
browse.destroy()
if len(proc.return_vals) > 0:
cmd = ', '.join([x[1] for x in proc.return_vals]) + ' = '
win = pdbbrowse.BrowseWin(ok_button=ok_clicked)
win.connect("destroy", bye)
win.set_modal(TRUE)
win.show()
gtk.main()
if '-' in proc.proc_name:
cmd = cmd + "pdb['%s']" % proc.proc_name
else:
cmd = cmd + "pdb.%s" % proc.proc_name
if len(proc.params) > 0 and proc.params[0][1] == 'run_mode':
params = proc.params[1:]
else:
params = proc.params
cmd = cmd + "(%s)" % ', '.join([x[1] for x in params])
cons.line.set_text(cmd)
dlg = gimpprocbrowser.dialog_new(on_apply)
button = gtk.Button("Browse")
button.connect("clicked", browse, cons)
cons.inputbox.pack_end(button, expand=FALSE)
button.show()
win.add(cons)
cons.show()
win.set_default_size(475, 300)
win.show()
cons.init()
# flush the displays every half second
......
......@@ -18,312 +18,30 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
from gimpfu import *
import gimpenums
import string
BrowseWin = None
pars = filter(lambda x: x[:4] == 'PDB_', dir(gimpenums))
partypes = [''] * len(pars)
for i in pars:
partypes[gimpenums.__dict__[i]] = i[4:]
del pars, i
def define_browse_win():
def plug_in_pdb_browse():
import pygtk
pygtk.require('2.0')
import gtk
global BrowseWin
class BrowseWin(gtk.Window):
def __init__(self, ok_button=None):
gtk.Window.__init__(self)
self.set_title("PDB Browser")
vbox = gtk.VBox(FALSE, 5)
vbox.set_border_width(2)
self.add(vbox)
vbox.show()
paned = gtk.HPaned()
vbox.pack_start(paned)
paned.show()
listsw = gtk.ScrolledWindow()
listsw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
paned.add1(listsw)
listsw.show()
self.list = gtk.CList(1)
self.list.set_column_auto_resize(0, TRUE)
self.list.set_selection_mode(gtk.SELECTION_BROWSE)
listsw.add(self.list)
self.list.show()
self.update_list()
self.list.connect("select_row", self.display)
self.infosw = gtk.ScrolledWindow()
self.infosw.set_policy(gtk.POLICY_AUTOMATIC,
gtk.POLICY_AUTOMATIC)
paned.add2(self.infosw)
self.infosw.show()
self.info = None
paned.set_position(150)
self.cmd = None
self.display(self.list, 0, -1, None)
hbox = gtk.HBox(FALSE, 5)
vbox.pack_start(hbox, expand=FALSE)
hbox.show()
entry = gtk.Entry()
hbox.pack_start(entry, expand=FALSE)
entry.show()
button = gtk.Button("Search by name")
button.connect("clicked", self.search_name, entry)
hbox.pack_start(button, expand=FALSE)
button.show()
button = gtk.Button("Search by blurb")
button.connect("clicked", self.search_blurb, entry)
hbox.pack_start(button, expand=FALSE)
button.show()
button = gtk.Button("Close")
button.connect("clicked", lambda btn, win: win.destroy(), self)
hbox.pack_end(button, expand=FALSE)
button.show()
if ok_button:
button = gtk.Button("OK")
button.connect("clicked", ok_button, self)
hbox.pack_end(button, expand=FALSE)
button.show()
self.set_default_size(500, 300)
def search_name(self, button, entry):
self.update_list(name=entry.get_text())
def search_blurb(self, button, entry):
self.update_list(blurb=entry.get_text())
def update_list(self, name='.*', blurb='.*'):
self.pdblist = pdb.query(name,blurb,'.*','.*','.*','.*','.*')
self.pdblist.sort()
self.list.clear()
for item in self.pdblist:
self.list.append([item])
def display(self, clist, row, column, event):
proc = pdb[clist.get_text(row, 0)]
self.info = gtk.Table(1, 5, FALSE);
row = 0
label = gtk.Label("Name:")
label.set_alignment(1.0, 0.5)
self.info.attach(label, 0,1, row,row+1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
label.show()
label = gtk.Entry()
label.set_text(proc.proc_name)
label.set_editable(FALSE)
self.info.attach(label, 1,4, row,row+1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
label.show()
row = row + 1
label = gtk.Label("Blurb:")
label.set_alignment(1.0, 0.5)
self.info.attach(label, 0,1, row,row+1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
label.show()
label = gtk.Label(proc.proc_blurb)
label.set_alignment(0.0, 0.5)
self.info.attach(label, 1,4, row,row+1,
yoptions=gtk.FILL)
label.show()
row = row + 1
label = gtk.Label("Copyright:")
label.set_alignment(1.0, 0.5)
self.info.attach(label, 0,1, row,row+1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
label.show()
label = gtk.Label(proc.proc_date+", "+proc.proc_copyright)
label.set_alignment(0.0, 0.5)
self.info.attach(label, 1,4, row,row+1,
yoptions=gtk.FILL)
label.show()
row = row + 1
label = gtk.Label("Author:")
label.set_alignment(1.0, 0.5)
self.info.attach(label, 0,1, row,row+1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
label.show()
label = gtk.Label(proc.proc_author)
label.set_alignment(0.0, 0.5)
self.info.attach(label, 1,4, row,row+1,
yoptions=gtk.FILL)
label.show()
row = row + 1
hsep = gtk.HSeparator()
self.info.attach(hsep, 0,4, row,row+1,
yoptions=gtk.FILL)
hsep.show()
row = row + 1
if len(proc.params) > 0:
label = gtk.Label("In:")
label.set_alignment(1.0, 0.5)
self.info.attach(label, 0,1, row,row+len(proc.params),
xoptions=gtk.FILL, yoptions=gtk.FILL)
label.show()
for tp, name, desc in proc.params:
label = gtk.Label(name)
label.set_alignment(0.0, 0.5)
self.info.attach(label, 1,2, row,row+1,
xoptions=gtk.FILL,
yoptions=gtk.FILL)
label.show()
label = gtk.Label(partypes[tp])
label.set_alignment(0.0, 0.5)
self.info.attach(label, 2,3, row,row+1,
xoptions=gtk.FILL,
yoptions=gtk.FILL)
label.show()
label = gtk.Label(desc)
label.set_alignment(0.0, 0.5)
self.info.attach(label, 3,4, row,row+1,
yoptions=gtk.FILL)
label.show()
row = row + 1
hsep = gtk.HSeparator()
self.info.attach(hsep, 0,4, row,row+1,
yoptions=gtk.FILL)
hsep.show()
row = row + 1
if len(proc.return_vals) > 0:
label = gtk.Label("Out:")
label.set_alignment(1.0, 0.5)
self.info.attach(label, 0,1,
row,row+len(proc.return_vals),
xoptions=gtk.FILL, yoptions=gtk.FILL)
label.show()
for tp, name, desc in proc.return_vals:
label = gtk.Label(name)
label.set_alignment(0.0, 0.5)
self.info.attach(label, 1,2, row,row+1,
xoptions=gtk.FILL,
yoptions=gtk.FILL)
label.show()
label = gtk.Label(partypes[tp])
label.set_alignment(0.0, 0.5)
self.info.attach(label, 2,3, row,row+1,
xoptions=gtk.FILL,
yoptions=gtk.FILL)
label.show()
label = gtk.Label(desc)
label.set_alignment(0.0, 0.5)
self.info.attach(label, 3,4, row,row+1,
yoptions=gtk.FILL)
label.show()
row = row + 1
hsep = gtk.HSeparator()
self.info.attach(hsep, 0,4, row,row+1,
yoptions=gtk.FILL)
hsep.show()
row = row + 1
label = gtk.Label("Help:")
label.set_alignment(1.0, 0.5)
self.info.attach(label, 0,1, row,row+1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
label.show()
label = gtk.Label(proc.proc_help)
label.set_alignment(0.0, 0.5)
label.set_justify(gtk.JUSTIFY_LEFT)
label.set_line_wrap(TRUE)
label.set_size_request(300, -1)
self.info.attach(label, 1,4, row,row+1,
yoptions=gtk.FILL)
label.show()
row = row + 1
self.info.set_col_spacings(5)
self.info.set_row_spacings(3)
self.info.set_border_width(3)
if self.infosw.child:
self.infosw.remove(self.infosw.child)
self.infosw.add_with_viewport(self.info)
self.info.show()
# now setup the self.cmd
self.cmd = ''
if len(proc.return_vals) > 0:
self.cmd = string.join(
map(lambda x: x[1], proc.return_vals), ', ') + ' = '
if '-' in proc.proc_name:
self.cmd = self.cmd + "pdb['" + proc.proc_name + "']"
else:
self.cmd = self.cmd + "pdb." + proc.proc_name
if len(proc.params) > 0 and proc.params[0][1] == 'run_mode':
params = proc.params[1:]
else:
params = proc.params
self.cmd = self.cmd + "(" + string.join(
map(lambda x: x[1], params), ', ') + ")"
if __name__ == '__main__':
def plug_in_pdb_browse():
import pygtk
pygtk.require('2.0')
import gtk
gtk.rc_parse(gimp.gtkrc())
define_browse_win()
def bye(*args):
gtk.main_quit()
win = BrowseWin()
win.connect("destroy", bye)
win.show()
gtk.main()
register(
"python_fu_pdb_browse",
"Browse the Procedural Database",
"Pick a PDB proc, and read the information",
"James Henstridge",
"James Henstridge",
"1997-1999",
"<Toolbox>/Xtns/Python-Fu/_PDB Browser",
"*",
[],
[],
plug_in_pdb_browse)
main()
else:
define_browse_win()
gtk.rc_parse(gimp.gtkrc())
import gimpprocbrowser
dlg = gimpprocbrowser.dialog_new()
gtk.main()
register(
"python_fu_pdb_browse",
"Browse the Procedural Database",
"Pick a PDB proc, and read the information",
"James Henstridge",
"James Henstridge",
"1997-1999",
"<Toolbox>/Xtns/Python-Fu/_PDB Browser",
"*",
[],
[],
plug_in_pdb_browse)
main()
/* -*- Mode: C; c-basic-offset: 4 -*-
Gimp-Python - allows the writing of Gimp plugins in Python.
Copyright (C) 2004 Manish Singh <yosh@gimp.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#include <Python.h>
#include <structseq.h>
#include <gtk/gtk.h>
#include <pygobject.h>
#include <pygtk/pygtk.h>
#include <libgimp/gimp.h>
#include <plug-ins/dbbrowser/gimpprocbrowser.h>
typedef PyObject *(*PyGimpPDBFunctionNew)(const char *name, const char *blurb,
const char *help, const char *author,
const char *copyright,
const char *date,
GimpPDBProcType proc_type,
int n_params, int n_return_vals,
GimpParamDef *params,
GimpParamDef *return_vals);
typedef struct
{
PyObject *func;
PyObject *data;
} ProxyData;
static PyTypeObject *PyGimpPDBFunction_Type;
static PyGimpPDBFunctionNew pygimp_pdb_function_new;
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)
{
ProxyData *proxy_data = user_data;
GimpParamDef *params_copy, *return_vals_copy;
PyObject *pdb_func, *ret;
params_copy = copy_paramdefs(params,