Przechwytywanie okna GTK: aplikacja VPython (OpenGL)

Po przeczytaniu dokumentacji dlaVPython iGwintowanie GTK, wydaje mi się, że możliwe byłoby osadzenie grafiki VPython w graficznym interfejsie graficznym gtk. Wiem, że jest to możliwewx w systemie Windows ale jestem na Linuksie i korzystam z PyGTK. Teraz udało mi się zdobyć część drogi. Mogę osadzić okno VPythonpod warunkiem, że powstaje oddzielny proces. Chciałbym osadzić go jako wątek. Te ostatnie spowodowałyby, że zdarzenia GUI kontrolujące OpenGL byłyby łatwiejsze do zaimplementowania - za pośrednictwem wątku zamiast gniazda i wywołań sieciowych.

Edytuj: Najwyraźniej nikt nic o tym nie wie ... Meh.

Oto kod, który mam. Odkomentuj dwie skomentowane linie i skomentuj kilka oczywistych innych, a będziesz mógł dostać się do kodu odradzania procesu.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
from visual import *
import threading
import Queue
import gtk
import pygtk
import re
import subprocess


class OPenGLThreadClass (threading.Thread):
    """Thread running the VPython code."""

    def __init__(self, queue):
        threading.Thread.__init__(self)
        self.queue = queue
        self.name = 'OpenGLThread'


    def run (self):
        gtk.threads_enter()
        self.scene = display.get_selected() 
        self.scene.title = 'OpenGL test'
        s = sphere()
        gtk.threads_leave()
        #P = subprocess.Popen(['python', 'opengl.py'])
        time.sleep(2)
        self.queue.put(self.find_window_id())
        self.queue.task_done()


    def find_window_id (self):
        """Gets the OpenGL window ID."""
        pattern = re.compile('0x[0-9abcdef]{7}')
        P = subprocess.Popen(['xwininfo', '-name', self.scene.title],
        #P = subprocess.Popen(['xwininfo', '-name', 'Visual WeldHead'],
                stdout=subprocess.PIPE)
        for line in P.stdout.readlines():
            match = pattern.findall(line)
            if len(match):
                ret = long(match[0], 16)
                print("OpenGL window id is %d (%s)" % (ret, hex(ret)))
                return ret


class GTKWindowThreadClass (threading.Thread):
    """Thread running the GTK code."""

    def __init__ (self, winID):
        threading.Thread.__init__(self)
        self.OpenGLWindowID = winID
        self.name = 'GTKThread'


    def run (self):
        """Draw the GTK GUI."""
        gtk.threads_enter()
        window = gtk.Window()
        window.show()
        socket = gtk.Socket()
        socket.show()
        window.add(socket)
        window.connect("destroy", lambda w: gtk.main_quit())
        print("Got winID as %d (%s)" % (self.OpenGLWindowID, hex(self.OpenGLWindowID)))
        socket.add_id(long(self.OpenGLWindowID))
        gtk.main()
        gtk.threads_leave()



def main ():
    thread = {}
    print("Embedding OpenGL/VPython into GTK GUI")
    queue = Queue.Queue()
    thread['OpenGL'] = OPenGLThreadClass(queue)
    thread['OpenGL'].start()
    winID = queue.get()
    print("Got winID as %d (%s)" % (winID, hex(winID)))
    gtk.gdk.threads_init()
    thread['GTK'] = GTKWindowThreadClass(winID)
    thread['GTK'].start()



if __name__ == "__main__":
    main()

questionAnswers(1)

yourAnswerToTheQuestion