PHP-GTK2 Cookbook Forum
Welcome, Guest
Please Login or Register.    Lost Password?
(Newbie question) How to access widget childs? (12 viewing) (12) Guests
Go to bottom Post Reply Favoured: 2
TOPIC: (Newbie question) How to access widget childs?


#4998
Malachite (User)
Fresh Boarder
Posts: 2
graphgraph
User Offline Click here to see the profile of this user
(Newbie question) How to access widget childs? 2 Years, 10 Months ago Karma: 1  
If I have a structure like that:
Code:
mainWindow
|--- vbox
     |--- anotherWidget
how can I access anotherWidget? All widgets have IDs, so I could easily access itů If I know how.
 
  The administrator has disabled public write access.

#5001
kksou (Admin)
Admin
Posts: 1728
graph
User Online Now Click here to see the profile of this user
Re:(Newbie question) How to access widget childs? 2 Years, 10 Months ago Karma: 27  
Hi,

Don't think there's a function that allows you to retrieve a widget by using widgetID.

For your case, you can retrieve each of the widget by using $widget->get_child() recursively.

Note that for GtkBin, it can contain one child only. You use: GtkBin::get_child()
e.g. Sample Code 186: How to change the font and font size of GtkButton?

For containers such as GtkVBox, it can contain multiple children. You use: GtkContainer::get_children()
e.g. Sample Code 100: How to change window contents on the fly by adding and removing widgets?

Regards,
/kksou
 
  The administrator has disabled public write access.

#5007
Malachite (User)
Fresh Boarder
Posts: 2
graphgraph
User Offline Click here to see the profile of this user
Re:(Newbie question) How to access widget childs? 2 Years, 10 Months ago Karma: 1  
I didn't find such a function, so I wrote it myself:
Code:
function getWidget($obj,$id) {
	if ((!is_subclass_of($obj,'GtkContainer'))) {
		return null;
	} elseif ($obj->name == $id) {
		return $obj;
	} else {
		foreach ($obj->get_children() as $child) {
			if ($child->name == $id) {
				return $child;
			} elseif ($cchild = getWidget($child,$id)) {
				return $cchild;
			} else {
				return false;
			}
		}
	}
}
 
  The administrator has disabled public write access.
#5066
melsi (User)
Fresh Boarder
Posts: 2
graphgraph
User Offline Click here to see the profile of this user
Re:(Newbie question) How to access widget childs? 2 Years, 9 Months ago Karma: 0  
Very well done!
 
  The administrator has disabled public write access.



Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2012. kksou.com. All Rights Reserved