Захват окон GTK: приложение VPython (OpenGL)

Прочитав документацию дляVPython а такжеGTK ThreadingМне кажется, что было бы возможно встроить графику VPython в графический интерфейс GTK. Я знаю, что это возможно сWX на Windows но я на Linux и использую PyGTK. Теперь мне удалось пройти часть пути. Я могу встроить окно VPythonprovided that it is spawned a separate process, То, что я хотел бы, чтобы вставить это как поток. Последнее упростит реализацию событий GUI, управляющих OpenGL - через поток вместо сокета и сетевых вызовов.

Edit: Apparently nobody knows anything about this... Meh.

Вот код, который у меня есть. Раскомментируйте две закомментированные строки и закомментируйте несколько очевидных других, и вы сможете перейти к процессу, вызывающему код.

#!/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()

Ответы на вопрос(1)

Ваш ответ на вопрос