PyGTK: Allow only one instance of your application (2)

In the post “PyGTK: Allow only one instance of your application” I presented a method to raise a PyGTK application’s window, but the solution was not perfect.

To raise the application’s window (from the application it self), I used the code:

self.window.present_with_time( int(time.time()) )
  • gtk.Window.present_with_time(): works all the time but it does not activate the window
  • gtk.Window.present: it does not works all the time (ex: it does not works if the application shows a modal dialog on the main window), but when it does it activate the window too

Using this method, in the worst case the window is raised but is not activate.

But this method was not good enough for me. I wanted a method that works all the time: raise the window and activate/focut it.
So this is the new solution:

self.window.present_with_time( int(time.time()) )
  • gtk.Window.present_with_time(): raise the window
  • self.window.window.focus(): focus the window

Tags: , ,

Leave a Reply