|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Button How to intercept signal from a istance of class into another classProblem:
I have a main window class ( Attntion: are two distinc classes ) class mywin extends GtkWindow { ...constructor... ... // Now I Instantiate buttons class $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 class where it is Instantiate How can I make it ??? } } Thanks |
|
|
Re: Button How to intercept signal from a istance of classinto another classAngeloP wrote:
> 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 > This is a basic PHP and object oriented programming question - please read the manual. To access any method in a child class (a class that extends another class) you use parent so onClose should call parent::OneFunction(); Thanks Elizabeth -- PHP-GTK General Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Button How to intercept signal from a istance of classinto another classI think you have not understood
It is not possible use this sintax parent::OneFunction(); because the mybuttons doesn't extends mywin class at this moment I use one method that find parent window for button In class mybuttons ... // find window parent public function get_window(){ $parent = $this; do{ $w = $parent; $parent = $w->get_parent(); } while($parent != null); return $w; } // Fine cerca window parent And then callback function OnClose($button) { $win =$this->get_window(); $win->myfunction(); return true; } |
|
|
Re: Button How to intercept signal from a istance of class into another classOk, 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 |
| Free embeddable forum powered by Nabble | Forum Help |