Re: [pygtk] Handling new foreign windows in pygtk app.

2010-01-21 Thread Tomeu Vizoso
On Tue, Jan 19, 2010 at 11:44, Radek Vykydal rvyky...@redhat.com wrote:
 Hello list,


 I am trying to solve this problem:

 In root-only environment (Anaconda installer) we are running very simple
 C window manager (only taking care of setting focus of windows), Anaconda
 pygtk GUI, and on demand nm-connection-editor (C Gtk+ application) can
 be run.

 In Anaconda (the pygtk app) I have class (constructor is taking Xid of
 window)
 for embedding nm-c-e foreign window using gtk.Socket. What I need now is
 a mechanism
 for notifying about appearing nm-c-e windows (providing their Xid), idally
 it would allow to set a callback on event/notification.

 My last idea was:
 - catch CreateNotify events in the C window manager
 - 'forward' them via ClientMessage to Anaconda pygtk app
  (to a window W specified/found in window manager by its wmname),
  sending Xid of created window
 - in Anaconda pygtk app set client-event callback on the window W
  which will use Xid to (eventually) embed the created window

 Does it sound like it could work?
 Especially, is X ClientMessage received in pyGtk app generating
 client-event Gtk signal?

 I made an example but it doesn't work - base.py doesn't call the ce-cb
 callback when
 I seem to send ClientMessage to its window.

 I run two python processes (in my environment, metacity wm is running).


 base.py:

 #!/usr/bin/python

 import pygtk
 import gtk

 def ce_cb(widget, event):
    print Got client event!

 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
 # This doesn't help
 #window.add_events(gtk.gdk.CLIENT_EVENT)
 window.connect(client-event, ce_cb)
 window.show()

 gtk.main()


 send_event.py:

 #!/usr/bin/python

 import sys
 import Xlib
 from Xlib import display
 from Xlib.protocol import event

 d = display.Display()
 s = d.screen()
 children = s.root.query_tree().children

 for c in children:
    if c.get_wm_name() == base.py:
        break
 else:
    print ERROR: base.py not found
    sys.exit(1)

 # here I don't know exactly what I am doing to be honest
 atom = d.intern_atom('WINDOW')

 cm = event.ClientMessage(window = c,
                         client_type = atom,
                         data = (8, 01234567890123456789))

 c.send_event(cm)
 d.flush()


 What I am doing wrong?
 Or is my whole concept wrong?

In my experience, though solutions like these seem like a shortcut,
when you get to the details it gets much tougher.

The longer path that I would favour is to put the C code that you want
to reuse in a shared library and generate pygobject bindings for it.

Regards,

Tomeu

-- 
«Sugar Labs is anyone who participates in improving and using Sugar.
What Sugar Labs does is determined by the participants.» - David
Farning
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] Handling new foreign windows in pygtk app.

2010-01-19 Thread Radek Vykydal
Hello list,


I am trying to solve this problem:

In root-only environment (Anaconda installer) we are running very simple
C window manager (only taking care of setting focus of windows), Anaconda
pygtk GUI, and on demand nm-connection-editor (C Gtk+ application) can 
be run.

In Anaconda (the pygtk app) I have class (constructor is taking Xid of 
window)
for embedding nm-c-e foreign window using gtk.Socket. What I need now is 
a mechanism
for notifying about appearing nm-c-e windows (providing their Xid), idally
it would allow to set a callback on event/notification.

My last idea was:
- catch CreateNotify events in the C window manager
- 'forward' them via ClientMessage to Anaconda pygtk app
  (to a window W specified/found in window manager by its wmname),
  sending Xid of created window
- in Anaconda pygtk app set client-event callback on the window W
  which will use Xid to (eventually) embed the created window

Does it sound like it could work?
Especially, is X ClientMessage received in pyGtk app generating 
client-event Gtk signal?

I made an example but it doesn't work - base.py doesn't call the ce-cb 
callback when
I seem to send ClientMessage to its window.

I run two python processes (in my environment, metacity wm is running).


base.py:

#!/usr/bin/python

import pygtk
import gtk

def ce_cb(widget, event):
print Got client event!

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
# This doesn't help
#window.add_events(gtk.gdk.CLIENT_EVENT)
window.connect(client-event, ce_cb)
window.show()

gtk.main()


send_event.py:

#!/usr/bin/python

import sys
import Xlib
from Xlib import display
from Xlib.protocol import event

d = display.Display()
s = d.screen()
children = s.root.query_tree().children

for c in children:
if c.get_wm_name() == base.py:
break
else:
print ERROR: base.py not found
sys.exit(1)

# here I don't know exactly what I am doing to be honest
atom = d.intern_atom('WINDOW')

cm = event.ClientMessage(window = c,
 client_type = atom,
 data = (8, 01234567890123456789))

c.send_event(cm)
d.flush()


What I am doing wrong?
Or is my whole concept wrong?


Thanks,

Radek



___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/