Automate a button click


Anyone know what’s the matter with this code to automate a button click?

def make_event_button(window, x, y, button, type)
case type
when :press
event_button =
when :release
event_button =
event_button.x = x
event_button.y = y
event_button.button = button
event_button.time = Gdk::Event::CURRENT_TIME
event_button.window = window

def left_click_on(widget)
make_event_button(widget.window, 0, 0, 1, :press).put
make_event_button(widget.window, 0, 0, 1, :release).put




Daniel Benjamin Lucraft


am Thu, 23 Apr 2009 20:17:04 +0100, tat Daniel L.
removed_email_address@domain.invalid der Welt kund:

Anyone know what’s the matter with this code to automate a button click?


I don’t know, whats wrong with your code, but if you only want to
simulate a button click, why not simply use Gtk::button.activate?

Cheers, detlef


Yes, thanks for the tip. I’d prefer to create click events because I
am trying to simluate user input as closely as possible for my
features. Code that simulates a click can be used everywhere, not just
on a button widget.

I tried the activate option anyway (I’ll try anything at this point)
but ran into problems. It works on standard buttons, but for some
reason when I call ‘activate’ on a button in a (non-modal)
FileChooserDialog, the dialog will hang with the button depressed.

I’ve not been able to figure out why this is. The stranger part is
that it doesn’t just hang my application, but in fact hangs the event
loops for ALL applications I have open. I can just about tell Ubuntu
to forcibly close my app, which brings everything else back to life,
thankfully. But my app is dead to the world.

What strange spirits have I angered, please?


Daniel Benjamin Lucraft

2009/4/23 Detlef R. removed_email_address@domain.invalid:


Cant you use this:


To trigger a signal?