Tk.generate_event before mainloop

Rubies:

I’m trying to do this pattern in Tk instead of Gtk:

    http://www.c2.com/cgi/wiki?ThenDontCallMainLoop

I’m doing a mouse- and keystroke intense app and need to test-first at that
level. Hence I would like to call event_generate, but possibly without
calling mainloop. Ogle this:

#!/usr/bin/env ruby

require “tk”

def main

    top = TkRoot.new
    canvas  = TkCanvas.new (top)
    canvas.grid 'row'=>0, 'column'=>0, 'sticky'=>'ew'
            canvas.configure 'width' => 200, 'height' => 500

    shape = [30, 30, 30, 60, 60, 30 ] 

    poly1 = TkcPolygon.new(canvas, shape) { 
        fill 'green'
         }
    
    poly1.bind ('Button-1') {
        puts 'yo'
        poly1.configure 'fill' => 'red'

Tk.event_generate(poly1, ‘Button-1’) # <-- yo

        }
    Tk.update
    Tk.event_generate(poly1, 'Button-1')
    Tk.update
    Tk.mainloop

end

main

If we de-comment the line marked “yo”, we get infinite recursion. So
event_generate works.

But the lowest call to event_generate, above the Tk.mainloop that we’d like
to take out, does not propagate, even though we pump the event queue before
and after with ‘update’.

Any tips?

···


Phlip
http://www.c2.com/cgi/wiki?PhlIp
– Set phasers on illin’ –