Just about everything in Gtk2 is event-driven, so if you add an event-watcher to the $image, as it's being loaded, it emits an "expose event" when displayed.
sub load_image {
...
....
....
$vp->add( $image );
# add event watcher
$image->signal_connect(
event => sub {
my ( $item, $event ) = @_;
warn "event " . $event->type . "\n";
return 0; #return 1 prevents window from closing
# return 0 lets the signal thru
}
);
.....
.....
}
Now, it would seem that you could just wait until the expose event occurs before proceeding. What the best way to do that
is probably a resettable flag $is_image_exposed, and go into a non-blocking delay until it is 1.
I havn't tested that, and there may be other ways. Read "perldoc Gtk2::Widget" and look for things like "$widget->has_screen" ( and others). The docs for Gtk2 are pretty meager, and require alot of experimentation to get the right code. But if you ask me, just set the delay slower. :-)
|