开发者

pygtk: find out focused element

i'm creating a dialog that finds out what is focused element. that's what i wrote:


import gtk
import gobject

class Focused开发者_JAVA技巧ElementPath(gtk.Dialog): 
    def __init__(self, parent, title=None):
        gtk.Dialog.__init__(self, title or 'Show path', parent)

        self.catch_within = parent      
        self.catch_focus = True

        self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)

        again_btn = gtk.Button('',gtk.STOCK_REFRESH)
        again_btn.connect('activate', self.refresh_pressed)
        again_btn.show()

        self.action_area.add(again_btn) 

        self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)

        self.action_area.set_layout(gtk.BUTTONBOX_EDGE)
        self.path = gtk.Label()
        self.path.show()

        self.vbox.add(self.path)        

    def refresh_pressed(self, btn): 
        self.catch_focus = True

    def do_focus_out_event(self, evt):
        nl = self.catch_within.get_focus() 
        if nl:
            self.catch_within.activate_focus()
            self.path.set_text(repr(nl))    
        else:
            self.path.set_text('None')      
        gtk.Dialog.on_focus_event(self, evt)

gobject.type_register(FocusedElementPath)

the problem is it returns previously focused element. is there any way to find out currently focused element? i've tried different events (for dialog and for window), but nothing helped :( what am i doing wrong or how do i do this correctly?


gtk.Window.get_focus (also available in gtk.Dialog) will return the currently focused child.

Anyway I don't quite understand what you want to achieve here...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