| View previous topic :: View next topic |
| Author |
Message |
edlynn
Joined: 29 Sep 2006 Posts: 10
|
Posted: Fri Sep 29, 2006 5:42 pm Post subject: Referring to widgets |
|
|
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
|
Posted: Sat Sep 30, 2006 6:25 am Post subject: |
|
|
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
|
Posted: Mon Oct 02, 2006 10:52 am Post subject: |
|
|
| Ah right, yes the first of those is fine thanks very much! |
|
| Back to top |
|
 |
|