Re: [gtk-list] Gtk/Perl ..and more questions =-)
- From: Dermot Musgrove <dermot glade perl connectfree co uk>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Gtk/Perl ..and more questions =-)
- Date: Wed, 17 Nov 1999 14:44:41 +0000
Hi, Luis.
Luis Felipe Piccolini Marull wrote:
>
> >
> > and destroy it by calling;
> > $window->TOPLEVEL->destroy;
> >
>
> Thanks a lot for your help Dermont, but i still have a lot of problems
> with my project...
I'm sorry that you are still having problems. I think that they are because
you don't fully understand the object oriented approach of perl and the way
that source code generated by Glade-Perl works. I will try to explain how
Glade-Perl code works but you will need to read the 'perltoot' man pages as
well.
1) The UI object
----------------
Each UI (toplevel form/dialog) is constructed by a separate perl module
(class) and returns a ref to a perl 'object' that has certain properties.
You can access the properties using class methods. If you look at the UI
construction sub (eg Subwin_buscar->new) you will see that the object has
some useful properties set:
$self->FORM($forms->{'Subwin_buscar'});
# FORM is now a ref to the anonymous hash of all widgets on _this_ form
$self->TOPLEVEL($self->FORM->{'Subwin_buscar'});
# TOPLEVEL is now a ref to the toplevel form/dialog in FORM
$self->INSTANCE("Subwin_buscar-$instance");
# INSTANCE is the key used to store a ref to us in the global anonymous
# hash $__PACKAGE__::all_forms.
# The first instance of this FORM (you might have several) will be stored in
# $__PACKAGE__::all_forms->{'Subwin_buscar-1'} and the second in
# $__PACKAGE__::all_forms->{'Subwin_buscar-2'} and so on
$__PACKAGE__::all_forms->{$self->INSTANCE} = $self->FORM;
# We have now stored a ref to _this_ copy of the FORM in the global hash.
return $self;
# We return the object (with the associated methods) for later use.
2) Signal handlers
------------------
Each signal handler is typically called with certain arguments so that
sub on_ctree1_button_press_event {
my ($class, $data, $object, $instance, $event) = @ARG;
will allow you to access all of them. The variables are:
$class a ref to the widget that triggered the signal
$data the data specified in Glade's signal definition
$object the name of the widget that triggered the signal
$instance the key of the particular FORM instance in the global hash
$event this is only defined if the signal was an event and it is a ref
to an event structure. For example, $event->{'button'} is the
mouse button (1, 2, 3 ...) that was pressed
> trying to destroy a window from this one, (a window showed by clicking on
> another one) (sorry for my english) i have this error:
>
> Can't access method `on_boton_21_cerrar_clicked' in class Gtk::Button at
> src/Project2.pm line 3463.
>
[...]
> and when I want to destroy this Subwin_buscar with something like
> window->TOPLEVEL->destroy i have that error.
> Anyway all buttons return this error no matter what they do... why is
> this??? please help me soon....thanks.
So it is no good calling $class->TOPLEVEL->destroy in the signal handler
because in your sub $class is a ref to a Gtk::Button. To destroy the
toplevel window that the button is on you must first get a ref to the
particular instance of the form that the button is on and then destroy that.
so use the code in the generated skeleton signal handlers like:
my $form = $__PACKAGE__::all_forms->{$instance};
# $form is now a ref to the anonymous hash of all widgets on this instance
# and then we can destroy the particular widget that we know is the toplevel
# window (it has the same name as the class).
$form->{'Subwin_buscar'}->destroy;
If you want to do something on another form you will probably want to store
the other form's instance name in a global somewhere or in the UI object
structure so that you can get to it from any signal handler whatever form
the signal was triggered from.
I'm sure that there is a better way that would make the UI objects more
obvious but this is how it works at the moment.
Please ask again if I have not been clear, it is not simple and it took me
a long time to understand myself :)
HTH, Dermot
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]