gnope php gtk gui gnope.org  

Referring to widgets

 
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners
View previous topic :: View next topic  
Author Message
edlynn



Joined: 29 Sep 2006
Posts: 10

PostPosted: Fri Sep 29, 2006 5:42 pm    Post subject: Referring to widgets Reply with quote

Sorry if this is a daft question, i'm just starting out with gtk, but when i want to refer to a widget, to call a function on it, do i always have to get it first or is there a shorter way of referring to it? at the mo im always doing...

Code:

$add_button = $glade->get_widget('add_button');
$add_button->grab_focus();


Can i not just do it in 1 line please?[/code]
Back to top
cweiske



Joined: 08 Dec 2005
Posts: 454
Location: Leipzig/Germany

PostPosted: Sat Sep 30, 2006 6:25 am    Post subject: Reply with quote

You could do
Code:
$glade->get_widget("name")->method()

but that's not what you want.

Another idea would be to use the magic methods of php5, e.g. __get() if you are using classes(!)

Code:

class something {
  function __get($name) {
    return $this->glade->get_widget($name);
  }

  function doSomething()
  {
    //if $widgetname does not exist as class variable, __get() will be called
    $this->widgetname->grab_focus();
  }
}
Back to top
edlynn



Joined: 29 Sep 2006
Posts: 10

PostPosted: Mon Oct 02, 2006 10:52 am    Post subject: Reply with quote

Ah right, yes the first of those is fine thanks very much!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Templates enhanced by DigiWiki. Hosting by Tradebit.