Re: How to pass value back to main via object



Tyler Hepworth said:
I am just learning about OO perl and trying to grasp how to tie it in with
Gtk2.  The question I have is how can I pass a value back to the main loop
after the loop has already been invoked.

Example:

#!/usr/perl/bin

my $self = Main->new->mainLoop; #Create a new object and start the loop
$self->{'window'}->set_default_size (700,450); # How can I make the loop
obey this command?

in the mainLoop function you call Gtk2->main. at that point control will be
inside of gtk+ and your app will no longer exec. its code (outside of
callbacks) until a Gtk2->main_quit is called.

one suggestion i would make based on the code here is not to have the package
Main. that package doesn't really do anything that couldn't be acomplished by
putting hash keys into and calling methods of Gtk2::Window. If you really want
you can create a descendant object of Gtk2::Window (see perldoc
Glib::Object::Subclass.) beyond that you probably don't want an object method
calling Gtk2->main, it's just unclear what's happening.

another posibility is to set_default_size in a signal or idle handler.

this is something like what i would do, doesn't make it right:

my $app = AppWindow->new;
$app->setup;
$app->show_all;
$app->set_default_size (700, 450);
# do everything you have to do before calling Gtk2->main.
Gtk2->main;

package AppWindow;

use Gtk2;
use Glib::Object::Subclass
    Gtk2::Window::
    ;
# at this point there's nothing else you really need above, but depending on
your deatils you may want to add properties and/or signals.

sub setup
{
     my $self = shift;
     $self->signal_connect (delete_event => sub {Gtk2->main_quit});
$self->set_title ('Object Browser');
}

-rm





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]