From: Phlip Date: 2004-08-23T23:50:45+09:00 Subject: Re: Fake Tk events Hidetoshi NAGAI wrote: > > > > what.event_generate('Motion', :x => cx, :y => cy) > > > > what.event_generate(how, :x => cx, :y => cy) > > > > end > > Noop. It no worky. Don't sweat this - nobody pushes libraries where I push > > them. Thanks again for the help. > > Even if you change 'Motion' to 'Enter', do you get the same result? > How about adding what.event_generate('Enter', :x => cx, :y => cy) > before the 'Motion' line? That worked! Did it work for you? > It seems that the problem exists on Tcl/Tk side (on the opration of > canvas widget), because wish has the same problem. The canvas widget > accepts all of the generated event ( You can test it by setting a > binding for the canvas. And it shows that the 'event_generate' works > properly.), but sometimes fails to call the binding of the canvas > item. I'm sorry but I couldn't find the conditions to succeed or not. > I'm sorry I cannot help you. In this source, without the line what.event_generate('Enter', :x => cx, :y => cy), the second test to run (in alpha order) fails, despite it's exactly the same as the first. The sequence of events is: - create a canvas - populate - update - generate a click - detect the click - remove all items - populate - update - generate a click - detect the click <--- failure The fix is to push an 'Enter' event into the event queue. require 'tk' require 'test/unit' def doc(anObject) puts(anObject.class.name) itsMethods = anObject.public_methods() - Object.new().public_methods() puts(itsMethods.sort()) if !itsMethods.nil? end class TestGrapher < Test::Unit::TestCase def click(what, how = 'Button-1') x1,y1,x2,y2 = what.bbox cx = (x2 + x1) / 2 cy = (y2 - y1) / 2 Tk.update() what.event_generate('Enter', :x => cx, :y => cy) what.event_generate(how, :x => cx, :y => cy) end def test_simulateMouseClick() Tk.restart() root = Tk.root() @canvas = TkCanvas.new(root) @canvas = TkCanvas.new() @canvas.configure('width', 600) @canvas.configure('height', 600) @canvas.pack() TkcOval.new(@canvas, 5.0, 12.0, 59.0, 48.0, :fill=>'red') oval = @canvas.find_all()[0] assert_equal(oval.class.name(), 'TkcOval') eventWasCalled = false oval.bind('Button-1') { |event| eventWasCalled = true } click(oval) assert(eventWasCalled) @canvas.destroy() root.withdraw() end def test_selectNode() Tk.restart() root = Tk.root() @canvas = TkCanvas.new(root) @canvas.configure('width', 600) @canvas.configure('height', 600) @canvas.pack() TkcOval.new(@canvas, 5.0, 12.0, 59.0, 48.0, :fill=>'red') oval = @canvas.find_all()[0] assert_equal('TkcOval', oval.class.name()) weGotClicked = false oval.bind('Button-1') { |event| weGotClicked = true } click(oval) assert(weGotClicked) @canvas.destroy() root.withdraw() end end -- Phlip http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces