Commit 872c501e authored by Manish Singh's avatar Manish Singh Committed by Manish Singh
Browse files

Make a compatibility wrapper for PyBool_FromLong for pre-2.3 versions of

2005-03-03  Manish Singh  <yosh@gimp.org>

        * plug-ins/pygimp/pygimp.h: Make a compatibility wrapper for
        PyBool_FromLong for pre-2.3 versions of python.

        * plug-ins/pygimp/gimpfu.py
        * plug-ins/pygimp/gimpui.py: Update to use some more modern python
        features.

        * plug-ins/pygimp/gimpmodule.c
        * plug-ins/pygimp/pygimp-display.c
        * plug-ins/pygimp/pygimp-drawable.c
        * plug-ins/pygimp/pygimp-image.c
        * plug-ins/pygimp/pygimp-parasite.c
        * plug-ins/pygimp/pygimp-pdb.c
        * plug-ins/pygimp/pygimp-tile.c: Throw exceptions on failures for
        libgimp wrappers (fixes bug #160136), and make the exception strings
        a lot more descriptive to aid debugging. Also return proper Bools when
        appropriate. Some new API wrapped as well. Still a work in progress.

        * plug-ins/pygimp/gimpplugin.py
        * plug-ins/pygimp/gimpshelf.py
        * plug-ins/pygimp/plug-ins/clothify.py
        * plug-ins/pygimp/plug-ins/foggify.py
        * plug-ins/pygimp/plug-ins/sphere.py: Add some whitespace to make
        things more readable.
parent fd308340
2005-03-03 Manish Singh <yosh@gimp.org>
* plug-ins/pygimp/pygimp.h: Make a compatibility wrapper for
PyBool_FromLong for pre-2.3 versions of python.
* plug-ins/pygimp/gimpfu.py
* plug-ins/pygimp/gimpui.py: Update to use some more modern python
features.
* plug-ins/pygimp/gimpmodule.c
* plug-ins/pygimp/pygimp-display.c
* plug-ins/pygimp/pygimp-drawable.c
* plug-ins/pygimp/pygimp-image.c
* plug-ins/pygimp/pygimp-parasite.c
* plug-ins/pygimp/pygimp-pdb.c
* plug-ins/pygimp/pygimp-tile.c: Throw exceptions on failures for
libgimp wrappers (fixes bug #160136), and make the exception strings
a lot more descriptive to aid debugging. Also return proper Bools when
appropriate. Some new API wrapped as well. Still a work in progress.
* plug-ins/pygimp/gimpplugin.py
* plug-ins/pygimp/gimpshelf.py
* plug-ins/pygimp/plug-ins/clothify.py
* plug-ins/pygimp/plug-ins/foggify.py
* plug-ins/pygimp/plug-ins/sphere.py: Add some whitespace to make
things more readable.
2005-03-03 Sven Neumann <sven@gimp.org>
* libgimp/gimpdrawablecombobox.c
......
......@@ -131,6 +131,7 @@ def register(func_name, blurb, help, author, copyright, date, menupath,
imagetypes, params, results, function,
on_query=None, on_run=None):
'''This is called to register a new plugin.'''
# First perform some sanity checks on the data
def letterCheck(str):
allowed = _string.letters + _string.digits + '_'
......@@ -139,24 +140,32 @@ def register(func_name, blurb, help, author, copyright, date, menupath,
return 0
else:
return 1
if not letterCheck(func_name):
raise error, "function name contains illegal characters"
for ent in params:
if len(ent) < 4:
raise error, ("parameter definition must contain at least 4 "
"elements (%s given: %s)" % (len(ent), ent))
if type(ent[0]) != type(42):
raise error, "parameter types must be integers"
if not letterCheck(ent[1]):
raise error, "parameter name contains illegal characters"
for ent in results:
if len(ent) < 3:
raise error, ("result definition must contain at least 3 elements "
"(%s given: %s)" % (len(ent), ent))
if type(ent[0]) != type(42):
raise error, "result types must be integers"
if not letterCheck(ent[1]):
raise error, "result name contains illegal characters"
if menupath[:8] == '<Image>/' or \
menupath[:7] == '<Load>/' or \
menupath[:7] == '<Save>/' or \
......@@ -186,11 +195,13 @@ def _query():
params, results, function,
on_query, on_run) = _registered_plugins_[plugin]
fn = lambda x: (_type_mapping[x[0]], x[1], x[2])
params = map(fn, params)
def make_params(params):
return [(_type_mapping[x[0]], x[1], x[2]) for x in params]
params = make_params(params)
# add the run mode argument ...
params.insert(0, (PDB_INT32, "run_mode",
"Interactive, Non-Interactive"))
"Interactive, Non-Interactive"))
if plugin_type == PLUGIN:
if menupath[:7] == '<Load>/':
params[1:1] = file_params
......@@ -202,7 +213,7 @@ def _query():
if menupath[:7] == '<Save>/':
params[3:3] = file_params
results = map(fn, results)
results = make_params(results)
gimp.install_procedure(plugin, blurb, help, author, copyright,
date, menupath, imagetypes, plugin_type,
params, results)
......@@ -217,11 +228,12 @@ def _get_defaults(func_name):
on_query, on_run) = _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)
return [x[3] for x in params]
def _set_defaults(func_name, defaults):
import gimpshelf
......@@ -268,6 +280,7 @@ def _interact(func_name, start_params):
def __init__(self, default=''):
gtk.Entry.__init__(self)
self.set_text(str(default))
def get_value(self):
return self.get_text()
......@@ -287,8 +300,9 @@ def _interact(func_name, start_params):
self.set_value(str(default))
def set_value (self, text):
def set_value(self, text):
self.buffer.set_text(text)
def get_value(self):
return self.buffer.get_text(self.buffer.get_start_iter(),
self.buffer.get_end_iter())
......@@ -299,15 +313,18 @@ def _interact(func_name, start_params):
return int(self.get_text())
except ValueError, e:
raise EntryValueError, e.args
class FloatEntry(StringEntry):
def get_value(self):
try:
return float(self.get_text())
except ValueError, e:
raise EntryValueError, e.args
# 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)):
......@@ -315,8 +332,10 @@ def _interact(func_name, start_params):
bounds[1], bounds[2],
bounds[2], 0)
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)):
......@@ -324,44 +343,57 @@ def _interact(func_name, start_params):
bounds[1], bounds[2],
bounds[2], 0)
gtk.SpinButton.__init__(self, self.adj, 1, 0)
def get_value(self):
try:
return int(self.get_text())
except ValueError, e:
raise EntryValueError, e.args
class ToggleEntry(gtk.ToggleButton):
def __init__(self, default=0):
gtk.ToggleButton.__init__(self)
self.label = gtk.Label("No")
self.add(self.label)
self.label.show()
self.connect("toggled", self.changed)
self.set_active(default)
def changed(self, tog):
if tog.get_active():
self.label.set_text("Yes")
else:
self.label.set_text("No")
def get_value(self):
return self.get_active()
class RadioEntry(gtk.Frame):
def __init__(self, default=0, items=(("Yes", 1), ("No", 0))):
gtk.Frame.__init__(self)
box = gtk.VBox(gtk.FALSE, 5)
box = gtk.VBox(False, 5)
self.add(box)
box.show()
button = None
for (label, value) in items:
button = gtk.RadioButton(button, label)
button.connect("toggled", self.changed, value)
box.pack_start(button)
button.show()
button.connect("toggled", self.changed, value)
if value == default:
button.set_active(gtk.TRUE)
button.set_active(True)
self.active_value = value
def changed(self, radio, value):
if radio.get_active():
self.active_value = value
def get_value(self):
return self.active_value
......@@ -408,32 +440,32 @@ def _interact(func_name, start_params):
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OK, gtk.RESPONSE_OK))
hbox = gtk.HBox(gtk.FALSE, 5)
hbox = gtk.HBox(False, 5)
hbox.set_border_width(5)
dialog.vbox.pack_start(hbox, expand=gtk.FALSE)
dialog.vbox.pack_start(hbox, expand=False)
hbox.show()
table = gtk.Table(len(params), 2, gtk.FALSE)
table = gtk.Table(len(params), 2, False)
table.set_border_width(5)
table.set_row_spacings(4)
table.set_col_spacings(10)
hbox.pack_end(table, expand=gtk.FALSE)
hbox.pack_end(table, expand=False)
table.show()
vbox = gtk.VBox(gtk.FALSE, 10)
hbox.pack_start(vbox, expand=gtk.FALSE)
vbox = gtk.VBox(False, 10)
hbox.pack_start(vbox, expand=False)
vbox.show()
pix = _get_logo()
if pix:
vbox.pack_start(pix, expand=gtk.FALSE)
vbox.pack_start(pix, expand=False)
pix.show()
label = gtk.Label(blurb)
label.set_line_wrap(gtk.TRUE)
label.set_line_wrap(True)
label.set_justify(gtk.JUSTIFY_LEFT)
label.set_size_request(100, -1)
vbox.pack_start(label, expand=gtk.FALSE)
vbox.pack_start(label, expand=False)
label.show()
progress_callback = None
......@@ -476,6 +508,7 @@ def _interact(func_name, start_params):
wid = _edit_mapping[pf_type](def_val)
table.attach(wid, 2,3, i,i+1, yoptions=0)
if pf_type != PF_TEXT:
tooltips.set_tip(wid, desc, None)
else:
......@@ -492,7 +525,7 @@ def _interact(func_name, start_params):
dialog.vbox.pack_start(frame)
frame.show()
vbox = gtk.VBox(gtk.FALSE, 5)
vbox = gtk.VBox(False, 5)
vbox.set_border_width(5)
frame.add(vbox)
vbox.show()
......
This diff is collapsed.
......@@ -26,30 +26,39 @@
# A plugin using this module would look something like this:
#
# import gimp, gimpplugin
#
# pdb = gimp.pdb
#
# class myplugin(gimpplugin.plugin):
# def query(self):
# gimp.install_procedure("plug_in_mine", ...)
# def plug_in_mine(self, par1, par2, par3,...):
# do_something()
# def query(self):
# gimp.install_procedure("plug_in_mine", ...)
#
# if __name__ == '__main__': myplugin().start()
# def plug_in_mine(self, par1, par2, par3,...):
# do_something()
#
# if __name__ == '__main__':
# myplugin().start()
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
if __name__ == '__main__': plugin().start()
if __name__ == '__main__':
plugin().start()
......@@ -41,16 +41,21 @@ except ImportError:
import gimp
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.Image, _image_id, gimp._id2image)
copy_reg.pickle(gimp.Layer, _drawable_id, gimp._id2drawable)
copy_reg.pickle(gimp.Image, _image_id, gimp._id2image)
copy_reg.pickle(gimp.Layer, _drawable_id, gimp._id2drawable)
copy_reg.pickle(gimp.Channel, _drawable_id, gimp._id2drawable)
copy_reg.pickle(gimp.Display, _display_id, gimp._id2display)
copy_reg.pickle(gimp.Display, _display_id, gimp._id2display)
del copy_reg, _image_id, _drawable_id, _display_id
class Gimpshelf:
......@@ -66,13 +71,16 @@ class Gimpshelf:
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, '')
......
......@@ -95,11 +95,11 @@ class ImageSelector(gtk.OptionMenu):
self.menu = ImageMenu(None, self.clicked)
self.set_menu(self.menu)
if default == None:
self.selected = self.menu.children()[0].get_data("Gimp-ID")
self.selected = self.menu.get_children()[0].get_data("Gimp-ID")
self.set_history (0)
else:
self.selected = default
children = self.menu.children()
children = self.menu.get_children()
for child in range(len(children)):
if children[child].get_data("Gimp-ID") == default:
self.set_history(child)
......@@ -115,11 +115,11 @@ class LayerSelector(gtk.OptionMenu):
self.menu = LayerMenu(None, self.clicked)
self.set_menu(self.menu)
if default == None:
self.selected = self.menu.children()[0].get_data("Gimp-ID")
self.selected = self.menu.get_children()[0].get_data("Gimp-ID")
self.set_history (0)
else:
self.selected = default
children = self.menu.children()
children = self.menu.get_children()
for child in range(len(children)):
if children[child].get_data("Gimp-ID") == default:
self.set_history(child)
......@@ -135,11 +135,11 @@ class ChannelSelector(gtk.OptionMenu):
self.menu = ChannelMenu(None, self.clicked)
self.set_menu(self.menu)
if default == None:
self.selected = self.menu.children()[0].get_data("Gimp-ID")
self.selected = self.menu.get_children()[0].get_data("Gimp-ID")
self.set_history (0)
else:
self.selected = default
children = self.menu.children()
children = self.menu.get_children()
for child in range(len(children)):
if children[child].get_data("Gimp-ID") == default:
self.set_history(child)
......@@ -155,11 +155,11 @@ class DrawableSelector(gtk.OptionMenu):
self.menu = DrawableMenu(None, self.clicked)
self.set_menu(self.menu)
if default == None:
self.selected = self.menu.children()[0].get_data("Gimp-ID")
self.selected = self.menu.get_children()[0].get_data("Gimp-ID")
self.set_history (0)
else:
self.selected = default
children = self.menu.children()
children = self.menu.get_children()
for child in range(len(children)):
if children[child].get_data("Gimp-ID") == default:
self.set_history(child)
......@@ -203,13 +203,13 @@ class ColourSelector(gtk.Button):
class _Selector(gtk.HBox):
def __init__(self):
gtk.HBox.__init__(self, gtk.FALSE, 5)
gtk.HBox.__init__(self, False, 5)
self.entry = gtk.Entry()
self.pack_start(self.entry)
self.entry.show()
self.button = gtk.Button("Browse...")
self.button.connect("clicked", self.show_dialog)
self.pack_start(self.button, expand=gtk.FALSE)
self.pack_start(self.button, expand=False)
self.button.show()
self.dialog = gtk.Dialog(self.get_title(), None, 0,
......@@ -226,7 +226,7 @@ class _Selector(gtk.HBox):
store = gtk.ListStore(gobject.TYPE_STRING)
treeview = gtk.TreeView(store)
treeview.set_headers_visible(gtk.FALSE)
treeview.set_headers_visible(False)
column = gtk.TreeViewColumn('Items', gtk.CellRendererText(), text=0)
treeview.append_column(column)
......@@ -319,20 +319,20 @@ class PaletteSelector(_Selector):
class FontSelector(gtk.HBox):
def __init__(self, default="Sans"):
gtk.HBox.__init__(self, gtk.FALSE, 5)
gtk.HBox.__init__(self, False, 5)
self.entry = gtk.Entry()
self.pack_start(self.entry)
self.entry.show()
self.button = gtk.Button("Browse...")
self.button.connect("clicked", self.show_dialog)
self.pack_start(self.button, expand=gtk.FALSE)
self.pack_start(self.button, expand=False)
self.button.show()
self.dialog = gtk.FontSelectionDialog("Fonts")
self.dialog.set_default_size(400, 300)
def delete_event(win, event):
win.hide()
return gtk.TRUE
return True
self.dialog.connect("delete_event", delete_event)
self.dialog.set_font_name(default)
......@@ -353,20 +353,20 @@ class FontSelector(gtk.HBox):
class FileSelector(gtk.HBox):
def __init__(self, default=""):
gtk.HBox.__init__(self, gtk.FALSE, 5)
gtk.HBox.__init__(self, False, 5)
self.entry = gtk.Entry()
self.pack_start(self.entry)
self.entry.show()
self.button = gtk.Button("...")
self.button.connect("clicked", self.show_dialog)
self.pack_start(self.button, expand=gtk.FALSE)
self.pack_start(self.button, expand=False)
self.button.show()
self.dialog = gtk.FileSelection("Files")
self.dialog.set_default_size(400, 300)
def delete_event(win, event):
win.hide()
return gtk.TRUE
return True
self.dialog.connect("delete_event", delete_event)
self.dialog.set_filename(default)
......
......@@ -23,27 +23,37 @@ from gimpfu import *
def python_clothify(timg, tdrawable, bx=9, by=9,
azimuth=135, elevation=45, depth=3):
bx = 9 ; by = 9 ; azimuth = 135 ; elevation = 45 ; depth = 3
width = tdrawable.width
height = tdrawable.height
img = gimp.Image(width, height, RGB)
img.disable_undo()
layer_one = gimp.Layer(img, "X Dots", width, height, RGB_IMAGE,
100, NORMAL_MODE)
img.add_layer(layer_one, 0)
pdb.gimp_edit_fill(layer_one, BACKGROUND_FILL)
pdb.plug_in_noisify(img, layer_one, 0, 0.7, 0.7, 0.7, 0.7)
layer_two = layer_one.copy()
layer_two.mode = MULTIPLY_MODE
layer_two.name = "Y Dots"
img.add_layer(layer_two, 0)
pdb.plug_in_gauss_rle(img, layer_one, bx, 1, 0)
pdb.plug_in_gauss_rle(img, layer_two, by, 0, 1)
img.flatten()
bump_layer = img.active_layer
pdb.plug_in_c_astretch(img, bump_layer)
pdb.plug_in_noisify(img, bump_layer, 0, 0.2, 0.2, 0.2, 0.2)
pdb.plug_in_bump_map(img, tdrawable, bump_layer, azimuth,
elevation, depth, 0, 0, 0, 0, TRUE, FALSE, 0)
gimp.delete(img)
register(
......
......@@ -9,6 +9,7 @@ def python_foggify(img, layer, name, colour, turbulence, opacity):
fog = gimp.Layer(img, name, layer.width, layer.height, RGBA_IMAGE,
opacity, NORMAL_MODE)
img.add_layer(fog, 0)
oldbg = gimp.get_background()
gimp.set_background(colour)
pdb.gimp_edit_fill(fog, BACKGROUND_FILL)
......
......@@ -23,49 +23,70 @@ from gimpfu import *
def python_sphere(radius, light, shadow, bg_colour, sphere_colour):
if radius < 1:
radius = 1
width = int(radius * 3.75)
height = int(radius * 2.5)
img = gimp.Image(width, height, RGB)
drawable = gimp.Layer(img, "Sphere Layer", width, height,
RGB_IMAGE, 100, NORMAL_MODE)
radians = light * math.pi / 180
cx = width / 2
cy = height / 2
light_x = cx + radius * 0.6 * math.cos(radians)
light_y = cy - radius * 0.6 * math.sin(radians)
light_end_x = cx + radius * math.cos(math.pi + radians)
light_end_y = cy - radius * math.sin(math.pi + radians)
offset = radius * 0.1
old_fg = gimp.get_foreground()
old_bg = gimp.get_background()
img.disable_undo()
img.add_layer(drawable, 0)
gimp.set_foreground(sphere_colour)
gimp.set_background(bg_colour)
pdb.gimp_edit_fill(drawable, BACKGROUND_FILL)
gimp.set_background(20, 20, 20)
if (light >= 45 and light <= 75 or light <= 135 and
light >= 105) and shadow:
shadow_w = radius * 2.5 * math.cos(math.pi + radians)
shadow_h = radius * 0.5
shadow_x = cx
shadow_y = cy + radius * 0.65
if shadow_w < 0:
shadow_x = cx + shadow_w
shadow_w = -shadow_w
pdb.gimp_ellipse_select(img, shadow_x, shadow_y, shadow_w, shadow_h,
CHANNEL_OP_REPLACE, TRUE, TRUE, 7.5)
pdb.gimp_edit_bucket_fill(drawable, BG_BUCKET_FILL,
MULTIPLY_MODE, 100, 0, FALSE, 0, 0)
pdb.gimp_ellipse_select(img, cx - radius, cy - radius, 2 * radius,
2 * radius, CHANNEL_OP_REPLACE, TRUE, FALSE, 0)
pdb.gimp_edit_blend(drawable, FG_BG_RGB_MODE, NORMAL_MODE, GRADIENT_RADIAL,
100, offset, REPEAT_NONE, FALSE, FALSE, 0, 0, TRUE,