Hi, 

From: "Phlip" <phlip_cpp / yahoo.com>
Subject: Fake Tk events
Date: Sun, 15 Aug 2004 10:46:05 +0900
Message-ID: <bazTc.3013$Y94.2098 / newssvr33.news.prodigy.com>
>  tx.bind('Button-1') { |e|
>   p e.x
>   p e.y
>   }
> 
>  entry = tx.bindinfo('Button-1')[0][0]
> 
>   entry.call( 21, "??", 1, 0, "??", true, 0, "i", 1, "NotifyNormal",
>                 false, "PlaceOnTop", 0, 7595922, 0, 115, 200, "??", 269,
>                 1, false, "??", 1, "0x0", "0x0", 4, nil, 269, 376 )

Because Tcl/Tk treats all values as strings, Ruby/Tk wraps 
a callback procedure in an argument converter.
The 'bindinfo' method returns the wrapping procedure. 
So, each of arguments of the procedure must be a string.
TkComm.simplelist method may be useful when arguments 
include null strings. 

  TkComm.simplelist('21 ?? 1 0 ?? true 0 i 1 NotifyNormal false PlaceOnTop 0 7595922 0 115 200 ?? 269 1 false ?? 1 0x0 0x0 4 {} 269 376')
   #==> ["21", "??", "1", "0", "??", "true", "0", "i", "1", "NotifyNormal", "false", "PlaceOnTop", "0", "7595922", "0", "115", "200", "??", "269", "1", "false", "??", "1", "0x0", "0x0", "4", "", "269", "376"]

Of course, if you know the body of the callback procedure, 
you can call the procedure with a created TkEvent::Event object. 

   cb_proc = proc{|e| p e.x; p e.y}
   tx.bind('Button-1', cb_proc)
   cb_proc.call(TkEvent::Event.new( 21, "??", 1, 0, "??", true, 0,
                                   "i", 1, "NotifyNormal", false, 
                                   "PlaceOnTop", 0, 7595922, 0, 
				   115, 200, "??", 269, 1, false, 
                                   "??", 1, "0x0", "0x0", 4, nil, 
                                   269, 376))

However, in this case, it seems that you need only 2 arguments, x and y.
It it is true, it is worthless to give the other arguments. 

   cb_proc = proc{|x, y| p x; p y}
   tx.bind('Button-1', cb_proc, '%x %y')
   entry = tx.bindinfo('Button-1')[0][0]
   entry.call(*%w(115 200))

# In this case, Ruby 1.8.2 preview returns a 'nil' for 
# tx.bindinfo('Button-1')[0][1]. 
# It is a bug. I'll fix it.

BTW, when callback arguments are given by '%' substitution, 
you can give some extra arguments. For example, 

   cb_proc = proc{|x, y, sft, btn| p x; p y; p sft; p btn}
   tx.bind('Button-1', cb_proc, '%x %y no-shift 1')
   tx.bind('Button-2', cb_proc, '%x %y no-shift 2')
   tx.bind('Shift-Button-1', cb_proc, '%x %y shift 1')
   tx.bind('Shift-Button-2', cb_proc, '%x %y shift 2')

-- 
                                  Hidetoshi NAGAI (nagai / ai.kyutech.ac.jp)