HOWTO?: tooltips for Gnome canvas items
- From: Jeremy Henty <jeremy chaos org uk>
- To: GTK users <gtk-list gnome org>
- Subject: HOWTO?: tooltips for Gnome canvas items
- Date: Sun, 17 Oct 2004 14:12:57 +0100
I'd like my application to have tooltips for individual Gnome canvas
items. My approach is to set the tooltip for the canvas and enable
and disable it as the mouse passes over the items. Provided I prod
the canvas with an event it *nearly* works. But the tooltip appears
just beneath the bottom of the canvas, not at the item. Can this be
worked around, or is this kludge just not going to work?
(Code attached but you'll need Ruby and ruby-gnome to run it.
Hopefully just reading it will make it clear what I'm doing; the
correspondence between the Ruby and Gtk APIs is straightforward.)
Cheers,
Jeremy Henty
#!/usr/bin/env ruby
# An attempt to implement tooltips for Gnome canvas items by
# attaching a tooltip to the canvas and enabling it and disabling it
# as the mouse passes over the items. We have to send an
# enter-notify event to the canvas to get it to work. But the tip
# appears at the bottom of the canvas! Aargh!
VERBOSE = true
require "gtk2"
require "gnomecanvas2"
def main
Gtk.init
Window.new.show_all
Gtk.main
end
class Window < Gtk::Window
def initialize
super()
set_title("Canvas Tips")
signal_connect("destroy") do
Gtk.main_quit
end
add(Canvas.new)
end
end
class Canvas < Gnome::Canvas
def initialize
super()
tips = Gtk::Tooltips.new
tips.set_tip(self,"Canvas!",nil)
tips.disable
[ -50, +50, ].each do |x|
[ -50, +50, ].each do |y|
Splot.new(self,tips,x,y)
end
end
end
end
class Splot < Gnome::CanvasEllipse
def initialize(canvas,tips,x,y)
radius = 5
parameters = {
:fill_color => "black",
:x1 => x - radius,
:x2 => x + radius,
:y1 => y - radius,
:y2 => y + radius,
}
super(canvas.root,parameters)
# return
signal_connect("event") do |item,event|
case event.event_type
when Gdk::Event::Type::ENTER_NOTIFY
tips.set_tip(canvas,"Item @ (#{x},#{y})",nil)
tips.enable
ev_new = Gdk::EventCrossing.new(Gdk::Event::Type::ENTER_NOTIFY)
ev_new.window = canvas.window
ev_new.x = x
ev_new.y = y
ev_new.put
when Gdk::Event::Type::LEAVE_NOTIFY
tips.disable
end
end
end
end
main
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]