Forum: Ruby-Gnome 2 How do you execute code at startup?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0d130f179f85401f248e6ebc2ef8292f?d=identicon&s=25 Eric C. (eric_c)
on 2016-05-24 04:07
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
cursor.

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:

gtk.main
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.

Eric
7157259218d3e6168b9b106b82f0da93?d=identicon&s=25 Cedlemo Cedlemo (cedlemo)
on 2016-05-24 15:55
Hi Eric,

Have you tried to use both move_cursor and a method like scroll_to_iter
before Gtk.main,
https://developer.gnome.org/gtk3/stable/GtkTextVie...
(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.

cedlemo
This topic is locked and can not be replied to.