Commit e8452778 authored by Scott Lembcke's avatar Scott Lembcke Committed by Scott Lembcke

Moved OO type class definitions to gimp.rb.

2006-08-08  Scott Lembcke <lemb0029@gnome.org>

        * gimp-lib/gimp_oo.rb: Moved OO type class definitions to gimp.rb.

        * gimp-lib/gimp.rb: Added autoload handles for all OO classes. Added
          Moved conversion of object types into the Gimp::Param class. Added
          the bool2int_filter() method to convert bools into C style bools.

        * Added files for OO types. (gimp-lib/gimp_oo_*.rb)

        * gimp-lib/Makefile.am: Added OO type files.

        * gimp-lib/pdb.rb: Added a call to bool2int() when converting pdb
          arguments. Now true/false can be used when calling procedures.

        * gimp-lib/rubyfu.rb: Fixed a bug when registering <Image> plugins.
          Moved the call to open the dialog befor converting any parameter
          types. Added support for running a procedure with the last values.
          Added a call to bool2int_filter() so ruby-fu procedures can return
          booleans.

        * plug-ins/: Added new example plugins: gloom.rb, helloworld.rb,
          sunset.rb. Added runfile.rb/rerunfile.rb plugins to aid in plug-in
          development. Added speed.rb plugin to the test scripts.

        * gimp-lib/Makefile.am: Added new plugins.
