PHP-GTK2 Cookbook Forum
Welcome, Guest
Please Login or Register.    Lost Password?
Get co-ordnates. (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Get co-ordnates.
#497
neil (User)
Junior Boarder
Posts: 20
graphgraph
User Offline Click here to see the profile of this user
Get co-ordnates. 3 Months, 3 Weeks ago Karma: 0  
Hi,

Can I find the position (x,y co-ordinates) of an eventbox, or a label ??

Neil.
 
  The administrator has disabled public write access.
#499
kksou (Admin)
Admin
Posts: 391
graph
User Online Now Click here to see the profile of this user
Re:Get co-ordnates. 3 Months, 3 Weeks ago Karma: 8  
You want to be a bit more specific? x-y co-ordinate of the top, left corner? of the eventbox/label?

Regards,
/kksou
 
  The administrator has disabled public write access.
#501
neil (User)
Junior Boarder
Posts: 20
graphgraph
User Offline Click here to see the profile of this user
Re:Get co-ordnates. 3 Months, 3 Weeks ago Karma: 0  
x-y co-ordinate of the top, left corner? of the eventbox/label ??

yes please, kksou.

(I really want the left/middle, but i expect given the left top, I can use height/2 to work it out).

Neil.
 
  The administrator has disabled public write access.
#503
kksou (Admin)
Admin
Posts: 391
graph
User Online Now Click here to see the profile of this user
Re:Get co-ordnates. 3 Months, 3 Weeks ago Karma: 8  
Use $label->window->get_geometry()

It will return a 5-tuple containing the window's location and size (x, y, width, height) and the bit depth of the window.

Here's a sample code you can try. Take a look in the command window to see the output.

I find that it only works when you stuff the label in an eventbox. If you just use a GtkLabel without GtkEventBox, for some reason, the value does not seem to be correct.

Regards,
/kksou

$window = new GtkWindow();
$window->set_size_request(400, 200);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkVBox());

$vbox->pack_start(new GtkLabel());

$vbox->pack_start($hbox = new GtkHBox());
$hbox->pack_start(new GtkLabel());
$label = new GtkLabel('this is the label');
$hbox->pack_start($eventbox = new GtkEventBox, 0);
$eventbox->add($label);
$eventbox->modify_bg(Gtk::STATE_NORMAL, GdkColor::parse("#aaaaaa"));
$hbox->pack_start(new GtkLabel());

$vbox->pack_start(new GtkLabel());

$window->show_all();

$label_pos = $label->window->get_geometry();
print_r($label_pos);

Gtk::main();
 
  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-2008. kksou.com. All Rights Reserved