I am trying to run panda and pygtk in parallel, using thread. I developped the panda part and the pygtk part separatly and I am now trying to run them together, using threads.
I believe that Panda does not run elsewhere than in the main thread, so I left it there. But It seems that pygtk does not love to run in a child thread at all.
from browser import *
from Queue import *
from gui import *
import thread
qGuiEvents = Queue()
qWorldEvents = Queue()
thread.start_new_thread(Gui,(qGuiEvents,qWorldEvents))
browser = Browser(qGuiEvents,qWorldEvents)
browser is the panda part, and Gui the gtk part.
When I do this, panda and pygtk are launched, but contrary to pygtk (which runs fine) panda doesn’t work. Windows tells me that the program is not responding etc…
Do you have any idea of how to solve the problem ?
from browser import * # browser is the class managing my Panda3D world
from Queue import *
from gui import * # gui is the pyGtk Gui (see below)
import thread
# these Queues are used to speak between pyGtk and Panda3D
qGuiEvents = Queue()
qWorldEvents = Queue()
thread.start_new_thread(Gui,(qGuiEvents,qWorldEvents))
browser = Browser(qGuiEvents,qWorldEvents)
Gui code :
import pygtk
import gtk
import gtk.glade
import gobject as go
class Gui:
def __init__(self,qGuiEvents,qWorldEvents):
# events queue
self.qGuiEvents = qGuiEvents # events sent to the GUI
self.qWorldEvents = qWorldEvents # events sent to the World
# thread-safe :
gtk.gdk.threads_init()
# entering main loop
gtk.gdk.threads_enter()
gtk.main()
gtk.gdk.threads_leave()
In fact, it is quite simple, but I had a lot of trouble with that.
And the GUI code needs to go in a file called gui.py, right?
I can’t run your code as I don’t have the browser module that it tries to import. Could you either provide that module or provide a stand-alone demo of GTK integration? Would be very interested.
Ok, I just did 3 files to illustrate how it works, but at my job I don’t have access to my ftp account.
How can I send the files to you ?
I could always post the source here, in plain text, but i don’t find it handy. is there a web repository where I could upload the files ? (and where the files will be kept, for this may interrest more people than just chombree)