|
From: Yann G. <ygo...@is...> - 2012-06-08 06:23:48
|
Has anyone managed to embed VPython within GTK? Maybe using GtkGLExt python's bindings? I know about the Windows wx example but was just wondering if there was something on gtk. If not, I shall endeavour to make it work and if successful will write a toy programme. -- GPG Fingerprint 8666 7F9A 17E7 AC8E CC36 1D1E C707 D658 6685 2528 The views expressed in this e-mail may or may not reflect those of the author and do not necessarily reflect those of Isotek Oil and Gas Ltd. |
|
From: Bruce S. <Bru...@nc...> - 2012-06-08 13:53:05
|
The Linux version of VPython is based on GTK. Several years ago I attempted to build VPython on Windows using GTK, and here is a summary of my experience: http://vpython.org/gtkmm_on_windows.html Bruce Sherwood On Fri, Jun 8, 2012 at 12:23 AM, Yann Golanski <ygo...@is...> wrote: > Has anyone managed to embed VPython within GTK? Maybe using GtkGLExt python's > bindings? > > I know about the Windows wx example but was just wondering if there was > something on gtk. If not, I shall endeavour to make it work and if > successful will write a toy programme. > > -- > GPG Fingerprint 8666 7F9A 17E7 AC8E CC36 1D1E C707 D658 6685 2528 > The views expressed in this e-mail may or may not reflect those of the > author and do not necessarily reflect those of Isotek Oil and Gas Ltd. > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > |
|
From: Yann G. <ygo...@is...> - 2012-06-08 14:58:50
|
Quoth Bruce Sherwood on Fri, Jun 08, 2012 at 07:52:34 -0600
> The Linux version of VPython is based on GTK.
Ah, then there maybe some hope. I am running on Linux.
What I want to do is to embed a VPython window within a bigger GTK GUI.
What I'd thought I'd do was create a gtk.Socket() and use that to embed
the VPython window. This works like a charm provided that the VPython
window and the GUI window are created by different processes. The
problem happens when I try to use threads -- yes, I know "I had a
problem. Then I used threading. Now Iav he wto pbleroms." ...
Still, I feel I am very close to it working. In the code below, I get:
test_opengl.py:62: GtkWarning: gtksocket.c:886: Can't add non-GtkPlug to GtkSocket socket.add_id(long(self.OpenGLWindowID))
/usr/bin/ipython:62: GtkWarning: IA__gdk_error_trap_pop: assertion `gdk_error_traps != NULL' failed
as an error. But if the code in GTKWindowThreadClass.run() is copied and
pasted into its own script (with the correct value of OpenGLWindowID as given
by xwininfo) then it works: the VPython window embeds into the GTK one.
Can anyone see what I am doing wrong?
Source code follows -- apologies for the spare commenting but it should
be simple enough to follow.
================================================================================
#!/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):
self.scene = display.get_selected()
self.scene.title = 'OpenGL test'
s = sphere()
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],
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()
================================================================================
--
GPG Fingerprint 8666 7F9A 17E7 AC8E CC36 1D1E C707 D658 6685 2528
The views expressed in this e-mail may or may not reflect those of the
author and do not necessarily reflect those of Isotek Oil and Gas Ltd.
|
|
From: Yann G. <ygo...@is...> - 2012-06-12 07:11:33
|
Hi,
Here is an example of embedding VPython within a GTK GUI. It is a trivial
skeleton type of thing. Process communication can be done via a named file
(FIFO) pipe or a Queue().
Feel free to add this example to your project if you think it will help
others.
================================================================================
#!/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()
================================================================================
--
GPG Fingerprint 8666 7F9A 17E7 AC8E CC36 1D1E C707 D658 6685 2528
The views expressed in this e-mail may or may not reflect those of the
author and do not necessarily reflect those of Isotek Oil and Gas Ltd.
|
|
From: Jerzy K. <jer...@un...> - 2012-06-12 09:53:42
|
Le 12/06/2012 09:11, Yann Golanski a écrit : > Here is an example of embedding VPython within a GTK GUI. > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users Nice idea... Of course this will not work on Windows (no os.fork, although some people manufactured some unsafe hacks). The problem can be probably solved using .subprocess in Python, but this is not my domain. Perhaps somebody could add something? Jerzy Karczmarczuk |
|
From: Yann G. <ygo...@is...> - 2012-06-12 10:54:44
|
Quoth Jerzy Karczmarczuk on Tue, Jun 12, 2012 at 11:53:17 +0200 > Of course this will not work on Windows (no os.fork, although some > people manufactured some unsafe hacks). That is true. > The problem can be probably solved using .subprocess in Python, but this > is not my domain. Perhaps somebody could add something? It should be trivial to do so. You just have a function that starts the VPython process instead of the child fork. Note that then you need to either set the VPython window title as a parameter or have an agreed title name (otherwise xwininfo will not work). That reminds me, I am not sure that xwininfo works on Windows either... So maybe not so trivial. A much nicer solution would involve threading. However, I could not make it work. The code core dumps when it attempt to embed VPython. If anyone wanted to help, I would not mind working it out but cannot afford to spend the time at work doing it. Sorry. -- GPG Fingerprint 8666 7F9A 17E7 AC8E CC36 1D1E C707 D658 6685 2528 The views expressed in this e-mail may or may not reflect those of the author and do not necessarily reflect those of Isotek Oil and Gas Ltd. |
|
From: Yann G. <ygo...@is...> - 2012-06-29 15:44:02
|
A bug has risen from the embedding code I send earlier. The code works
fine under the fvwm2 window manager but not under Gnome. It appears
that Gnome is more picky with GTK. This result in any embedding command
destroying the VPythong window instead of embedding it.
Basically, to embed a GTK window into another one, you need to have a
pair of Gtk::Plug and Gtk::Socket. The child process (VPython in this
case) creates a plug and exposes the plug ID. The programme that
will embed VPython uses this plug ID as a parameter to its Gtk::Socket
and thus can embed the plug.
So, would it be possible to have a gtk::Plug() object within main_gui()
and a method that would return the Plug ID? Ideally, this would be
wrapped within a Python call so that I could do something akin to:
display.get_selected()
plug_id = display.get_gtk_plug_id()
Would it be okay if this became a feature request?
--
GPG Fingerprint 8666 7F9A 17E7 AC8E CC36 1D1E C707 D658 6685 2528
The views expressed in this e-mail may or may not reflect those of the
author and do not necessarily reflect those of Isotek Oil and Gas Ltd.
|
|
From: Bruce S. <Bru...@nc...> - 2012-06-29 16:16:27
|
I don't really follow the details of this, but it doesn't sound like a good candidate for the standard version of VPython because it is apparently GTK-specific, and VPython attempts to be platform-independent. I'm currently studying how it might be possible to base VPython on wxPython, in which case the OpenGL canvas could be part of a window, with cross-platform support for menus etc. My immediate concern is, as I've commented before, to be able to run VPython on a 64-bit Python on the Mac, based on Cocoa. On the wxpython-users list, wxPython experts have been very helpful in my quest, including making a suggestion on how to get around the very serious problem that the Cocoa interact loop must be in the primary thread, the roadblock that David Scherer and I were unable to get around when we tried in 2008. Bruce Sherwood On Fri, Jun 29, 2012 at 9:43 AM, Yann Golanski <ygo...@is...> wrote: > A bug has risen from the embedding code I send earlier. The code works > fine under the fvwm2 window manager but not under Gnome. It appears > that Gnome is more picky with GTK. This result in any embedding command > destroying the VPythong window instead of embedding it. > > Basically, to embed a GTK window into another one, you need to have a > pair of Gtk::Plug and Gtk::Socket. The child process (VPython in this > case) creates a plug and exposes the plug ID. The programme that > will embed VPython uses this plug ID as a parameter to its Gtk::Socket > and thus can embed the plug. > > So, would it be possible to have a gtk::Plug() object within main_gui() > and a method that would return the Plug ID? Ideally, this would be > wrapped within a Python call so that I could do something akin to: > > display.get_selected() > plug_id = display.get_gtk_plug_id() > > Would it be okay if this became a feature request? > > -- > GPG Fingerprint 8666 7F9A 17E7 AC8E CC36 1D1E C707 D658 6685 2528 > The views expressed in this e-mail may or may not reflect those of the > author and do not necessarily reflect those of Isotek Oil and Gas Ltd. > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > |