From: Phlip Date: 2004-08-20T01:27:10+09:00 Subject: Re: Fake Tk events Hidetoshi NAGAI wrote: > One of the examples of remote control with Tcl's send command > is 'ext/tk/lib/remote-tk.rb' (included in 1.8.2 preview). > The library can create a remote interpreter object to control > a Tk interpreter on the other process. > 'ext/tk/sample/remote-ip_sample*.rb' are samples of the library. Someone needs to say to me "send" sends commands over a network. Nobody has said that yet. If they did, I would not try to use it. > About 'event generation', I wrote an example in my Ruby/Tk book > (Japanese). The following is the example (but a little changed). > It is also an example of 'Tk.callback_continue/callback_break', > 'bindtag' and 'virtual event'. I will try that next. But I'm stuck again, here: require 'tk' require 'test/unit' 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(how, :x => cx, :y => cy) end def test_simulateMouseClick() @canvas = TkCanvas.new() @canvas.configure('width', 600) @canvas.configure('height', 600) @canvas.grid() 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() Tk.restart() end def test_selectNode() @canvas = TkCanvas.new() @canvas.configure('width', 600) @canvas.configure('height', 600) @canvas.grid() 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() Tk.restart() end end Those tests fail. They try to create a canvas, click on it, destroy it, restart Tk, create a canvas, and click on it again. Whichever test case runs last, based on its name, fails. The assert(weGotClicked) is false. Is this because I call Tk.update() twice in a row? -- Phlip http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces