runfile.rb 2.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/usr/bin/env ruby

# 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.

21
require "rubyfu"
22 23 24 25 26 27

include Gimp
include RubyFu

module RubyFu
  class Procedure
Scott Lembcke's avatar
Scott Lembcke committed
28
    attr_reader :type
29 30 31 32 33 34 35 36 37 38 39 40 41
  end

  def self.test_proc(procname, drawable)
    proc = @@procedures[procname]
    
    params = proc.fullparams
    case proc.type
    when :toolbox:
      proc.run(Param.INT32(RUN_INTERACTIVE))
    when :image:
      image = Param.IMAGE(PDB.gimp_drawable_get_image(drawable))
      drawable = Param.DRAWABLE(drawable)
      proc.run(Param.INT32(RUN_INTERACTIVE), image, drawable)
Scott Lembcke's avatar
Scott Lembcke committed
42
    else
43 44 45 46 47 48
      args = RubyFu.dialog("Testing #{procname}", procname, params)
      proc.run(*args)
    end
  end
end

Scott Lembcke's avatar
Scott Lembcke committed
49
help_string = _(
50 51 52 53
  "The procedure argument should be the name of the " +
  "procedure defined in the file you wish to run. " +
  "The drawable argument is only needed if the procedure "+
  "is image based."
Scott Lembcke's avatar
Scott Lembcke committed
54 55
)

56
register(
57 58
  "ruby-fu-run-file", #procedure name
  _("Runs a Ruby-Fu script without requiring you to install it."), #blurb
Scott Lembcke's avatar
Scott Lembcke committed
59
  help_string, #help
60 61 62 63
  "Scott Lembcke", #author
  "Scott Lembcke", #copyright
  "2006", #date
  _("Run File"), #menupath
64 65
  nil, #image types
  [
66 67 68
    ParamDef.FILE("file", _("File")),
    ParamDef.STRING("procedure", _("Procedure name"), "ruby-fu-"),
    ParamDef.DRAWABLE("drawable", _("Drawable (if needed)")),
69 70 71
  ], #params
  [] #results
) do|run_mode, filename, procname, drawable|
72
  Shelf["ruby-fu-last-run-file"] = [filename, procname, drawable]
73 74 75

  load(filename)
  RubyFu.test_proc(procname, drawable)
76 77
end

78
menu_register("ruby-fu-run-file", RubyFuMenu)
Scott Lembcke's avatar
Scott Lembcke committed
79 80


81
register(
82 83
  "ruby-fu-rerun-file", #procedure name
  _("Reruns the last file ran using Runfile"), #blurb
84
  nil, #help
85 86 87 88
  "Scott Lembcke", #author
  "Scott Lembcke", #copyright
  "2006", #date
  _("Rerun File"), #menupath
89 90 91 92
  nil, #image types
  [], #params
  [] #results
) do|run_mode, filename, procname|
93
  last = Shelf["ruby-fu-last-run-file"]
94
  
95
  if last
Scott Lembcke's avatar
Scott Lembcke committed
96
    PDB.ruby_fu_run_file(*last)
97
  else
98
    Gimp.message _("No previous file to run")
99
  end
100
end
Scott Lembcke's avatar
Scott Lembcke committed
101

102
menu_register("ruby-fu-rerun-file", RubyFuMenu)