#!/usr/bin/env python import sys import os import gobject import gtk failure = False child = None def on_socket_map(socket, command): global child, failure try: child = os.spawnvp(os.P_NOWAIT, command[0], command + ['--parent-id', str(socket.get_id())]) gobject.child_watch_add(child, on_child_exited) except: failure = True raise def on_child_exited(pid, condition): gtk.main_quit() print 'Child exit condition:', condition def on_window_delete(window, event): gtk.main_quit() os.kill(child, 15) return False def main(args): window = gtk.Window() window.set_default_size(640, 480) window.set_title('Embedder') window.set_property('border-width', 4) window.connect('delete-event', on_window_delete) frame = gtk.Frame() frame.set_property('shadow-type', gtk.SHADOW_IN) window.add(frame) socket = gtk.Socket() socket.connect_after('map', on_socket_map, args) frame.add(socket) window.show_all() if failure: sys.exit(1) gtk.main() if __name__ == '__main__': main(sys.argv[1:])