[pygtk] Tooltips on comboBox

Alessandro Dentella sandro at e-den.it
Wed Jan 21 00:05:06 WST 2009


On Sun, Jan 18, 2009 at 11:31:57PM +0100, Alessandro Dentella wrote:
> hi,
> 
>   I  have been googling around for a while but I can't see if there is any
>   possibility to set tooltips for combobox entries.
> 

>   Is it any possible?

in my attempt to get tooltips I see that as I click on the arrow and the
popup appears, the tooltip disappears.

It seems the popup is a different gtk.Widget, and I should connect to that
one to attach tooltips. Is that correct? and in case how can I have that
widget?

I tried to connect to 'add' signal but it's never triggered. I see the 
ComboBox has a child: a CellView, but if I understand correctly CellView
only displayes *one* line and moreover I was not able to add a tooltip
anyhow.

Can somebody clearify widh is the way a ComboBox pops a menu and how Ican
get to it's components to set a ooltip?

thanks
sandro
*:-)





################################################

import gtk
import datetime

class Test(object):

    def __init__(self):
        self.w = gtk.Window()
        self.v = gtk.VBox()
        self.c = gtk.ComboBox()
        self.c = gtk.combo_box_new_text()
        #print self.c, type(self.c)

        for i in "= > < >= <= ~ ~!".split():
            self.c.append_text(i)

        self.c.set_property('has-tooltip', True)
        self.c.connect('query-tooltip', self.on_query_tooltip)

        self.w.add(self.v)
        self.v.add(self.c)
        
        self.w.show_all()

    def on_query_tooltip(self, widget,  x, y, keyboard_mode, tooltip):
        print widget, x, y, keyboard_mode, tooltip
        tooltip.set_text(datetime.datetime.now().strftime('%M:%S'))
        return True


if __name__ == '__main__':

    t = Test()
    gtk.main()


More information about the pygtk mailing list