some more updates

This commit is contained in:
James Henstridge 2002-08-28 16:18:18 +00:00
parent dc70b17ac0
commit 698bd613cc
4 changed files with 374 additions and 407 deletions

View File

@ -44,12 +44,12 @@ mode. Note that the the PF_SPINNER and PF_SLIDER types expect a fifth
element in their description tuple -- a 3-tuple of the form (lower,upper,step),
which defines the limits for the slider or spinner.'''
import string; _string = string; del string
import string as _string
import gimp
from gimpenums import *
pdb = gimp.pdb
error = "gimpfu.error"
class error(RuntimeError):pass
PF_INT8 = PDB_INT8
PF_INT16 = PDB_INT16
@ -90,329 +90,303 @@ PF_PATTERN = 1006
PF_GRADIENT = 1007
_type_mapping = {
PF_INT8 : PDB_INT8,
PF_INT16 : PDB_INT16,
PF_INT32 : PDB_INT32,
PF_FLOAT : PDB_FLOAT,
PF_STRING : PDB_STRING,
PF_INT8ARRAY : PDB_INT8ARRAY,
PF_INT16ARRAY : PDB_INT16ARRAY,
PF_INT32ARRAY : PDB_INT32ARRAY,
PF_FLOATARRAY : PDB_FLOATARRAY,
PF_STRINGARRAY : PDB_STRINGARRAY,
PF_COLOUR : PDB_COLOR,
PF_REGION : PDB_REGION,
PF_IMAGE : PDB_IMAGE,
PF_LAYER : PDB_LAYER,
PF_CHANNEL : PDB_CHANNEL,
PF_DRAWABLE : PDB_DRAWABLE,
PF_INT8 : PDB_INT8,
PF_INT16 : PDB_INT16,
PF_INT32 : PDB_INT32,
PF_FLOAT : PDB_FLOAT,
PF_STRING : PDB_STRING,
PF_INT8ARRAY : PDB_INT8ARRAY,
PF_INT16ARRAY : PDB_INT16ARRAY,
PF_INT32ARRAY : PDB_INT32ARRAY,
PF_FLOATARRAY : PDB_FLOATARRAY,
PF_STRINGARRAY : PDB_STRINGARRAY,
PF_COLOUR : PDB_COLOR,
PF_REGION : PDB_REGION,
PF_IMAGE : PDB_IMAGE,
PF_LAYER : PDB_LAYER,
PF_CHANNEL : PDB_CHANNEL,
PF_DRAWABLE : PDB_DRAWABLE,
PF_TOGGLE : PDB_INT32,
PF_SLIDER : PDB_FLOAT,
PF_SPINNER : PDB_INT32,
PF_TOGGLE : PDB_INT32,
PF_SLIDER : PDB_FLOAT,
PF_SPINNER : PDB_INT32,
PF_FONT : PDB_STRING,
PF_FILE : PDB_STRING,
PF_BRUSH : PDB_STRING,
PF_PATTERN : PDB_STRING,
PF_GRADIENT : PDB_STRING
PF_FONT : PDB_STRING,
PF_FILE : PDB_STRING,
PF_BRUSH : PDB_STRING,
PF_PATTERN : PDB_STRING,
PF_GRADIENT : PDB_STRING
}
_registered_plugins_ = {}
def register(func_name, blurb, help, author, copyright, date, menupath,
imagetypes, params, results, function):
'''This is called to register a new plugin.'''
# First perform some sanity checks on the data
def letterCheck(str):
allowed = _string.letters + _string.digits + '_'
for ch in str:
if not ch in allowed:
return 0
else:
return 1
if not letterCheck(func_name):
raise error, "function name contains ileagal characters"
for ent in params:
if len(ent) < 4:
raise error, "sequence not long enough for "+ent[0]
if type(ent[0]) != type(42):
raise error, "parameter types must be integers"
if not letterCheck(ent[1]):
raise error,"parameter name contains ilegal characters"
for ent in results:
if len(ent) < 3:
raise error, "sequence not long enough for "+ent[0]
if type(ent[0]) != type(42):
raise error, "result types must be integers"
if not letterCheck(ent[1]):
raise error,"result name contains ilegal characters"
if menupath[:8] == '<Image>/':
plugin_type = PLUGIN
elif menupath[:10] == '<Toolbox>/':
plugin_type = EXTENSION
'''This is called to register a new plugin.'''
# First perform some sanity checks on the data
def letterCheck(str):
allowed = _string.letters + _string.digits + '_'
for ch in str:
if not ch in allowed:
return 0
else:
raise error, "menu path must start with <Image> or <Toolbox>"
return 1
if not letterCheck(func_name):
raise error, "function name contains ileagal characters"
for ent in params:
if len(ent) < 4:
raise error, "sequence not long enough for "+ent[0]
if type(ent[0]) != type(42):
raise error, "parameter types must be integers"
if not letterCheck(ent[1]):
raise error,"parameter name contains ilegal characters"
for ent in results:
if len(ent) < 3:
raise error, "sequence not long enough for "+ent[0]
if type(ent[0]) != type(42):
raise error, "result types must be integers"
if not letterCheck(ent[1]):
raise error,"result name contains ilegal characters"
if menupath[:8] == '<Image>/':
plugin_type = PLUGIN
elif menupath[:10] == '<Toolbox>/':
plugin_type = EXTENSION
else:
raise error, "menu path must start with <Image> or <Toolbox>"
if not func_name[:7] == 'python_' and \
not func_name[:10] == 'extension_' and \
not func_name[:8] == 'plug_in_':
func_name = 'python_fu_' + func_name
if not func_name[:7] == 'python_' and \
not func_name[:10] == 'extension_' and \
not func_name[:8] == 'plug_in_':
func_name = 'python_fu_' + func_name
_registered_plugins_[func_name] = (blurb, help, author, copyright,
date, menupath, imagetypes,
plugin_type, params, results,
function)
_registered_plugins_[func_name] = (blurb, help, author, copyright,
date, menupath, imagetypes,
plugin_type, params, results,
function)
def _query():
for plugin in _registered_plugins_.keys():
(blurb, help, author, copyright, date,
menupath, imagetypes, plugin_type,
params, results, function) = _registered_plugins_[plugin]
for plugin in _registered_plugins_.keys():
(blurb, help, author, copyright, date,
menupath, imagetypes, plugin_type,
params, results, function) = _registered_plugins_[plugin]
fn = lambda x: (_type_mapping[x[0]], x[1], x[2])
params = map(fn, params)
# add the run mode argument ...
params.insert(0, (PDB_INT32, "run_mode",
"Interactive, Non-Interactive"))
if plugin_type == PLUGIN:
params.insert(1, (PDB_IMAGE, "image",
"The image to work on"))
params.insert(2, (PDB_DRAWABLE, "drawable",
"The drawable to work on"))
results = map(fn, results)
gimp.install_procedure(plugin, blurb, help, author, copyright,
date, menupath, imagetypes, plugin_type,
params, results)
fn = lambda x: (_type_mapping[x[0]], x[1], x[2])
params = map(fn, params)
# add the run mode argument ...
params.insert(0, (PDB_INT32, "run_mode",
"Interactive, Non-Interactive"))
if plugin_type == PLUGIN:
params.insert(1, (PDB_IMAGE, "image",
"The image to work on"))
params.insert(2, (PDB_DRAWABLE, "drawable",
"The drawable to work on"))
results = map(fn, results)
gimp.install_procedure(plugin, blurb, help, author, copyright,
date, menupath, imagetypes, plugin_type,
params, results)
def _get_defaults(func_name):
import gimpshelf
(blurb, help, author, copyright, date,
menupath, imagetypes, plugin_type,
params, results, function) = _registered_plugins_[func_name]
import gimpshelf
(blurb, help, author, copyright, date,
menupath, imagetypes, plugin_type,
params, results, function) = _registered_plugins_[func_name]
key = "python-fu-save--" + func_name
if gimpshelf.shelf.has_key(key):
return gimpshelf.shelf[key]
else:
# return the default values
return map(lambda x: x[3], params)
key = "python-fu-save--" + func_name
if gimpshelf.shelf.has_key(key):
return gimpshelf.shelf[key]
else:
# return the default values
return map(lambda x: x[3], params)
def _set_defaults(func_name, defaults):
import gimpshelf
import gimpshelf
key = "python-fu-save--" + func_name
gimpshelf.shelf[key] = defaults
key = "python-fu-save--" + func_name
gimpshelf.shelf[key] = defaults
def _interact(func_name):
(blurb, help, author, copyright, date,
menupath, imagetypes, plugin_type,
params, results, function) = _registered_plugins_[func_name]
(blurb, help, author, copyright, date,
menupath, imagetypes, plugin_type,
params, results, function) = _registered_plugins_[func_name]
# short circuit for no parameters ...
if len(params) == 0: return []
# short circuit for no parameters ...
if len(params) == 0: return []
import gtk
import gimpui
import gtk
import gimpui
gtk.rc_parse(gimp.gtkrc())
gtk.rc_parse(gimp.gtkrc())
defaults = _get_defaults(func_name)
# define a mapping of param types to edit objects ...
class StringEntry(gtk.GtkEntry):
def __init__(self, default=''):
import gtk
gtk.GtkEntry.__init__(self)
self.set_text(str(default))
def get_value(self):
return self.get_text()
class IntEntry(StringEntry):
def get_value(self):
import string
return string.atoi(self.get_text())
class FloatEntry(StringEntry):
def get_value(self):
import string
return string.atof(self.get_text())
class ArrayEntry(StringEntry):
def get_value(self):
return eval(self.get_text())
class SliderEntry(gtk.GtkHScale):
# bounds is (upper, lower, step)
def __init__(self, default=0, bounds=(0, 100, 5)):
import gtk
self.adj = gtk.GtkAdjustment(default, bounds[0],
bounds[1], bounds[2],
bounds[2], bounds[2])
gtk.GtkHScale.__init__(self, self.adj)
def get_value(self):
return self.adj.value
class SpinnerEntry(gtk.GtkSpinButton):
# bounds is (upper, lower, step)
def __init__(self, default=0, bounds=(0, 100, 5)):
import gtk
self.adj = gtk.GtkAdjustment(default, bounds[0],
bounds[1], bounds[2],
bounds[2], bounds[2])
gtk.GtkSpinButton.__init__(self, self.adj, 1, 0)
def get_value(self):
return int(self.adj.value)
class ToggleEntry(gtk.GtkToggleButton):
def __init__(self, default=0):
import gtk
gtk.GtkToggleButton.__init__(self)
self.label = gtk.GtkLabel("No")
self.add(self.label)
self.label.show()
self.connect("toggled", self.changed)
self.set_active(default)
def changed(self, tog):
if tog.active:
self.label.set_text("Yes")
else:
self.label.set_text("No")
def get_value(self):
return self.get_active()
defaults = _get_defaults(func_name)
# define a mapping of param types to edit objects ...
class StringEntry(gtk.Entry):
def __init__(self, default=''):
import gtk
gtk.Entry.__init__(self)
self.set_text(str(default))
def get_value(self):
return self.get_text()
class IntEntry(StringEntry):
def get_value(self):
import string
return string.atoi(self.get_text())
class FloatEntry(StringEntry):
def get_value(self):
import string
return string.atof(self.get_text())
class ArrayEntry(StringEntry):
def get_value(self):
return eval(self.get_text())
class SliderEntry(gtk.HScale):
# bounds is (upper, lower, step)
def __init__(self, default=0, bounds=(0, 100, 5)):
import gtk
self.adj = gtk.Adjustment(default, bounds[0],
bounds[1], bounds[2],
bounds[2], bounds[2])
gtk.HScale.__init__(self, self.adj)
def get_value(self):
return self.adj.value
class SpinnerEntry(gtk.SpinButton):
# bounds is (upper, lower, step)
def __init__(self, default=0, bounds=(0, 100, 5)):
import gtk
self.adj = gtk.Adjustment(default, bounds[0],
bounds[1], bounds[2],
bounds[2], bounds[2])
gtk.SpinButton.__init__(self, self.adj, 1, 0)
def get_value(self):
return int(self.adj.value)
class ToggleEntry(gtk.ToggleButton):
def __init__(self, default=0):
import gtk
gtk.ToggleButton.__init__(self)
self.label = gtk.GtkLabel("No")
self.add(self.label)
self.label.show()
self.connect("toggled", self.changed)
self.set_active(default)
def changed(self, tog):
if tog.active:
self.label.set_text("Yes")
else:
self.label.set_text("No")
def get_value(self):
return self.get_active()
_edit_mapping = {
PF_INT8 : IntEntry,
PF_INT16 : IntEntry,
PF_INT32 : IntEntry,
PF_FLOAT : FloatEntry,
PF_STRING : StringEntry,
PF_INT8ARRAY : ArrayEntry,
PF_INT16ARRAY : ArrayEntry,
PF_INT32ARRAY : ArrayEntry,
PF_FLOATARRAY : ArrayEntry,
PF_STRINGARRAY : ArrayEntry,
PF_COLOUR : gimpui.ColourSelector,
PF_REGION : IntEntry, # should handle differently ...
PF_IMAGE : gimpui.ImageSelector,
PF_LAYER : gimpui.LayerSelector,
PF_CHANNEL : gimpui.ChannelSelector,
PF_DRAWABLE : gimpui.DrawableSelector,
_edit_mapping = {
PF_INT8 : IntEntry,
PF_INT16 : IntEntry,
PF_INT32 : IntEntry,
PF_FLOAT : FloatEntry,
PF_STRING : StringEntry,
PF_INT8ARRAY : ArrayEntry,
PF_INT16ARRAY : ArrayEntry,
PF_INT32ARRAY : ArrayEntry,
PF_FLOATARRAY : ArrayEntry,
PF_STRINGARRAY : ArrayEntry,
PF_COLOUR : gimpui.ColourSelector,
PF_REGION : IntEntry, # should handle differently ...
PF_IMAGE : gimpui.ImageSelector,
PF_LAYER : gimpui.LayerSelector,
PF_CHANNEL : gimpui.ChannelSelector,
PF_DRAWABLE : gimpui.DrawableSelector,
PF_TOGGLE : ToggleEntry,
PF_SLIDER : SliderEntry,
PF_SPINNER : SpinnerEntry,
PF_TOGGLE : ToggleEntry,
PF_SLIDER : SliderEntry,
PF_SPINNER : SpinnerEntry,
PF_FONT : gimpui.FontSelector,
PF_FILE : gimpui.FileSelector,
PF_BRUSH : gimpui.BrushSelector,
PF_PATTERN : gimpui.PatternSelector,
PF_GRADIENT : gimpui.GradientSelector,
}
PF_FONT : gimpui.FontSelector,
PF_FILE : gimpui.FileSelector,
PF_BRUSH : gimpui.BrushSelector,
PF_PATTERN : gimpui.PatternSelector,
PF_GRADIENT : gimpui.GradientSelector,
}
tooltips = gtk.GtkTooltips()
tooltips = gtk.Tooltips()
dialog = gtk.GtkDialog()
dialog.set_title(func_name)
table = gtk.GtkTable(len(params), 3, gtk.FALSE)
table.set_border_width(5)
table.set_row_spacings(2)
table.set_col_spacings(10)
dialog.vbox.pack_start(table)
table.show()
dialog = gtk.Dialog(func_name, None, 0,
(gtk.STOCK_OK, gtk.RESPONSE_OK,
gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
table = gtk.Table(len(params), 3, gtk.FALSE)
table.set_border_width(5)
table.set_row_spacings(2)
table.set_col_spacings(10)
dialog.vbox.pack_start(table)
table.show()
vbox = gtk.GtkVBox(gtk.FALSE, 15)
table.attach(vbox, 0,1, 0,len(params), xoptions=gtk.FILL)
vbox.show()
pix = _get_logo(vbox.get_colormap())
vbox.pack_start(pix, expand=gtk.FALSE)
pix.show()
vbox = gtk.VBox(gtk.FALSE, 15)
table.attach(vbox, 0,1, 0,len(params), xoptions=gtk.FILL)
vbox.show()
pix = _get_logo(vbox.get_colormap())
vbox.pack_start(pix, expand=gtk.FALSE)
pix.show()
label = gtk.GtkLabel(blurb)
label.set_line_wrap(TRUE)
label.set_justify(gtk.JUSTIFY_LEFT)
label.set_usize(100, -1)
vbox.pack_start(label, expand=gtk.FALSE)
label = gtk.Label(blurb)
label.set_line_wrap(TRUE)
label.set_justify(gtk.JUSTIFY_LEFT)
label.set_usize(100, -1)
vbox.pack_start(label, expand=gtk.FALSE)
label.show()
edit_wids = []
for i in range(len(params)):
type = params[i][0]
name = params[i][1]
desc = params[i][2]
def_val = defaults[i]
label = gtk.Label(name)
label.set_alignment(1.0, 0.5)
table.attach(label, 1,2, i,i+1, xoptions=gtk.FILL)
label.show()
edit_wids = []
for i in range(len(params)):
type = params[i][0]
name = params[i][1]
desc = params[i][2]
def_val = defaults[i]
if type in (PF_SPINNER, PF_SLIDER):
wid = _edit_mapping[type](def_val, params[i][4])
else:
wid = _edit_mapping[type](def_val)
table.attach(wid, 2,3, i,i+1)
tooltips.set_tip(wid, desc, None)
wid.show()
edit_wids.append(wid)
label = gtk.GtkLabel(name)
label.set_alignment(1.0, 0.5)
table.attach(label, 1,2, i,i+1, xoptions=gtk.FILL)
label.show()
if type in (PF_SPINNER, PF_SLIDER):
wid = _edit_mapping[type](def_val, params[i][4])
else:
wid = _edit_mapping[type](def_val)
table.attach(wid, 2,3, i,i+1)
tooltips.set_tip(wid, desc, None)
wid.show()
edit_wids.append(wid)
def delete_event(win, event=None):
import gtk
win.hide()
gtk.mainquit()
return TRUE
# this is a hack ...
finished = [ 0 ]
def ok_clicked(button, win=dialog, finished=finished):
import gtk
win.hide()
finished[0] = 1
gtk.mainquit()
b = gtk.GtkButton("OK")
b.set_flags(gtk.CAN_DEFAULT)
dialog.action_area.pack_start(b)
b.grab_default()
b.connect("clicked", ok_clicked)
b.show()
b = gtk.GtkButton("Cancel")
b.set_flags(gtk.CAN_DEFAULT)
dialog.action_area.pack_start(b)
b.connect("clicked", delete_event)
b.show()
dialog.show()
tooltips.enable()
# run the main loop
gtk.mainloop()
ret = None
if finished[0]:
# OK was clicked
ret = map(lambda wid: wid.get_value(), edit_wids)
_set_defaults(func_name, ret)
dialog.destroy()
return ret
tooltips.enable()
dialog.show()
response = dialog.run()
ret = None
if response = gtk.RESPONSE_OK:
# OK was clicked
ret = map(lambda wid: wid.get_value(), edit_wids)
_set_defaults(func_name, ret)
dialog.destroy()
return ret
def _run(func_name, params):
run_mode = params[0]
plugin_type = _registered_plugins_[func_name][7]
func = _registered_plugins_[func_name][10]
run_mode = params[0]
plugin_type = _registered_plugins_[func_name][7]
func = _registered_plugins_[func_name][10]
if plugin_type == PLUGIN:
start_params = params[1:3]
extra_params = params[3:]
else:
start_params = ()
extra_params = params[1:]
if plugin_type == PLUGIN:
start_params = params[1:3]
extra_params = params[3:]
else:
start_params = ()
extra_params = params[1:]
if run_mode == RUN_INTERACTIVE:
extra_params = _interact(func_name)
if extra_params == None:
return
elif run_mode == RUN_WITH_LAST_VALS:
extra_params = _get_defaults(func_name)
if run_mode == RUN_INTERACTIVE:
extra_params = _interact(func_name)
if extra_params == None:
return
elif run_mode == RUN_WITH_LAST_VALS:
extra_params = _get_defaults(func_name)
params = start_params + tuple(extra_params)
res = apply(func, params)
if run_mode != RUN_NONINTERACTIVE: gimp.displays_flush()
params = start_params + tuple(extra_params)
res = apply(func, params)
if run_mode != RUN_NONINTERACTIVE: gimp.displays_flush()
def main():
'''This should be called after registering the plugin.'''
gimp.main(None, None, _query, _run)
'''This should be called after registering the plugin.'''
gimp.main(None, None, _query, _run)
_python_image = [
"64 64 7 1",
@ -490,6 +464,6 @@ _python_image = [
]
def _get_logo(colormap):
import gtk
pix, mask = gtk.create_pixmap_from_xpm_d(colormap, None, _python_image)
return gtk.GtkPixmap(pix, mask)
import gtk
pix, mask = gtk.create_pixmap_from_xpm_d(colormap, None, _python_image)
return gtk.GtkPixmap(pix, mask)

View File

@ -295,7 +295,7 @@ pygimp_progress_update(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Query_images(PyObject *self, PyObject *args)
pygimp_query_images(PyObject *self, PyObject *args)
{
gint32 *imgs;
int nimgs, i;
@ -310,7 +310,7 @@ gimp_Query_images(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Install_procedure(PyObject *self, PyObject *args)
pygimp_install_procedure(PyObject *self, PyObject *args)
{
char *name, *blurb, *help, *author, *copyright, *date, *menu_path,
*image_types, *n, *d;
@ -358,7 +358,7 @@ gimp_Install_procedure(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Install_temp_proc(PyObject *self, PyObject *args)
pygimp_install_temp_proc(PyObject *self, PyObject *args)
{
char *name, *blurb, *help, *author, *copyright, *date, *menu_path,
*image_types, *n, *d;
@ -406,7 +406,7 @@ gimp_Install_temp_proc(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Uninstall_temp_proc(PyObject *self, PyObject *args)
pygimp_uninstall_temp_proc(PyObject *self, PyObject *args)
{
char *name;
@ -418,7 +418,7 @@ gimp_Uninstall_temp_proc(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Register_magic_load_handler(PyObject *self, PyObject *args)
pygimp_register_magic_load_handler(PyObject *self, PyObject *args)
{
char *name, *extensions, *prefixes, *magics;
if (!PyArg_ParseTuple(args, "ssss:register_magic_load_handler",
@ -430,7 +430,7 @@ gimp_Register_magic_load_handler(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Register_load_handler(PyObject *self, PyObject *args)
pygimp_register_load_handler(PyObject *self, PyObject *args)
{
char *name, *extensions, *prefixes;
if (!PyArg_ParseTuple(args, "sss:register_load_handler",
@ -442,7 +442,7 @@ gimp_Register_load_handler(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Register_save_handler(PyObject *self, PyObject *args)
pygimp_register_save_handler(PyObject *self, PyObject *args)
{
char *name, *extensions, *prefixes;
if (!PyArg_ParseTuple(args, "sss:register_save_handler",
@ -454,7 +454,7 @@ gimp_Register_save_handler(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Gamma(PyObject *self, PyObject *args)
pygimp_gamma(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":gamma"))
return NULL;
@ -462,7 +462,7 @@ gimp_Gamma(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Install_cmap(PyObject *self, PyObject *args)
pygimp_install_cmap(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":install_cmap"))
return NULL;
@ -470,7 +470,7 @@ gimp_Install_cmap(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Gtkrc(PyObject *self, PyObject *args)
pygimp_gtkrc(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":gtkrc"))
return NULL;
@ -478,7 +478,7 @@ gimp_Gtkrc(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Get_background(PyObject *self, PyObject *args)
pygimp_get_background(PyObject *self, PyObject *args)
{
GimpRGB colour;
guchar r, g, b;
@ -490,7 +490,7 @@ gimp_Get_background(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Get_foreground(PyObject *self, PyObject *args)
pygimp_get_foreground(PyObject *self, PyObject *args)
{
GimpRGB colour;
guchar r, g, b;
@ -502,7 +502,7 @@ gimp_Get_foreground(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Set_background(PyObject *self, PyObject *args)
pygimp_set_background(PyObject *self, PyObject *args)
{
GimpRGB colour;
int r, g, b;
@ -518,7 +518,7 @@ gimp_Set_background(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Set_foreground(PyObject *self, PyObject *args)
pygimp_set_foreground(PyObject *self, PyObject *args)
{
GimpRGB colour;
int r, g, b;
@ -534,7 +534,7 @@ gimp_Set_foreground(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Gradients_get_list(PyObject *self, PyObject *args)
pygimp_gradients_get_list(PyObject *self, PyObject *args)
{
char **list;
int num, i;
@ -550,7 +550,7 @@ gimp_Gradients_get_list(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Gradients_get_gradient(PyObject *self, PyObject *args)
pygimp_gradients_get_gradient(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":gradients_get_gradient"))
return NULL;
@ -558,7 +558,7 @@ gimp_Gradients_get_gradient(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Gradients_set_gradient(PyObject *self, PyObject *args)
pygimp_gradients_set_gradient(PyObject *self, PyObject *args)
{
char *actv;
if (!PyArg_ParseTuple(args, "s:gradients_set_gradient", &actv))
@ -569,7 +569,7 @@ gimp_Gradients_set_gradient(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Gradients_sample_uniform(PyObject *self, PyObject *args)
pygimp_gradients_sample_uniform(PyObject *self, PyObject *args)
{
int num, i, j;
double *samp;
@ -586,7 +586,7 @@ gimp_Gradients_sample_uniform(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Gradients_sample_custom(PyObject *self, PyObject *args)
pygimp_gradients_sample_custom(PyObject *self, PyObject *args)
{
int num, i, j;
double *pos, *samp;
@ -621,7 +621,7 @@ gimp_Gradients_sample_custom(PyObject *self, PyObject *args)
}
static PyObject *
gimp_delete(PyObject *self, PyObject *args)
pygimp_delete(PyObject *self, PyObject *args)
{
PyGimpImage *img;
@ -637,7 +637,7 @@ gimp_delete(PyObject *self, PyObject *args)
static PyObject *
gimp_Displays_flush(PyObject *self, PyObject *args)
pygimp_displays_flush(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":flush"))
return NULL;
@ -648,7 +648,7 @@ gimp_Displays_flush(PyObject *self, PyObject *args)
static PyObject *
gimp_Tile_cache_size(PyObject *self, PyObject *args)
pygimp_tile_cache_size(PyObject *self, PyObject *args)
{
unsigned long k;
if (!PyArg_ParseTuple(args, "l:tile_cache_size", &k))
@ -660,7 +660,7 @@ gimp_Tile_cache_size(PyObject *self, PyObject *args)
static PyObject *
gimp_Tile_cache_ntiles(PyObject *self, PyObject *args)
pygimp_tile_cache_ntiles(PyObject *self, PyObject *args)
{
unsigned long n;
if (!PyArg_ParseTuple(args, "l:tile_cache_ntiles", &n))
@ -672,7 +672,7 @@ gimp_Tile_cache_ntiles(PyObject *self, PyObject *args)
static PyObject *
gimp_Tile_width(PyObject *self, PyObject *args)
pygimp_tile_width(PyObject *self, PyObject *args)
{
if (PyArg_ParseTuple(args, ":tile_width"))
return NULL;
@ -681,7 +681,7 @@ gimp_Tile_width(PyObject *self, PyObject *args)
static PyObject *
gimp_Tile_height(PyObject *self, PyObject *args)
pygimp_tile_height(PyObject *self, PyObject *args)
{
if (PyArg_ParseTuple(args, ":tile_height"))
return NULL;
@ -692,7 +692,7 @@ void gimp_extension_ack (void);
void gimp_extension_process (guint timeout);
static PyObject *
gimp_Extension_ack(PyObject *self, PyObject *args)
pygimp_extension_ack(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":extension_ack"))
return NULL;
@ -702,7 +702,7 @@ gimp_Extension_ack(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Extension_process(PyObject *self, PyObject *args)
pygimp_extension_process(PyObject *self, PyObject *args)
{
int timeout;
@ -725,7 +725,7 @@ new_parasite(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Parasite_find(PyObject *self, PyObject *args)
pygimp_parasite_find(PyObject *self, PyObject *args)
{
char *name;
if (!PyArg_ParseTuple(args, "s:parasite_find", &name))
@ -734,7 +734,7 @@ gimp_Parasite_find(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Parasite_attach(PyObject *self, PyObject *args)
pygimp_parasite_attach(PyObject *self, PyObject *args)
{
PyGimpParasite *parasite;
if (!PyArg_ParseTuple(args, "O!:parasite_attach",
@ -746,7 +746,7 @@ gimp_Parasite_attach(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Attach_new_parasite(PyObject *self, PyObject *args)
pygimp_attach_new_parasite(PyObject *self, PyObject *args)
{
char *name, *data;
int flags, size;
@ -759,7 +759,7 @@ gimp_Attach_new_parasite(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Parasite_detach(PyObject *self, PyObject *args)
pygimp_parasite_detach(PyObject *self, PyObject *args)
{
char *name;
if (!PyArg_ParseTuple(args, "s:parasite_detach", &name))
@ -770,7 +770,7 @@ gimp_Parasite_detach(PyObject *self, PyObject *args)
}
static PyObject *
gimp_Default_display(PyObject *self, PyObject *args)
pygimp_default_display(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":default_display"))
return NULL;
@ -822,39 +822,39 @@ static struct PyMethodDef gimp_methods[] = {
{"get_data", (PyCFunction)pygimp_get_data, METH_VARARGS},
{"progress_init", (PyCFunction)pygimp_progress_init, METH_VARARGS},
{"progress_update", (PyCFunction)pygimp_progress_update, METH_VARARGS},
{"query_images", (PyCFunction)gimp_Query_images, METH_VARARGS},
{"install_procedure", (PyCFunction)gimp_Install_procedure, METH_VARARGS},
{"install_temp_proc", (PyCFunction)gimp_Install_temp_proc, METH_VARARGS},
{"uninstall_temp_proc", (PyCFunction)gimp_Uninstall_temp_proc, METH_VARARGS},
{"register_magic_load_handler", (PyCFunction)gimp_Register_magic_load_handler, METH_VARARGS},
{"register_load_handler", (PyCFunction)gimp_Register_load_handler, METH_VARARGS},
{"register_save_handler", (PyCFunction)gimp_Register_save_handler, METH_VARARGS},
{"gamma", (PyCFunction)gimp_Gamma, METH_VARARGS},
{"install_cmap", (PyCFunction)gimp_Install_cmap, METH_VARARGS},
{"gtkrc", (PyCFunction)gimp_Gtkrc, METH_VARARGS},
{"get_background", (PyCFunction)gimp_Get_background, METH_VARARGS},
{"get_foreground", (PyCFunction)gimp_Get_foreground, METH_VARARGS},
{"set_background", (PyCFunction)gimp_Set_background, METH_VARARGS},
{"set_foreground", (PyCFunction)gimp_Set_foreground, METH_VARARGS},
{"gradients_get_list", (PyCFunction)gimp_Gradients_get_list, METH_VARARGS},
{"gradients_get_gradient", (PyCFunction)gimp_Gradients_get_gradient, METH_VARARGS},
{"gradients_set_gradient", (PyCFunction)gimp_Gradients_set_gradient, METH_VARARGS},
{"gradients_sample_uniform", (PyCFunction)gimp_Gradients_sample_uniform, METH_VARARGS},
{"gradients_sample_custom", (PyCFunction)gimp_Gradients_sample_custom, METH_VARARGS},
{"delete", (PyCFunction)gimp_delete, METH_VARARGS},
{"displays_flush", (PyCFunction)gimp_Displays_flush, METH_VARARGS},
{"tile_cache_size", (PyCFunction)gimp_Tile_cache_size, METH_VARARGS},
{"tile_cache_ntiles", (PyCFunction)gimp_Tile_cache_ntiles, METH_VARARGS},
{"tile_width", (PyCFunction)gimp_Tile_width, METH_VARARGS},
{"tile_height", (PyCFunction)gimp_Tile_height, METH_VARARGS},
{"extension_ack", (PyCFunction)gimp_Extension_ack, METH_VARARGS},
{"extension_process", (PyCFunction)gimp_Extension_process, METH_VARARGS},
{"query_images", (PyCFunction)pygimp_query_images, METH_VARARGS},
{"install_procedure", (PyCFunction)pygimp_install_procedure, METH_VARARGS},
{"install_temp_proc", (PyCFunction)pygimp_install_temp_proc, METH_VARARGS},
{"uninstall_temp_proc", (PyCFunction)pygimp_uninstall_temp_proc, METH_VARARGS},
{"register_magic_load_handler", (PyCFunction)pygimp_register_magic_load_handler, METH_VARARGS},
{"register_load_handler", (PyCFunction)pygimp_register_load_handler, METH_VARARGS},
{"register_save_handler", (PyCFunction)pygimp_register_save_handler, METH_VARARGS},
{"gamma", (PyCFunction)pygimp_gamma, METH_VARARGS},
{"install_cmap", (PyCFunction)pygimp_install_cmap, METH_VARARGS},
{"gtkrc", (PyCFunction)pygimp_gtkrc, METH_VARARGS},
{"get_background", (PyCFunction)pygimp_get_background, METH_VARARGS},
{"get_foreground", (PyCFunction)pygimp_get_foreground, METH_VARARGS},
{"set_background", (PyCFunction)pygimp_set_background, METH_VARARGS},
{"set_foreground", (PyCFunction)pygimp_set_foreground, METH_VARARGS},
{"gradients_get_list", (PyCFunction)pygimp_gradients_get_list, METH_VARARGS},
{"gradients_get_gradient", (PyCFunction)pygimp_gradients_get_gradient, METH_VARARGS},
{"gradients_set_gradient", (PyCFunction)pygimp_gradients_set_gradient, METH_VARARGS},
{"gradients_sample_uniform", (PyCFunction)pygimp_gradients_sample_uniform, METH_VARARGS},
{"gradients_sample_custom", (PyCFunction)pygimp_gradients_sample_custom, METH_VARARGS},
{"delete", (PyCFunction)pygimp_delete, METH_VARARGS},
{"displays_flush", (PyCFunction)pygimp_displays_flush, METH_VARARGS},
{"tile_cache_size", (PyCFunction)pygimp_tile_cache_size, METH_VARARGS},
{"tile_cache_ntiles", (PyCFunction)pygimp_tile_cache_ntiles, METH_VARARGS},
{"tile_width", (PyCFunction)pygimp_tile_width, METH_VARARGS},
{"tile_height", (PyCFunction)pygimp_tile_height, METH_VARARGS},
{"extension_ack", (PyCFunction)pygimp_extension_ack, METH_VARARGS},
{"extension_process", (PyCFunction)pygimp_extension_process, METH_VARARGS},
{"parasite", (PyCFunction)new_parasite, METH_VARARGS},
{"parasite_find", (PyCFunction)gimp_Parasite_find, METH_VARARGS},
{"parasite_attach", (PyCFunction)gimp_Parasite_attach, METH_VARARGS},
{"attach_new_parasite",(PyCFunction)gimp_Attach_new_parasite,METH_VARARGS},
{"parasite_detach", (PyCFunction)gimp_Parasite_detach, METH_VARARGS},
{"default_display", (PyCFunction)gimp_Default_display, METH_VARARGS},
{"parasite_find", (PyCFunction)pygimp_parasite_find, METH_VARARGS},
{"parasite_attach", (PyCFunction)pygimp_parasite_attach, METH_VARARGS},
{"attach_new_parasite",(PyCFunction)pygimp_attach_new_parasite,METH_VARARGS},
{"parasite_detach", (PyCFunction)pygimp_parasite_detach, METH_VARARGS},
{"default_display", (PyCFunction)pygimp_default_display, METH_VARARGS},
{"_id2image", (PyCFunction)id2image, METH_VARARGS},
{"_id2drawable", (PyCFunction)id2drawable, METH_VARARGS},
{"_id2display", (PyCFunction)id2display, METH_VARARGS},
@ -943,6 +943,7 @@ initgimp()
/* export the types used in gimpmodule */
PyDict_SetItemString(d, "Image", (PyObject *)&PyGimpImage_Type);
PyDict_SetItemString(d, "Drawable", (PyObject *)&PyGimpDrawable_Type);
PyDict_SetItemString(d, "Layer", (PyObject *)&PyGimpLayer_Type);
PyDict_SetItemString(d, "Channel", (PyObject *)&PyGimpChannel_Type);
PyDict_SetItemString(d, "Display", (PyObject *)&PyGimpDisplay_Type);

View File

@ -38,19 +38,18 @@
import gimp
class plugin:
def start(self):
gimp.main(self.init, self.quit, self.query, self._run)
def init(self):
pass
def quit(self):
pass
def query(self):
pass
def _run(self, name, params):
if hasattr(self, name):
apply(getattr(self, name), params)
else:
raise AttributeError, name
def start(self):
gimp.main(self.init, self.quit, self.query, self._run)
def init(self):
pass
def quit(self):
pass
def query(self):
pass
def _run(self, name, params):
if hasattr(self, name):
apply(getattr(self, name), params)
else:
raise AttributeError, name
if __name__ == '__main__': plugin().start()

View File

@ -27,57 +27,50 @@
# to the gimp module's primitive interface, which resembles the shelve module.
try:
# use cPickle instead of pickle if it is available.
import cPickle
pickle = cPickle
del cPickle
# use cPickle instead of pickle if it is available.
import cPickle
pickle = cPickle
del cPickle
except ImportError:
import pickle
import pickle
import StringIO
import gimp
try:
# this will fail with python 1.4. All we lose is that the values
# for a plugin which takes extra image/drawables/etc will not be
# saved between invocations.
import copy_reg
def _image_id(obj):
return gimp._id2image, (obj.ID,)
def _drawable_id(obj):
return gimp._id2drawable, (obj.ID,)
def _display_id(obj):
return gimp._id2display, int(obj)
copy_reg.pickle(gimp.ImageType, _image_id, gimp._id2image)
copy_reg.pickle(gimp.LayerType, _drawable_id, gimp._id2drawable)
copy_reg.pickle(gimp.ChannelType, _drawable_id, gimp._id2drawable)
copy_reg.pickle(gimp.DisplayType, _display_id, gimp._id2display)
del copy_reg, _image_id, _drawable_id, _display_id
except ImportError:
pass
import copy_reg
def _image_id(obj):
return gimp._id2image, (obj.ID,)
def _drawable_id(obj):
return gimp._id2drawable, (obj.ID,)
def _display_id(obj):
return gimp._id2display, int(obj)
copy_reg.pickle(gimp.ImageType, _image_id, gimp._id2image)
copy_reg.pickle(gimp.LayerType, _drawable_id, gimp._id2drawable)
copy_reg.pickle(gimp.ChannelType, _drawable_id, gimp._id2drawable)
copy_reg.pickle(gimp.DisplayType, _display_id, gimp._id2display)
del copy_reg, _image_id, _drawable_id, _display_id
class Gimpshelf:
def has_key(self, key):
try:
s = gimp.get_data(key)
return 1
except gimp.error:
return 0
def has_key(self, key):
try:
s = gimp.get_data(key)
return 1
except gimp.error:
return 0
def __getitem__(self, key):
try:
s = gimp.get_data(key)
except gimp.error:
raise KeyError, key
f = StringIO.StringIO(s)
return pickle.Unpickler(f).load()
def __setitem__(self, key, value):
f = StringIO.StringIO()
p = pickle.Pickler(f)
p.dump(value)
gimp.set_data(key, f.getvalue())
def __delitem__(self, key):
gimp.set_data(key, '')
def __getitem__(self, key):
try:
s = gimp.get_data(key)
except gimp.error:
raise KeyError, key
f = StringIO.StringIO(s)
return pickle.Unpickler(f).load()
def __setitem__(self, key, value):
f = StringIO.StringIO()
p = pickle.Pickler(f)
p.dump(value)
gimp.set_data(key, f.getvalue())
def __delitem__(self, key):
gimp.set_data(key, '')
shelf = Gimpshelf()
del Gimpshelf