On May 4, 2006, at 8:02 AM, Frederic Back wrote:

Hello,

is there a simple way to add tooltips to cells in a treeview?

If not, I guess that catching button events on the treeview and popping
up menues are the way to go.

Cheers,
Fred

Here's an e-mail exchange I had about adding tooltips to menus. Since menus use treeviews underneath, I imagine the same hack should work. (The original e-mails don't seem to be in the archive...)

Please note that the code here is due to Phil Dumont, not me. The only substantial change I made to get it to work in my context was to put a try/except around the line "cv_parent = cell_view.get_parent ()". If you're using arrow keys to navigate a menu, sometimes cell_view is a TreeViewColumn and doesn't have a get_parent method.

 --  Steve

On Jul 8, 2005, at 11:28 AM, Phil Dumont wrote:


Steve,

I looked pretty hard for how to do this (because I wanted
to do it too), and pretty well convinced myself that there
is no "right" way to do it.

But I have discovered a HACK that seems to accomplish it
reasonably well.

That this should work is not at all supported by the
documentation, and was discovered by trial-n-error.
(Who knows; if you are running a sligtly different release
than I, it may not ever work for you.)

See the code at the end.

The 'tipmap' stuff is to avoid some flicker the first time
you hover over an item after a ComboBox popup.  Since the
cell_layout_data_func() gets called every time the cell is
renderered, the same tooltip can get set on the same widget
multiple times, causing choppiness.

Even with that bit of choppiness removed, there's still some
left.  The tooltip disappears every time the entry gets a
motion event, reappearing after brief motionlessness.
Normally (like the top-level tooltip on the ComboBox itself),
the tooltip stays put for motion events, only going away on
a leave event.  Oh well.

If you come across a better way to do this, *please* let me
know.

phil dumont


Steve Langer
Thu, 30 Jun 2005 09:42:53 -0700

Hi --


I hope this isn't a faq -- I couldn't find the answer in the
official faq or in the list...

I'm belatedly porting a large application from
gtk+1.2/pygtk-0.6.x to gtk2.6. With gtk+1.2 I was able to
add tooltips to the individual menu items in the pull-down
menu part of a GtkOptionMenu. Each entry in the menu was a
GtkMenuItem, to which I could assign a tooltip. This was
very useful, because users could see a description of a menu
item before selecting it.

With gtk2, I have to use a ComboBox instead. Is it possible
to assign tooltips to the items?

Many thanks.
        -- Steve

--

############# The sample code: #############
import gtk, gobject

w=gtk.Window()
w.connect_after('delete-event', lambda *args: gtk.main_quit())

tips = gtk.Tooltips()
tipmap = {}

def cell_layout_data_func(cell_view, cell_renderer, model, iter):
    idx = model.get_path(iter)[0]
    item_text = model.get_value(iter, 0)
    cell_renderer.set_property('text', item_text)
    tip_text = "tooltip for ComboBox Entry '%s'"%item_text
    cv_parent = cell_view.get_parent()
if isinstance(cv_parent, gtk.MenuItem) and (cv_parent not in tipmap
or tipmap[cv_parent] != tip_text):
        tipmap[cv_parent] = tip_text
        tips.set_tip(cv_parent, tip_text)

cb=gtk.ComboBox()
mod=gtk.ListStore(gobject.TYPE_STRING)
cb.set_model(mod)
cr=gtk.CellRendererText()
cb.pack_start(cr)
for item in ['this','is','a','test']:
    cb.append_text(item)
cb.set_active(0)
cb.set_cell_data_func(cr, cell_layout_data_func)

eb = gtk.EventBox()
eb.add(cb)

tips.set_tip(eb, 'tip on ComboBox')

w.add(eb)
w.show_all()

gtk.main()




--
-- EMail: [EMAIL PROTECTED] Phone: (301) 975-5423 -- -- WWW: http://math.nist.gov/mcsd/Staff/SLanger/ Fax: (301) 975-3144 -- -- Mail: NIST; 100 Bureau Drive -- Stop 8910; Gaithersburg, Md 20899-8910 --

-- "I don't think this will work. That's why it's science." -- -- Naomi Langer, 17 Feb 2003 --


_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to