parent 77d3a8e6
2006-08-08 Scott Lembcke <lemb0029@gnome.org>
* gimp-lib/gimp_oo.rb: Moved OO type class definitions to gimp.rb.
* gimp-lib/gimp.rb: Added autoload handles for all OO classes. Added
Moved conversion of object types into the Gimp::Param class. Added
the bool2int_filter() method to convert bools into C style bools.
* Added files for OO types. (gimp-lib/gimp_oo_*.rb)
* gimp-lib/Makefile.am: Added OO type files.
* gimp-lib/pdb.rb: Added a call to bool2int() when converting pdb
arguments. Now true/false can be used when calling procedures.
* gimp-lib/rubyfu.rb: Fixed a bug when registering <Image> plugins.
Moved the call to open the dialog befor converting any parameter
types. Added support for running a procedure with the last values.
Added a call to bool2int_filter() so ruby-fu procedures can return
booleans.
* plug-ins/: Added new example plugins: gloom.rb, helloworld.rb,
sunset.rb. Added runfile.rb/rerunfile.rb plugins to aid in plug-in
development. Added speed.rb plugin to the test scripts.
* gimp-lib/Makefile.am: Added new plugins.
2006-08-05 Kevin Cozens <kcozens@cvs.gnome.org>
* Makefile.am: Added po directory to the SUBDIRS list.
......
......@@ -3,10 +3,23 @@
gimplibdir = $(GIMP_LIBDIR)/ruby
gimplib = \
gimp_oo.rb \
gimp.rb \
pdb.rb \
rubyfu.rb
gimp.rb \
gimp_oo.rb \
gimp_oo_brush.rb \
gimp_oo_channel.rb \
gimp_oo_context.rb \
gimp_oo_display.rb \
gimp_oo_drawable.rb \
gimp_oo_edit.rb \
gimp_oo_gradient.rb \
gimp_oo_image.rb \
gimp_oo_layer.rb \
gimp_oo_palette.rb \
gimp_oo_progress.rb \
gimp_oo_selection.rb \
gimp_oo_vectors.rb \
pdb.rb \
rubyfu.rb
gimplib_SCRIPTS = $(gimplib)
......
......@@ -22,15 +22,21 @@ require 'gimpext'
require 'pdb'
def _(str)
puts 'bam'
Gimp.gettext(str)
end
def N_(str)
puts 'whap'
str
end
def bool2int_filter(value)
case value
when true: 1
when false: 0
else value
end
end
module Gimp
def message(*messages)
messages.each do|message|
......@@ -122,6 +128,23 @@ module Gimp
return new(Gimp.const_get("PDB_#{sym}".to_sym), data)
end
def transform
case type
when PDB_DISPLAY
Display.create(data)
when PDB_IMAGE
Image.create(data)
when PDB_LAYER
Layer.create(data)
when PDB_CHANNEL
Channel.create(data)
when PDB_VECTORS
Vectors.create(data)
else
self.data
end
end
def to_s
"GimpParam #{EnumNames::PDBArgType[type]}: #{data}"
end
......@@ -178,4 +201,19 @@ module Gimp
PDB.gimp_procedural_db_set_data(key, bytes, data)
end
end
autoload(:Drawable, 'gimp_oo_drawable.rb')
autoload(:Brush, 'gimp_oo_brush.rb')
autoload(:Channel, 'gimp_oo_channel.rb')
autoload(:Display, 'gimp_oo_display.rb')
autoload(:Gradient, 'gimp_oo_gradient.rb')
autoload(:Image, 'gimp_oo_image.rb')
autoload(:Layer, 'gimp_oo_layer.rb')
autoload(:Palette, 'gimp_oo_palette.rb')
autoload(:Vectors, 'gimp_oo_vectors.rb')
autoload(:Context, 'gimp_oo_context.rb')
autoload(:Edit, 'gimp_oo_edit.rb')
autoload(:Progress, 'gimp_oo_progress.rb')
autoload(:Selection, 'gimp_oo_selection.rb')
end
......@@ -111,89 +111,7 @@ module Gimp
end
return mod
end
end
Gimp::Drawable = ClassTemplate.template('gimp-drawable-', nil)
Gimp::Brush = ClassTemplate.template('gimp-brush-', 'gimp-brushes-')
Gimp::Channel = ClassTemplate.template('gimp-channel-', nil, Gimp::Drawable)
Gimp::Display = ClassTemplate.template('gimp-display-', 'gimp-displays-')
Gimp::Gradient = ClassTemplate.template('gimp-gradient-', 'gimp-gradients-')
Gimp::Image = ClassTemplate.template('gimp-image-', nil)
Gimp::Layer = ClassTemplate.template('gimp-layer-', nil, Gimp::Drawable)
Gimp::Palette = ClassTemplate.template('gimp-palette-', 'gimp-palettes-')
Gimp::Vectors = ClassTemplate.template('gimp-vectors-', nil)
Gimp::Context = ModuleTemplate.template('gimp-context-')
Gimp::Edit = ModuleTemplate.template('gimp-edit-')
Gimp::Fonts = ModuleTemplate.template('gimp-fonts-')
Gimp::ProceduralDB = ModuleTemplate.template('gimp-procedural-db-')
Gimp::Progress = ModuleTemplate.template('gimp-progress-')
Gimp::Selection = ModuleTemplate.template('gimp-selection-')
end
class Image
add_class_method('list', 'gimp-image-list')
alias_method :old_undo_group_start, :undo_group_start
def undo_group
old_undo_group_start
if block_given?
begin
yield
ensure
undo_group_end
end
end
end
alias_method :old_undo_disable, :undo_disable
def undo_disable
old_undo_disable
if block_given?
begin
yield
ensure
undo_enable
end
end #if
end #meth
end #class
module Context
class << self
alias_method :old_push, :push
def push
old_push
if block_given?
begin
yield
ensure
pop
end
end #if
end #meth
end #class
end #def
end #module
end #module
end #module
module Gimp
class Param
def transform
case type
when PDB_DISPLAY
Display.create(data)
when PDB_IMAGE
Image.create(data)
when PDB_LAYER
Layer.create(data)
when PDB_CHANNEL
Channel.create(data)
when PDB_VECTORS
Vectors.create(data)
else
self.data
end
end
end
end
# GIMP-Ruby -- Allows GIMP plugins to be written in Ruby.
# Copyright (C) 2006 Scott Lembcke
#
# 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., 51 Franklin Street, Fifth Floor,Boston, MA
# 02110-1301, USA.
require 'gimp_oo.rb'
module Gimp
Brush = GimpOO::ClassTemplate.template('gimp-brush-', 'gimp-brushes-')
end
\ No newline at end of file
# GIMP-Ruby -- Allows GIMP plugins to be written in Ruby.
# Copyright (C) 2006 Scott Lembcke
#
# 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., 51 Franklin Street, Fifth Floor,Boston, MA
# 02110-1301, USA.
require 'gimp_oo.rb'
module Gimp
Channel = GimpOO::ClassTemplate.template('gimp-channel-', nil, Gimp::Drawable)
end
\ No newline at end of file
# GIMP-Ruby -- Allows GIMP plugins to be written in Ruby.
# Copyright (C) 2006 Scott Lembcke
#
# 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., 51 Franklin Street, Fifth Floor,Boston, MA
# 02110-1301, USA.
require 'gimp_oo.rb'
module Gimp
Context = GimpOO::ModuleTemplate.template('gimp-context-')
module Context
class << self
alias_method :old_push, :push
def push
old_push
if block_given?
begin
yield
ensure
pop
end #begin
end #if
end #def
end #class
end #module
end #module
\ No newline at end of file
# GIMP-Ruby -- Allows GIMP plugins to be written in Ruby.
# Copyright (C) 2006 Scott Lembcke
#
# 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., 51 Franklin Street, Fifth Floor,Boston, MA
# 02110-1301, USA.
require 'gimp_oo.rb'
module Gimp
Display = GimpOO::ClassTemplate.template('gimp-display-', 'gimp-displays-')
end
\ No newline at end of file
# GIMP-Ruby -- Allows GIMP plugins to be written in Ruby.
# Copyright (C) 2006 Scott Lembcke
#
# 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., 51 Franklin Street, Fifth Floor,Boston, MA
# 02110-1301, USA.
require 'gimp_oo.rb'
module Gimp
Drawable = GimpOO::ClassTemplate.template('gimp-drawable-', nil)
end
\ No newline at end of file
# GIMP-Ruby -- Allows GIMP plugins to be written in Ruby.
# Copyright (C) 2006 Scott Lembcke
#
# 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., 51 Franklin Street, Fifth Floor,Boston, MA
# 02110-1301, USA.
require 'gimp_oo.rb'
module Gimp
Edit = GimpOO::ModuleTemplate.template('gimp-edit-')
end
\ No newline at end of file
# GIMP-Ruby -- Allows GIMP plugins to be written in Ruby.
# Copyright (C) 2006 Scott Lembcke
#
# 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., 51 Franklin Street, Fifth Floor,Boston, MA
# 02110-1301, USA.
require 'gimp_oo.rb'
module Gimp
Gradient = GimpOO::ClassTemplate.template('gimp-gradient-', 'gimp-gradients-')
end
\ No newline at end of file
# GIMP-Ruby -- Allows GIMP plugins to be written in Ruby.
# Copyright (C) 2006 Scott Lembcke
#
# 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., 51 Franklin Street, Fifth Floor,Boston, MA
# 02110-1301, USA.
require 'gimp_oo.rb'
module Gimp
Image = GimpOO::ClassTemplate.template('gimp-image-', nil)
class Image
add_class_method('list', 'gimp-image-list')
alias_method :old_undo_group_start, :undo_group_start
def undo_group
old_undo_group_start
if block_given?
begin
yield
ensure
undo_group_end
end #begin
end #if
end #def
alias_method :old_undo_disable, :undo_disable
def undo_disable
old_undo_disable
if block_given?
begin
yield
ensure
undo_enable
end
end #if
end #def
end #class
end #module
\ No newline at end of file
# GIMP-Ruby -- Allows GIMP plugins to be written in Ruby.
# Copyright (C) 2006 Scott Lembcke
#
# 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., 51 Franklin Street, Fifth Floor,Boston, MA
# 02110-1301, USA.
require 'gimp_oo.rb'
module Gimp
Layer = GimpOO::ClassTemplate.template('gimp-layer-', nil, Gimp::Drawable)
end
\ No newline at end of file
# GIMP-Ruby -- Allows GIMP plugins to be written in Ruby.
# Copyright (C) 2006 Scott Lembcke
#
# 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., 51 Franklin Street, Fifth Floor,Boston, MA
# 02110-1301, USA.
require 'gimp_oo.rb'
module Gimp
Palette = GimpOO::ClassTemplate.template('gimp-palette-', 'gimp-palettes-')
end
\ No newline at end of file
# GIMP-Ruby -- Allows GIMP plugins to be written in Ruby.
# Copyright (C) 2006 Scott Lembcke
#
# 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., 51 Franklin Street, Fifth Floor,Boston, MA
# 02110-1301, USA.
require 'gimp_oo.rb'
module Gimp
Progress = GimpOO::ModuleTemplate.template('gimp-progress-')
end
\ No newline at end of file
# GIMP-Ruby -- Allows GIMP plugins to be written in Ruby.
# Copyright (C) 2006 Scott Lembcke
#
# 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., 51 Franklin Street, Fifth Floor,Boston, MA
# 02110-1301, USA.
require 'gimp_oo.rb'
module Gimp
Selection = GimpOO::ModuleTemplate.template('gimp-selection-')
end
\ No newline at end of file
# GIMP-Ruby -- Allows GIMP plugins to be written in Ruby.
# Copyright (C) 2006 Scott Lembcke
#
# 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., 51 Franklin Street, Fifth Floor,Boston, MA
# 02110-1301, USA.
require 'gimp_oo.rb'
module Gimp
Vectors = GimpOO::ClassTemplate.template('gimp-vectors-', nil)
end
\ No newline at end of file
......@@ -81,6 +81,7 @@ module PDB
begin
result = args.zip(paramdefs).collect do|arg, paramdef|
arg = bool2int_filter(arg)
paramdef.check(arg)
Gimp::Param.new(paramdef.type, arg)
end
......
......@@ -163,7 +163,7 @@ module RubyFu
case @type
when :toolbox
[Gimp::ParamDef.INT32('run-mode', 'Run mode')]
when :images
when :image
[
Gimp::ParamDef.INT32('run-mode', 'Run mode'),
Gimp::ParamDef.IMAGE('image', 'Input image'),
......@@ -200,17 +200,27 @@ module RubyFu
end
end
def run_interactive(args)
return run_noninteractive(args) if @params.empty?
def get_interactive_args
return [] if @params.empty?
args = RubyFu.dialog(@menulabel, @name, @params)
raise Cancel unless args
Gimp::Shelf[@name + ':last_params'] = args
args
end
interactive_args = RubyFu.dialog(@menulabel, @name, @params)
raise Cancel unless interactive_args
def get_last_args
args = Gimp::Shelf[@name + ':last_params']
args += interactive_args
return @function.call(*args)
if args
args
else
default_args
end
end
def run_noninteractive(args)
def run_with_args(args)
nargs = args.length
nparams = @fullparams.length
unless nargs == nparams
......@@ -220,35 +230,26 @@ module RubyFu
return @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
return @function.call(*args)
end
def run(*args)
#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
require 'gimp_oo.rb'
extra_args = case runMode
when Gimp::RUN_INTERACTIVE: get_interactive_args
when Gimp::RUN_WITH_LAST_VALS: get_last_args
else []
end
args = args.zip(@fullparams).collect do|arg, param|
raise(CallError, "Bad argument") unless arg.type == param.type
next arg.transform
end
values = case runMode
when Gimp::RUN_INTERACTIVE: run_interactive(args)
when Gimp::RUN_NONINTERACTIVE: run_noninteractive(args)
when Gimp::RUN_WITH_LAST_VALS: run_last_vals(args)
end
values = run_with_args(args + extra_args)
if values == nil
values = []
else
......@@ -264,6 +265,7 @@ module RubyFu
begin
values = values.zip(@results).collect do|value, result|
value = bool2int_filter(value)
result.check(value)
Gimp::Param.new(result.type, value)
end
......@@ -278,7 +280,7 @@ module RubyFu
@@procedures = {}
def self.register(
def register(
name,
blurb,
help,
......@@ -307,6 +309,7 @@ module RubyFu
@@procedures[name] = proc
end
module_function :register
def self.query
@@procedures.each_value{|proc| proc.query}
......
......@@ -5,10 +5,17 @@ pluginexecdir = $(GIMP_PLUGINDIR)
scripts = \
coolmetal-logo.rb \
sphere.rb \
irbconsole.rb
irbconsole.rb \
runfile.rb \
rerunfile.rb \
gloom.rb \
sunset.rb \
helloworld.rb
test_scripts = \
test.rb
test.rb \
speed.rb
if GIMPRUBY_UNSTABLE
......
require 'rubyfu'
Size = 256
include Gimp
include RubyFu
register(
'ruby-fu-gloom', #procedure name
'', #blurb
'', #help
'Scott Lembcke', #author
' Scott Lembcke', #copyright
'2006', #date
'<Image>/Ruby-Fu/Gloom', #menupath
'*', #image types
[
ParamDef.SLIDER('radius', 'Radius', 5.0, 0..50, 0.1),
ParamDef.SLIDER('amount', 'Amount', 100, 0..100, 1),
], #params
[] #results
) do|run_mode, image, drawable, radius, amount|
include PDB::Access
image.undo_group do
gloom = Layer.new_from_drawable(drawable, image)
image.add_layer(gloom, -1)
gimp_drawable_set_name(gloom, 'gloom')
gloom.set_mode(DARKEN_ONLY_MODE)