tags:

views:

160

answers:

2

I have a PyGTK program which is hidden most of the time, but with a keypress it shall come up as a popup. Therefore I want the program not to be activated when its opened. I tried several options to to that, with no success:

self.window.show()

self.window.set_focus(None)

Activates the program, but sets no focus.


self.window.set_accept_focus(False)

self.window.show()

self.window.set_accept_focus(True)

With the last command, the window gets activated.


self.window.show()

self.window.unset_flags(gtk.HAS_FOCUS)

Does nothing...


Btw. I am using Ubuntu 9.10 (metacity)

+1  A: 

Build the window but don't call show() on it until it is ready to be activated. Then use self.window.present().

EDIT: If you never want the window to be activated, why not try a notification popup? You need libnotify for this. There are Python bindings. Here is an example: http://roscidus.com/desktop/node/336

In combination with a toolbar applet, this could do what you want -- i.e. the notification is raised when the user either clicks on the applet or presses the key combination.

ptomato
Though the present() method shows the window, it also activates it. I want to show the window but not activate it. My program will only be a notification. Note that I can not use a gtk.WINDOW_POPUP instead of a gtk.WINDOW_TOPLEVEL, because in principal i want to be able to activate the window by clicking on it.
Funsi
I think I now understand what you are trying to do, see edit. It might help if you gave a little more information.
ptomato
Sorry, that I am not very clear. Libnotify (or a gtk.WINDOW_POPUP) is almost what i want, BUT: These windows can not grab the focus! So what I want is: 1) If the user presses a key combination, show my notification window, but do not grab the focus, so that the user's work will not be disturbed (that is show but do not activated). 2) If the user clicks on one of the textfields of my notification window, then grab the focus.
Funsi
+1  A: 
I figured out how to do it. See the example below:

#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk
import gobject

class HelloWorld:
    window=None
    def hello(self, widget, data=None, data2=None):
    HelloWorld.window.set_accept_focus(True)
    HelloWorld.window.present()

    def __init__(self):
        HelloWorld.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.button = gtk.Entry(50)
        self.button.connect("focus-in-event", self.hello, None)
        HelloWorld.window.add(self.button)
        self.button.show()
    HelloWorld.window.set_accept_focus(False)
    self.button.connect('button-press-event', self.hello)
    HelloWorld.window.show()
    def main(self):
        gtk.main()

if __name__ == "__main__":
    hello = HelloWorld()
    hello.main()
Funsi