VPython 및 GTK threading에 대한 설명서를 읽었으므로 gtk GUI 내에 VPython 그래픽을 포함시킬 수 있습니다. 나는 그것이 wx on Windows으로 가능하다는 것을 알고 있지만, 나는 리눅스에 있고 PyGTK를 사용하고있다. 이제, 나는 그럭저럭 그 길의 일부를 얻을 수 있었다. VPython 창 을 별도의 프로세스을 생성하는 경우 임베드 할 수 있습니다. 내가 원하는 것은 스레드로 그것을 포함시키는 것입니다. 후자는 소켓 및 네트워크 호출 대신 스레드를 통해 OpenGL을 쉽게 제어 할 수있는 GUI 이벤트를 구현할 수있게합니다.GTK 창 캡처 : VPython (OpenGL) 응용 프로그램
편집 : 분명히 아무도 이것에 대해 아무 것도 모릅니다 ... 맙소사.
다음 코드는 있습니다. 주석 처리 된 두 줄의 주석 처리를 제거하고 몇 가지 명백한 주석을 달아서 프로세스 생성 코드를 얻을 수 있습니다.
#!/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()
낡은 실 · 같은 호. 동일한 논리를 구현하는 C 비슷한 문제가 있습니다. GTK 개발 팀에 문의하려고 했습니까? 어쨌든 다른 솔루션을 찾았습니까? 감사합니다 – tmow
@ tmow : 아니, 나는하지 않았다. – Sardathrion