简体   繁体   中英

PyGTK: move custom build tooltip window

I have built PyGTK application with matplotlib graph in it. I also would like to use custom built tooltip windows. Tooltip value changes according to mouse position on graph.

My problem is that, i can not move my tooltip windows next to my mouse, because i dont know how to get mouse position in screen

Here is my stripped code:

def figPrepare(self):   #initialize graph
        #figure preparation stuff

        #custom tooltip window
        tooltip = gtk.Window(gtk.WINDOW_POPUP)
        lbl = gtk.Label()
        tooltip.add(lbl)
        lbl.show()

        figure.canvas.set_tooltip_window(tooltip)
        figure.canvas.props.has_tooltip = True
        #events
        figure.canvas.mpl_connect('figure_enter_event',lambda w: tooltip.show())
        figure.canvas.mpl_connect('motion_notify_event',lambda w: self.updateTooltip(tooltip, lbl))
        figure.canvas.mpl_connect('figure_leave_event',lambda w: tooltip.hide())


    def updateTooltip(self, win, lbl):
        lbl.set_text(str(time.time()))
        win.move(w.x, w.y)

This code moves tooltip window, but values are based on matplotlib graph, not absolute position in screen.

Could someone point me how to move tooltip windows next to mouse pointer?

I found solution:

def updateTooltip(self, win, lbl):
    lbl.set_text(str(time.time()))
    x, y, mods = win.get_screen().get_root_window().get_pointer()   #this gets absolute mouse possition on screen
    win.move(x+15, y+10)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM