Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python GTK::Socket和GTK::Plug在Gnome和FVWM2下的意外行为_Python_Gtk_Pygtk_Gnome_Vpython - Fatal编程技术网

Python GTK::Socket和GTK::Plug在Gnome和FVWM2下的意外行为

Python GTK::Socket和GTK::Plug在Gnome和FVWM2下的意外行为,python,gtk,pygtk,gnome,vpython,Python,Gtk,Pygtk,Gnome,Vpython,如果在FVWM2中运行,以下代码可以正常工作。但是如果您将桌面更改为Gnome,那么嵌入的窗口将被销毁,而不是被嵌入 为什么?我错过了什么 代码如下,但基本上它所做的就是fork。在child中,我们创建一个VPython窗口,让它永远空闲。在父窗口中,我们创建一个GTK窗口,找出子窗口的窗口ID,并尝试将其嵌入到GTK::Socket中 请注意,VPython部分可能与此无关 #!/usr/bin/env python # -*- coding: utf-8 -*- import subpro

如果在FVWM2中运行,以下代码可以正常工作。但是如果您将桌面更改为Gnome,那么嵌入的窗口将被销毁,而不是被嵌入

为什么?我错过了什么

代码如下,但基本上它所做的就是fork。在child中,我们创建一个VPython窗口,让它永远空闲。在父窗口中,我们创建一个GTK窗口,找出子窗口的窗口ID,并尝试将其嵌入到GTK::Socket中

请注意,VPython部分可能与此无关

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
import sys
import os
import re
import time
from visual import *


def find_window_id (title):
    """Gets the OpenGL window ID."""
    pattern = re.compile('0x[0-9abcdef]{7}')
    proc = subprocess.Popen(['xwininfo', '-name', title],
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    errors = proc.stderr.readlines()
    if errors:
        return None
    for line in proc.stdout.readlines():
        match = pattern.findall(line)
        if len(match):
            return long(match[0], 16)
    return None



class Setting ():
    """VPython/OpenGL class."""

    def __init__ (self, w=256, h=256, title='OpenGL via VPython'):
        """Initiator."""
        self.width = w
        self.height = h
        self.title = title
        self.scene = display.get_selected() 
        self.scene.title = self.title
        self.scene.width = self.width
        self.scene.height = self.height
        self.sphere = sphere()



class GTKDisplay ():

    def __init__ (self, winID):
        """Initiator: Draws the GTK GUI."""
        import gtk
        import pygtk
        self.OpenGLWindowID = winID
        window = gtk.Window()
        window.show()
        socket = gtk.Socket()
        socket.show()
        window.add(socket)
        window.connect("destroy", lambda w: gtk.main_quit())
        socket.add_id(long(self.OpenGLWindowID))
        gtk.main()



def main ():
    """Main entry point."""
    name = 'sphere OpenGL window'
    child_pid = os.fork()
    if 0 == child_pid:
        sut = Setting(title=name)
    else:
        winID = None
        while not winID:
            time.sleep(.1)
            winID = find_window_id(name)
        try:
            gui = GTKDisplay(winID)
        except KeyboardInterrupt, err:
            print '\nAdieu monde cruel!'


if __name__ == "__main__":
    main()
PS:是的,这是我们的跟进