[prev in list] [next in list] [prev in thread] [next in thread]
List: php-gtk-general
Subject: Re: [PHP-GTK] Button How to intercept signal from a istance of
From: "Pablo Dall'Oglio" <pablo () dalloglio ! net>
Date: 2008-11-01 3:57:38
Message-ID: 1225511858.6674.73.camel () localhost ! localdomain
[Download RAW message or body]
Ok, I got it.
As the first class (mywin) is not the parent class of the second class
(mybuttons), it does not make sense to call parent::... as you have
mentioned.
The right way to do that is to pass the callback signature of the first
method (OneFunction) as an attribute of the mybuttons object OR create a
method in mybuttons class to receive this signature (the same way the
connect() method works).
The simplest way is:
$three_buttons = new mybuttons();
$three_buttons->my_callback = array($this, 'OneFunction');
This way, you have stored this callback inside the $three_buttons
object. But remember the ENCAPSULATION principles... It's better to
create a method to receive this... ;-)
Now, you can use the property my_callback inside the OnClose() method,
this way:
call_user_function($this->my_callback);
www.php.net/call_user_func
But take care with this. If you need $this->my_callback available in the
constructor method of the mybuttons class, you'll need to pass the
callback signature in its constructor method. Because the way I told
you, this signature will be available just before the instantiation...
I hope it's usefull for you.
bests
Pablo Dall'Oglio
Em Qua, 2008-10-29 ās 02:31 -0700, AngeloP escreveu:
> Problem:
> I have a main window class
>
> class mywin extends GtkWindow
> {
> ...constructor...
> ...
>
> // Button section
> $three_buttons = new mybuttons()
> $vbox -> pack_start($three_buttons,0);
> ...... ..etc...
> end constructor
>
> function OneFunction()
> {
> make something
> }
>
> }
>
> class mybuttons extends GtkHbox
> {
> .... constructor
>
> $button_a=new GtkButton("Open");
> $this -> pack_start($button_a,0);
>
> $button_b=new GtkButton("Run");
> $this -> pack_start($button_b,0);
>
> $button_c=new GtkButton("Close");
> $this -> pack_start($button_c,0);
>
> $close_c->connect("clicked", array($this,"OnClose")); // note 6
>
> ...... end cosntructor
>
> function OnClose ($widget )
> {
> Here I would call the function OneFunction() in the parent class
> How can I make it ???
> }
>
> }
>
>
> Thanks
>
> --
> View this message in context: \
> http://www.nabble.com/Button-How-to-intercept-signal-from-a-istance-of-class-into-another-class-tp20223469p20223469.html
> Sent from the Php - GTK - General mailing list archive at Nabble.com.
>
>
--
PHP-GTK General Mailing List (http://gtk.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic