osdir.com
mailing list archive

Subject: behaviour of window.present() on different WM - msg#00045

List: gnome.gtk+.python

Date: Prev Next Index Thread: Prev Next Index
Hi list,

I'm trying to popup a window_toplevel (win2) when a key is pressed in a first
window_toplevel (win) but I also want to keep the first one (win) the active
window with the focus on the textview inside (win), at the end the second
(win2) have to stay on top anyway...
To achieve this goal I'm using window.present() on (win) after the second is
popped-up (win2) then textview.grab_focus and window.set_keep_above(gtk.TRUE)
on the second window (win2)....

Because probably my english sucks...let's post some code:

This is the first version, it works perfectly on the following DE or WM:
kde, openbox, waimea, fvwm2, xfce4 and also Microsoft Windows.
When a key is pressed on win1, win2 is shown, win1 gets active and the focus
is into the textview.

but it does not work on:
gnome (metacity) and fluxbox.

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

class SecondWin:
def __init__(self):
self.win = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.win.connect("delete_event", self.delete_event)
self.win.connect("destroy", self.destroy)
self.win.connect("key-press-event", self.newTree)
self.win.set_default_size(500, 500)
self.text = gtk.TextView()
self.win.add(self.text)
self.win.show_all()

def newTree(self, widget, event):
self.win2 = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.win2.set_default_size(300, 300)
self.tree = gtk.TreeView()
self.win2.add(self.tree)
self.win2.show_all()
self.win.grab_focus()
self.win.present()
self.win2.set_keep_above(gtk.TRUE)

def delete_event(self, widget, event, data=None):
return gtk.FALSE

def destroy(self, widget, data=None):
return gtk.main_quit()

def main(self):
gtk.main()

if __name__ == "__main__":
second = SecondWin()
second.main()

After I spoke with xordoquy (thanks again) in IRC he proposed this:

def newTree(self, widget, event):
self.win2 = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.win2.set_default_size(300, 300)
self.tree = gtk.TreeView()
self.win2.add(self.tree)
self.win2.show_all()
gtk.idle_add(self.delay)

def delay(self):
self.win.present()
self.win.grab_focus()
self.win2.set_keep_above(gtk.TRUE)

It does work only once (the first time you press a button but then not
anymore) on gnome (metacity), with fluxbox it doesn't work at all.

Sorry for the long post but I would like to understand why this happen and
maybe what I can do to have my code running as I would like on all the DE /
WM.

Thanks a lot to everybody for the patience.
Have a nice day, evening or whatever in the world now :)

GMario
_______________________________________________
pygtk mailing list pygtk@xxxxxxxxxx
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

FileChooserDialog an FontSelectionDialog

Hi all, I'm moving my application to GTK2.4. Now I'm playing with Dialogs, gtk.FileChooserDialog and gtk.FontButton but I've some problems. First of all, I'm not sure if gtk.FileSelection is deprecated or not, because in pygtk2reference it isn't marked as deprecated, but glade puts it in the "deprecated" section. However I'm moving my dialogs to FileChooserDialog (I really don't like it because it is a little bit crowded. But I have another problem, on my system (Fedora Core 2 with fluxbox) the dialog is shown without icons, and it is impossible to recognize files and directories (On Windows I see icons associated with Home, C: etc ...). How can I force the theme with Icons? Now let's talk about FontButton or FontSelectionDialog. I tried it on Windows2000 and it crash when I try to open fonts like Wingdings, i.e. graphics fonts. I know these are more properly GTK problems but I'm more confident with Pygtk so I decided to post here. Every hint is very appreciated. -- |\ | |HomePage : http://nem01.altervista.org | \|emesis |XPN (my nr): http://xpn.altervista.org _______________________________________________ pygtk mailing list pygtk@xxxxxxxxxx http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Next Message by Date: click to view message preview

Re: behaviour of window.present() on different WM

On Thu, 9 Dec 2004 22:18:18 +0100, Gian Mario Tagliaretti <g.tagliaretti@xxxxxxxxxxxxxxxx> wrote: <snip> > def newTree(self, widget, event): > self.win2 = gtk.Window(gtk.WINDOW_TOPLEVEL) > self.win2.set_default_size(300, 300) > self.tree = gtk.TreeView() > self.win2.add(self.tree) > self.win2.show_all() > self.win.grab_focus() > self.win.present() Short answer: I belive that you should use self.win2.set_focus_on_map(gtk.FALSE) before showing it and remove the calls you used to focus self.win. Problem with short answer: This is the correct way for X window managers, but not all support the _NET_WM_USER_TIME property in the EWMH spec of freedesktop.org yet. (Metacity has support in the 2.8.x releases with x>=5, but it was disabled because some libraries and apps don't have sufficient support--so you'll actually have to wait for Gnome 2.10 for Metacity support...). So, this probably still won't work today for you, but other than some hack to force self.win2 to be mapped (and not just queued for mapping) before calling self.win.present() I don't see any way to currently get the behavior you want consistently. Long answer: This looks like a race condition to me. I don't know how Windows works, so let me just assume you're on an X server. self.win2.show_all() tells gtk to show the window, which then has gtk+ do a bunch of stuff to tell X to map the window. But, of course, X is asynchronous and it gets around to mapping it when it wants to... You then call self.win.present, to try to make sure self.win is focused instead of self.win2. This also ends up in a gtk+ call that results in an X client message to the window manager. Now, the window manager is (probably) going to focus self.win when it gets the Xclient message generated from your self.win.present() call, and is (probably) going to focus self.win2 when it receives the mapping notification for that window. However, the order in which those two events are received is non-deterministic. (I say probably in both cases because the window manager is free to do just about whatever it wants in most circumstances, even without violating the EWMH spec) Those events are sent from gtk+ with a timestamp (assuming a sufficiently recent version of gtk+) but unfortunately they'll both be sent with the timestamp of gtk_get_current_event_time so the window manager will be unable to distinguish the present() call as having come later. > self.win2.set_keep_above(gtk.TRUE) Why are you setting the ABOVE state? I believe what you want to do is to self.win2.set_transient_for(self.win) -- that doesn't have the nasty side-effects of keep_above (which, the gtk+ documentation aptly states that app authors should avoid). > After I spoke with xordoquy (thanks again) in IRC he proposed this: > > def newTree(self, widget, event): > self.win2 = gtk.Window(gtk.WINDOW_TOPLEVEL) > self.win2.set_default_size(300, 300) > self.tree = gtk.TreeView() > self.win2.add(self.tree) > self.win2.show_all() > gtk.idle_add(self.delay) > > def delay(self): > self.win.present() > self.win.grab_focus() > self.win2.set_keep_above(gtk.TRUE) This is basically an attempt to avoid the race condition by adding a timing separation between the self.win2.show_all() and the self.win.present(). It doesn't look very failproof... > It does work only once (the first time you press a button but then not > anymore) on gnome (metacity), with fluxbox it doesn't work at all. Another question is whether fluxbox supports _NET_ACTIVE_WINDOW (since gtk_window_present is implemented by sending that X client message...) Hope that helps, Elijah _______________________________________________ pygtk mailing list pygtk@xxxxxxxxxx http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Previous Message by Thread: click to view message preview

FileChooserDialog an FontSelectionDialog

Hi all, I'm moving my application to GTK2.4. Now I'm playing with Dialogs, gtk.FileChooserDialog and gtk.FontButton but I've some problems. First of all, I'm not sure if gtk.FileSelection is deprecated or not, because in pygtk2reference it isn't marked as deprecated, but glade puts it in the "deprecated" section. However I'm moving my dialogs to FileChooserDialog (I really don't like it because it is a little bit crowded. But I have another problem, on my system (Fedora Core 2 with fluxbox) the dialog is shown without icons, and it is impossible to recognize files and directories (On Windows I see icons associated with Home, C: etc ...). How can I force the theme with Icons? Now let's talk about FontButton or FontSelectionDialog. I tried it on Windows2000 and it crash when I try to open fonts like Wingdings, i.e. graphics fonts. I know these are more properly GTK problems but I'm more confident with Pygtk so I decided to post here. Every hint is very appreciated. -- |\ | |HomePage : http://nem01.altervista.org | \|emesis |XPN (my nr): http://xpn.altervista.org _______________________________________________ pygtk mailing list pygtk@xxxxxxxxxx http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Next Message by Thread: click to view message preview

Re: behaviour of window.present() on different WM

On Thu, 9 Dec 2004 22:18:18 +0100, Gian Mario Tagliaretti <g.tagliaretti@xxxxxxxxxxxxxxxx> wrote: <snip> > def newTree(self, widget, event): > self.win2 = gtk.Window(gtk.WINDOW_TOPLEVEL) > self.win2.set_default_size(300, 300) > self.tree = gtk.TreeView() > self.win2.add(self.tree) > self.win2.show_all() > self.win.grab_focus() > self.win.present() Short answer: I belive that you should use self.win2.set_focus_on_map(gtk.FALSE) before showing it and remove the calls you used to focus self.win. Problem with short answer: This is the correct way for X window managers, but not all support the _NET_WM_USER_TIME property in the EWMH spec of freedesktop.org yet. (Metacity has support in the 2.8.x releases with x>=5, but it was disabled because some libraries and apps don't have sufficient support--so you'll actually have to wait for Gnome 2.10 for Metacity support...). So, this probably still won't work today for you, but other than some hack to force self.win2 to be mapped (and not just queued for mapping) before calling self.win.present() I don't see any way to currently get the behavior you want consistently. Long answer: This looks like a race condition to me. I don't know how Windows works, so let me just assume you're on an X server. self.win2.show_all() tells gtk to show the window, which then has gtk+ do a bunch of stuff to tell X to map the window. But, of course, X is asynchronous and it gets around to mapping it when it wants to... You then call self.win.present, to try to make sure self.win is focused instead of self.win2. This also ends up in a gtk+ call that results in an X client message to the window manager. Now, the window manager is (probably) going to focus self.win when it gets the Xclient message generated from your self.win.present() call, and is (probably) going to focus self.win2 when it receives the mapping notification for that window. However, the order in which those two events are received is non-deterministic. (I say probably in both cases because the window manager is free to do just about whatever it wants in most circumstances, even without violating the EWMH spec) Those events are sent from gtk+ with a timestamp (assuming a sufficiently recent version of gtk+) but unfortunately they'll both be sent with the timestamp of gtk_get_current_event_time so the window manager will be unable to distinguish the present() call as having come later. > self.win2.set_keep_above(gtk.TRUE) Why are you setting the ABOVE state? I believe what you want to do is to self.win2.set_transient_for(self.win) -- that doesn't have the nasty side-effects of keep_above (which, the gtk+ documentation aptly states that app authors should avoid). > After I spoke with xordoquy (thanks again) in IRC he proposed this: > > def newTree(self, widget, event): > self.win2 = gtk.Window(gtk.WINDOW_TOPLEVEL) > self.win2.set_default_size(300, 300) > self.tree = gtk.TreeView() > self.win2.add(self.tree) > self.win2.show_all() > gtk.idle_add(self.delay) > > def delay(self): > self.win.present() > self.win.grab_focus() > self.win2.set_keep_above(gtk.TRUE) This is basically an attempt to avoid the race condition by adding a timing separation between the self.win2.show_all() and the self.win.present(). It doesn't look very failproof... > It does work only once (the first time you press a button but then not > anymore) on gnome (metacity), with fluxbox it doesn't work at all. Another question is whether fluxbox supports _NET_ACTIVE_WINDOW (since gtk_window_present is implemented by sending that X client message...) Hope that helps, Elijah _______________________________________________ pygtk mailing list pygtk@xxxxxxxxxx http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by