Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following code works fine if run within FVWM2. But if you change desktop to Gnome, then the embedded window is destroyed instead of being embedded.

Why is that? What am I missing?...

The code follows but basically all it does is fork. In the child, we create a VPython window an let it idle forever. In the parent, we create a GTK window, find out what the window ID of the child window is, and try to embed it vis a GTK::Socket.

Note that the VPython part maybe irrelevant to this.

#!/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'):
        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()
        socket = gtk.Socket()
        window.connect("destroy", lambda w: gtk.main_quit())

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

if __name__ == "__main__":

PS: Yes, this is a follow up from this question and this one.

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.