[SOLVED] wxpython and panda3d on xubuntu 12.10

I am new to xubuntu 12.10. And I found that:

panda3d.org/manual/index.php/Main_Loop

has some code for wxpython in panda3d:

app = wx.App(0) 
 
def handleWxEvents(task): 
   while app.Pending(): 
      app.Dispatch() 
   return Task.cont 
 
taskMgr.add(handleWxEvents, 'handleWxEvents') 
run()  # Panda handles the main loop

does’t work. (Panda3d app run, wx app doesn’t run)

Resolve: I change method “handleWxEvents” with that:

    def handleWxEvents(self, task):
        evtloop = wx.EventLoop() 
        wx.EventLoop.SetActive(evtloop)    
        while evtloop.Pending(): 
            evtloop.Dispatch()
        return task.cont 

Panda3d app run and wx app run too. I think document should update ^^

Panda creates its own wx app and loop now, so you don’t have to worry about this. You can set “use-wx #t” in your Config.prc file.

I have tried it:

import wx

from panda3d.core import loadPrcFileData
loadPrcFileData('', "use-wx #t")

import direct.directbase.DirectStart

app = wx.App(0) 
frame = wx.Frame(None, wx.ID_ANY, "Hello World") # A Frame is a top-level window.
frame.Show(True)  
def handleWxEvents(task): 
    while app.Pending(): 
        app.Dispatch() 
    return task.cont 
 
taskMgr.add(handleWxEvents, 'handleWxEvents') 
run()  # Panda handles the main loop

and the result:

Panda3d Window appear, Wx Window doesn’t appear

You have to use base.wxApp instead of creating your own wx.App. You also don’t need to call Dispatch in a task any more, Panda will do it for you.

I received this message in console when I was using base.wxApp:

Code:

import wx

from panda3d.core import loadPrcFileData
loadPrcFileData('', "use-wx #t")

import direct.directbase.DirectStart

app =  base.wxApp(0) 
frame = wx.Frame(None, wx.ID_ANY, "Hello World") # A Frame is a top-level window.
frame.Show(True)  
 
 
run()  # Panda handles the main loop

It’s base.wxApp, not base.wxApp(0). As I said before, Panda already creates the app object.

However, the error indicates that it is None. You may need to call base.startWx() first.

It’s useful, thanks !