Hello,
I'm writing a Ruby-Tk application on the Mac and am trying to hook into the tk_mac module to access some Mac-specific commands from Ruby-Tk. I am having trouble getting the parameters right and am getting errors.
Here is the implementation of the command in question from the tk_mac module:
def self.def_OpenDocument(cmd=Proc.new)
ip_eval("proc ::tk::mac::OpenDocument {args} { eval #{install_cmd(cmd)} $args }")
nil
end
Here is my setup of this call:
Tk::Mac.def_OpenDocument(cmd=proc{setDir})
And here is the "setDir" call that I am using as a callback:
def setDir(file)
if File.directory?(file)
$dirname = file
$dirname.value = file
end
end
On the Mac, the "OpenDocument" command receives an array of files dropped on the application icon as a parameter or argument. I am only dropping a single file (directory) on the icon, but I consistently get this error:
ArgumentError: wrong number of arguments (given 0, expected 1)
The backtrace says the directory name arg is getting lost when passed to Ruby. What I am not clear on is how to set up the callback in the Tk::Mac module with a parameter. Can someone point me in the right direction?
(More backtrace detail below.)
---< backtrace of Ruby side >-----
/Users/kevin/Programming/stringscan/build/Stringscan.app/Contents/Resources/main.rb:174:in `setDir'
/Users/kevin/Programming/stringscan/build/Stringscan.app/Contents/Resources/main.rb:184:in `block in initialize'
/Users/kevin/Programming/stringscan/build/Stringscan.app/Contents/Resources/lib/ruby/2.3.0/tk.rb:1456:in `eval_cmd'
/Users/kevin/Programming/stringscan/build/Stringscan.app/Contents/Resources/lib/ruby/2.3.0/tk.rb:1456:in `cb_eval'
/Users/kevin/Programming/stringscan/build/Stringscan.app/Contents/Resources/lib/ruby/2.3.0/tk.rb:1403:in `call'
/Users/kevin/Programming/stringscan/build/Stringscan.app/Contents/Resources/lib/ruby/2.3.0/tk.rb:1607:in `block in callback'
/Users/kevin/Programming/stringscan/build/Stringscan.app/Contents/Resources/lib/ruby/2.3.0/tk.rb:1606:in `catch'
/Users/kevin/Programming/stringscan/build/Stringscan.app/Contents/Resources/lib/ruby/2.3.0/tk.rb:1606:in `callback'
/Users/kevin/Programming/stringscan/build/Stringscan.app/Contents/Resources/lib/ruby/2.3.0/tk.rb:1871:in `mainloop'
/Users/kevin/Programming/stringscan/build/Stringscan.app/Contents/Resources/lib/ruby/2.3.0/tk.rb:1871:in `mainloop'
/Users/kevin/Programming/stringscan/build/Stringscan.app/Contents/Resources/main.rb:190:in `<main>'
---< backtrace of Tk side >-------
invoked from within
"rb_out c00001 /Users/kevin/Programming/stringscan/maclibs"
("eval" body line 1)
invoked from within
"eval rb_out c00001 $args "
(procedure "::tk::mac::OpenDocument" line 1)
invoked from within
"::tk::mac::OpenDocument /Users/kevin/Programming/stringscan/maclibs"
Thank you,
Kevin
···
--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com