How do you execute code at startup?

I have a Gtk::TextView in my program, and I’m trying to make the cursor
in the textview move to line 30, then scroll the textview so the cursor
is visible on the screen. Sounds simple?

The method to move the cursor and scroll the textview works perfectly.
The problem is that I can’t get it to run at startup time.

When I try to move the cursor before gtk.main is called, it sets the
cursor to the proper position, but the screen doesn’t scroll to show the

The scrolling of the textview is animated so it must be done in the gtk
main loop. That means it must be called AFTER gtk.main. But this
doesn’t work:

move_cursor(3) #never gets here

Gtk.main is blocking.

So once gtk.main is called I need to execute this code one at startup
when everything is shown in the window, so it can animate. is there an
event that happens once that signals the start of the loop?

is there an event called start_of_processing_events?

or start_event_handling_to_help_eric?

This issue is a lot harder than it looks.


Hi Eric,

Have you tried to use both move_cursor and a method like scroll_to_iter
before Gtk.main,

(it should be Gtk::TextView#scroll_to_iter). I have not tested this.

It would be very helpfull if you could provide a simple working example
that illustrate your problem.