I'm using Python 2.7.4 with Gtk3 on Ubuntu 13.10.
I'm using the Keybinder library to hide and show my Gtk window using a hotkey. Now, when my window does show up using the hotkey, it does not always receive focus.
The concerned code is below:
def toggle(self, key, data):
if self.hidden:
self.hidden = False
self.set_keep_above(True)
self.set_accept_focus(True)
self.present()
self.enteredName.grab_focus()
else:
self.hidden = True
self.hide()
Here, self
refers to the Gtk window and self.enteredName
is a widget of type Gtk.Entry()
.
Normally, the combination of set_accept_focus()
, set_keep_above()
, followed by present()
works. Without the set_keep_above
, my window doesn't rise to the top. Without the set_accept_focus
, my window doesn't get keyboard focus.
The above set up works when I just start my app and then test it using the hotkey (hiding and showing it). My window always receives keyboard focus. Howver, let's say I have a GVim window opened and I've given keyboard focus to it. On pressing the hotkey, my window shows up on the top (even on top of the GVim window), but the keyboard focus still lies with the GVim window.
I've tried several combinations (by adding activate
), and grabbing focus on a text widget. But it's not working as expected.
Anything I'm missing here?