Commit 3a1520cd authored by Scott Lembcke's avatar Scott Lembcke Committed by Scott Lembcke

Added #to_proc to PDB::Procedure.

2006-06-27  Scott Lembcke <lemb0029@gnome.org>

	* gimp-lib/gimp.rb: Added #to_proc to PDB::Procedure.

	* gimp-lib/rubyfu.rb: Added RubyFu::ParamDef with support for default
	  parameters. Also, required parameters were changed to be added
	  automatically.

	* plug-ins/*: Minor changes to reflect the changes applied to rubyfu.rb.
parent fa2936ca
2006-06-27 Scott Lembcke <lemb0029@gnome.org>
* gimp-lib/gimp.rb: Added #to_proc to PDB::Procedure.
* gimp-lib/rubyfu.rb: Added RubyFu::ParamDef with support for default
parameters. Also, required parameters were changed to be added
automatically.
* plug-ins/*: Minor changes to reflect the changes applied to rubyfu.rb.
2006-06-24 Scott Lembcke <lemb0029@gnome.org>
* ext/Makefile.am: Added ext/arraytypes.c.
* ext/arraytypes.c: Added ext/arraytypes.c which contains stubs to wrap
array pointers.
array pointers.
* ext/conversion.c: Added support for array conversion and ParamRegions,
and changed the behavior of GimpParams2rb() to return an array of
Gimp::Param structs.
and changed the behavior of GimpParams2rb() to return an array of
Gimp::Param structs.
* ext/ids.c: Added additional ids for use with Gimp::ParamRegion structs.
* ext/rbgimp.c: Moved constant definitions to rbgimpconstants.c and added
additional module functions.
additional module functions.
* ext/rbgimpconstants.c: Enumerations are now defined using
gimp_enums_get_names(). Added additional constants.
gimp_enums_get_names(). Added additional constants.
* ext/rbgimpmain.c: GimpParam arrays are now registered with the Ruby GC
so that they are freed at exit. Fixed a couple of bugs pertaining to
exception handling and return values.
so that they are freed at exit. Fixed a couple of bugs pertaining to
exception handling and return values.
* gimp-lib/gimp.rb.c: Changed code for definition of Gimp::Param and
Gimp::ParamDef. Added type checking abilities to Gimp::Param and
Gimp::ParamDef. Fixed bugs in the type checking and parameter handling of
the PDB module.
Gimp::ParamDef. Added type checking abilities to Gimp::Param and
Gimp::ParamDef. Fixed bugs in the type checking and parameter
handling of the PDB module.
* plug-ins/Makefile.am: Added coolmetal-logo.rb.
* plug-ins/coolmetal-logo.rb.c: Tried porting the old ruby plugin, still
has some issues with the reflection.
has some issues with the reflection.
2006-06-22 Kevin Cozens <kcozens@cvs.gnome.org>
......
......@@ -189,6 +189,12 @@ module PDB
"return_vals: #@return_vals",
].join("\n")
end
def to_proc
lambda do|*args|
self.call(*args)
end
end
end
def self.[](name)
......
......@@ -4,6 +4,24 @@ module RubyFu
class ResultError < Exception
end
class ParamDef < Gimp::ParamDef
attr_reader :default
def self.method_missing(sym, *args)
nargs = args.length
if nargs == 3
default = args.pop
pdef = super(sym, *args)
pdef.check(default)
pdef.instance_variable_set(:@default, default)
return pdef
else
return super
end
end
end
class Procedure
def initialize(*args, &func)
......@@ -15,7 +33,13 @@ module RubyFu
menupath,*rem = *rem
if menupath.empty?
@menulabel = ""
@type = :internal
else
@type = case menupath
when /<Image>/: :image
when /<Toolbox>/: :toolbox
end
@menubasepath = File.dirname menupath
@menulabel = File.basename menupath
end
......@@ -23,10 +47,27 @@ module RubyFu
@imagetypes, *rem = *rem
@params, @results, *rem = *rem
@fullparams = preparams + @params
@function = func
end
def preparams
case @type
when :toolbox
[Gimp::ParamDef.INT32('run-mode', 'Run mode')]
when :images
[
Gimp::ParamDef.INT32('run-mode', 'Run mode'),
Gimp::ParamDef.IMAGE('image', 'Input image'),
Gimp::ParamDef.DRAWABLE('drawable', 'Input drawable'),
]
else
[]
end
end
def query
def query
Gimp.install_procedure(
@name,
@blurb,
......@@ -37,8 +78,8 @@ module RubyFu
@menulabel,
@imagetypes,
Gimp::PLUGIN,
@params,
@results
(@fullparams.empty? ? nil : @fullparams),
(@results.empty? ? nil : @results)
)
if @menubasepath
......@@ -46,40 +87,57 @@ module RubyFu
end
end
def default_args
defArgs = @params.collect do|pdef|
pdef.default if pdef.respond_to? :default
end
end
def run_interactive(args)
#use default values for now
#TODO (much later) create an input dialog.
warn "Interactive mode not implemented, sending default params."
args += default_args
values = @function.call(*args)
end
def run_noninteractive(args, params)
nargs = args.length
nparams = params.length
unless nargs == nparams
raise(CallError, "Wrong number of arguments. (#{nargs} for #{nparams})")
end
values = @function.call(*args)
end
def run_last_vals(args)
#use default values for now
#TODO actually remember the last values
warn "Last value mode not implemented, sending default params."
args += default_args
values = @function.call(*args)
end
def run(*args)
params = @params ? @params : []
results = @results ? @results : []
if params.length > 0 and params[0].name == 'run-mode'
#FIXME this could be improved
if @fullparams.length > 0 and @fullparams[0].name == 'run-mode'
runMode = args[0].data
else
runMode = Gimp::RUN_NONINTERACTIVE
end
args = args.zip(params).collect do|arg, param|
args = args.zip(@fullparams).collect do|arg, param|
raise(CallError, "Bad argument") unless arg.type == param.type
next arg.data
end
case runMode
when Gimp::RUN_INTERACTIVE
#use default values for now
#TODO (much later) create an input dialog.
warn "Interactive mode not implemented, sending default params."
values = @function.call(*args)
when Gimp::RUN_NONINTERACTIVE
nargs = args.length
nparams = params.length
unless nargs == nparams
raise(CallError, "Wrong number of arguments. (#{nargs} for #{nparams})")
end
values = @function.call(*args)
when Gimp::RUN_WITH_LAST_VALS
#use default values for now
#TODO actually remember the last values
warn "Last value mode not implemented, sending default params."
values = @function.call(*args)
values = case runMode
when Gimp::RUN_INTERACTIVE: run_interactive(args)
when Gimp::RUN_NONINTERACTIVE: run_noninteractive(args, @fullparams)
when Gimp::RUN_WITH_LAST_VALS: run_last_vals(args)
end
if values == nil
......@@ -88,17 +146,15 @@ module RubyFu
*values = *values
end
#TODO check & convert return values and handle exceptions
nvalues = values.length
nresults = results.length
nresults = @results.length
unless nvalues == nresults
#FIXME A more descriptive exception type would be good here.
message = "Wrong number of return values. (#{nvalues} for #{nresults})"
raise(ResultError, message)
end
begin
values = values.zip(results).collect do|value, result|
values = values.zip(@results).collect do|value, result|
result.check(value)
Gimp::Param.new(result.type, value)
end
......@@ -135,8 +191,8 @@ module RubyFu
String(date),
String(menupath),
String(imagetypes),
params,
results,
Array(params),
Array(results),
&function
)
......@@ -152,15 +208,15 @@ module RubyFu
proc = @@procedures[name]
values = proc.run(*args)
values.unshift Param.STATUS(PDB_SUCCESS)
values.unshift Gimp::Param.STATUS(Gimp::PDB_SUCCESS)
return values
rescue CallError
PDB.gimp_message("A calling error has occured: #$!.message")
return [Param.STATUS(PDB_CALLING_ERROR)]
return [Gimp::Param.STATUS(PDB_CALLING_ERROR)]
rescue Exception
PDB.gimp_message "A #{$!.class} has occured: #{$!.message}\n#{$@.join("\n")}"
return [Param.STATUS(PDB_EXECUTION_ERROR)]
return [Gimp::Param.STATUS(Gimp::PDB_EXECUTION_ERROR)]
end
end
......@@ -171,7 +227,8 @@ module RubyFu
method(:run)
)
def self.main
def main
Gimp.main(PLUG_IN_INFO)
end
module_function :main
end
\ No newline at end of file
......@@ -2,6 +2,7 @@
require "gimp"
include Gimp
include RubyFu
include PDB::Access
......@@ -133,9 +134,6 @@ RubyFu.register(
"<Image>/Ruby-Fu/Alpha to Logo/Cool Metal...",
"RGBA",
[
ParamDef.INT32('run-mode', 'Run mode'),
ParamDef.IMAGE("image", "Image"),
ParamDef.DRAWABLE("drawable", "Drawable"),
ParamDef.INT32("effect_size", "Effect Size (pixels)"),
ParamDef.COLOR("bg_color", "Background Color"),
ParamDef.STRING("gradient", "Gradient"),
......@@ -145,7 +143,7 @@ RubyFu.register(
)
def ruby_fu_cool_metal_logo(run_mode, text = "Cool Metal", size = 100, font = "-*-Crillee-*-r-*-*-24-*-*-*-p-*-*-*", bg_color = Gimp::Rgb.new(1.0, 1.0, 1.0), gradient = "Horizon 1")
def ruby_fu_cool_metal_logo(run_mode, text, size, font, bg_color, gradient)
# img = Gimp::Image::new(256, 256, RGB)
img = gimp_image_new(600, 256, RGB)
begin
......@@ -179,12 +177,11 @@ RubyFu.register(
"<Toolbox>/Xtns/Languages/Ruby-Fu/Cool Metal...",
"",
[
ParamDef.INT32('run-mode', 'Run-Mode'),
ParamDef.STRING("text", "Text"),
ParamDef.INT32("font_size", "Font Size (pixels)"),
ParamDef.STRING("font", "Font"),
ParamDef.COLOR("bg_color", "Background Color"),
ParamDef.STRING("gradient", "Gradient"),
ParamDef.STRING("text", "Text", 'Cool Metal'),
ParamDef.INT32("font_size", "Font Size (pixels)", 100),
ParamDef.STRING("font", "Font", "-*-Crillee-*-r-*-*-24-*-*-*-p-*-*-*"),
ParamDef.COLOR("bg_color", "Background Color", Rgb.new(1.0, 1.0, 1.0)),
ParamDef.STRING("gradient", "Gradient", "Horizon 1"),
],
[
ParamDef.IMAGE('image', 'Image'),
......
#!/usr/bin/env ruby
GC.disable
require 'gimp'
include Gimp
#include RubyFu
#include PDB::Access
......@@ -17,10 +15,12 @@ RubyFu.register(
'<Toolbox>/Xtns/Languages/Ruby-Fu/Hello World!',
'',
[
ParamDef.INT32('run-mode', 'Run mode'),
RubyFu::ParamDef.STRING('stuff', 'test', 'test string'),
],
nil
) do|run_mode|
) do|run_mode, stuff|
run_mode = Gimp::EnumNames::RunMode[run_mode]
Gimp.message "Run mode: #{run_mode}\nStuff: #{stuff.inspect}"
PDB.ruby_fu_hello2
nil
end
......
......@@ -17,12 +17,32 @@ Parameters:
require "gimp"
include Gimp
include RubyFu
#include PDB::Access
include Math
def run(run_mode, radius = 100, light = 45, shadow = true, bg_color = Gimp::Rgb.new(1.0, 1.0, 1.0), sphere_color = Gimp::Rgb.new(1.0, 0.0, 0.0))
RubyFu.register(
"ruby_fu_sphere",
"Simple sphere with a drop shadow",
"Simple sphere with a drop shadow",
"Spencer Kimball and Masahiro Sakai",
"Spencer Kimball",
"2001",
'<Toolbox>/Xtns/Languages/Ruby-Fu/Sphere',
"",
[
ParamDef.FLOAT('radius', 'Radius', 100),
ParamDef.FLOAT('lighting', 'Lighting Degrees', 45),
ParamDef.INT32('shadow', 'Shadow', 1),
ParamDef.COLOR('bg color', 'Background Color', Rgb.new(1.0, 1.0, 1.0)),
ParamDef.COLOR('color', 'Sphere Color', Rgb.new(1.0, 0.0, 0.0)),
],
[ParamDef.IMAGE('image', 'Result Image')]
) do |run_mode, radius, light, shadow, bg_color, sphere_color|
shadow = (shadow != 0)
width = radius * 3.75
height = radius * 2.5
......@@ -83,29 +103,7 @@ def run(run_mode, radius = 100, light = 45, shadow = true, bg_color = Gimp::Rgb.
PDB.gimp_context_pop()
PDB.gimp_display_new(img)
return img
img
end
RubyFu.register(
"ruby_fu_sphere",
"Simple sphere with a drop shadow",
"Simple sphere with a drop shadow",
"Spencer Kimball and Masahiro Sakai",
"Spencer Kimball",
"2001",
'<Toolbox>/Xtns/Languages/Ruby-Fu/Sphere',
"",
[
ParamDef.INT32('run-mode', 'Run mode'),
ParamDef.FLOAT('radius', 'Radius'),
ParamDef.FLOAT('lighting', 'Lighting Degrees'),
ParamDef.INT32('shadow', 'Shadow'),
ParamDef.COLOR('bg color', 'Background Color'),
ParamDef.COLOR('color', 'Sphere Color'),
],
[ParamDef.IMAGE('image', 'Result Image')],
&method(:run)
)
RubyFu.main
main
......@@ -8,10 +8,10 @@ Handle parameter definitions/defaults better in RubyFu.
Finish OO Gimp types.
Figure what other parts of the C API needs wrapping.
Make sure all the useful parts of the C API were wrapped.
The color code has turned out to be less than useful. Fix this.
The color code has turned out to be sub-par, lots of room for improvment.
Signal handlers need to be backed up. (see how the old one did this. Is it still necessary?)
Signal handlers might need to be backed up. (see how the old one did this. Is it still necessary?)
Read up on Gtk before working on any UI stuff.
\ No newline at end of file
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