[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

annoying problem with gnome2 canvas

Tool69

1/20/2006 10:58:00 PM

Hello,
I'm trying different things with the gnome2canvas, but don't understand
the following behaviour :

#!/usr/bin/env ruby

require 'gtk2'
require 'gnomecanvas2'

def item_event(item, event)
case event.event_type
when Gdk::Event::BUTTON_PRESS
item_x, item_y = item.parent.w2i(event.x, event.y)
case event.button
when 1
if event.state & Gdk::Window::SHIFT_MASK ==
Gdk::Window::SHIFT_MASK
item.destroy()
else
@x = item_x;
@y = item_y;
fleur = Gdk::Cursor.new(Gdk::Cursor::FLEUR)
item.grab(Gdk::Event::POINTER_MOTION_MASK |
Gdk::Event::BUTTON_RELEASE_MASK,
fleur,
event.time)
@dragging = true
end
when 2
if event.state & Gdk::Window::SHIFT_MASK ==
Gdk::Window::SHIFT_MASK
item.lower_to_bottom()
else
item.lower(1)
end
when 3
if event.state & Gdk::Window::SHIFT_MASK ==
Gdk::Window::SHIFT_MASK
item.raise_to_top()
else
item.raise(1)
end
end
when Gdk::Event::MOTION_NOTIFY
item_x, item_y = item.parent.w2i(event.x, event.y)
if @dragging && (event.state & Gdk::Window::BUTTON1_MASK ==
Gdk::Window::BUTTON1_MASK)
item.move(item_x - @x, item_y - @y)
@x = item_x;
@y = item_y;
end
when Gdk::Event::BUTTON_RELEASE
item.ungrab(event.time)
@dragging = false;
end
end

def setup_item(item)
item.signal_connect("event") do |item, event|
item_event(item, event)
end
end

Gtk.init

@ECX = 600
@ECY = 600

@combo1 = Gtk::ComboBox.new(true)
@combo1.append_text("Build")
@combo1.append_text("Move")
@combo1.set_active(0)

@labelcoord = Gtk::Label.new("")

@box1 = Gtk::HBox.new(false,5)
@boxv1 = Gtk::VBox.new(false,5)
@boxv2 = Gtk::VBox.new(false,5)

@canvas = Gnome::Canvas.new(true)

@zoomf = 1
@canvas.set_pixels_per_unit(@zoomf)
@canvas.set_size_request(@ECX, @ECY)
@canvas.set_scroll_region(0, 0, @ECX, @ECY)
@root = @canvas.root

# ScrolledWindow
@scroller = Gtk::ScrolledWindow.new
@scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC )
@scroller.add( @canvas )

# Main window
window = Gtk::Window.new
window.signal_connect("destroy") {
puts "Bye."
Gtk.main_quit
}

@boxv1.pack_start(@combo1,false, false, 0)
@box1.pack_start(@boxv1)
@box1.pack_start(@boxv2)
@boxv1.pack_start(@labelcoord,false, false, 0)
@boxv2.pack_start(@scroller,false, false, 0)
window.border_width = 10
window.add(@box1)
window.show_all
x,y = 200,200
pt = Gnome::CanvasEllipse.new(@root,{:x1 => x-3,
:y1 => y-3,
:x2 => x+3,
:y2 => y+3,
:outline_color => "goldenrod",
:fill_color_rgba => 0x0000ff80,
:width_units => 0.5})
setup_item(pt)

#@canvas.signal_connect("motion-notify-event") do |widget, event|
#x,y = event.x,event.y
#@labelcoord.set_text("X= #{x}, Y= #{y}")
#end

Gtk.main

You can move the point with the mouse easily, right?
Now, uncomment the last 4 lines before "Gtk.main" : I can't move the
point anymore, and I don't know why.
Thanks for your replies.