[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

mouse coordinates in a gnome2 canvas

Tool69

1/3/2006 2:55:00 PM

Hi,
I want to show the mouse coordinates inside a label in a gnome2
application if my mouse is on a canvas. How to procede ? I' ve found no
documentation on the canvas on ruby gnome2 API. rbbr is not working on
my ubuntu (no description at all), so you're my last chance...
In fact, it's not really a canvas problem but more a gtk one. I've
tried something like :

@ecran = Gdk::Display.default
canvas.signal_connect("event") do
pos = @ecran.window_at_pointer
@label1.set_text("x=#{pos[1]}")
@label2.set_text("y=#{pos[2]}")
end

....but then all my drawings disappear.

Thanks in advance :
6TooL9

2 Answers

Joe Van Dyk

1/3/2006 5:57:00 PM

0

On 1/3/06, Tool69 <kibleur.christophe@gmail.com> wrote:
> Hi,
> I want to show the mouse coordinates inside a label in a gnome2
> application if my mouse is on a canvas. How to procede ? I' ve found no
> documentation on the canvas on ruby gnome2 API. rbbr is not working on
> my ubuntu (no description at all), so you're my last chance...
> In fact, it's not really a canvas problem but more a gtk one. I've
> tried something like :
>
> @ecran = Gdk::Display.default
> canvas.signal_connect("event") do
> pos = @ecran.window_at_pointer
> @label1.set_text("x=#{pos[1]}")
> @label2.set_text("y=#{pos[2]}")
> end
>
> ....but then all my drawings disappear.

require 'gnomecanvas2'

Gtk.init

window = Gtk::Window.new "Mouse Coordinate display"
window.set_default_size 300, 300
grid = Gtk::VBox.new
window << grid

canvas = Gnome::Canvas.new
grid.pack_start canvas

coord_label = Gtk::Label.new "sup"
grid.pack_start coord_label, false

window.show_all

window.signal_connect("destroy") { Gtk::main_quit }

canvas.signal_connect("motion-notify-event") do |widget, event|
x = event.x
y = event.y
coord_label.text = "X Pos: #{ x }, Y Pos: #{ y }"
end

Gtk::main


Tool69

1/3/2006 6:56:00 PM

0

Thanks Joe,
I thought that it was impossible to connect the canvas to something
other than "event".
Your code helped me a lot to understand.