Panda3D stops calling task

Hi!
I have been working around an issue I have with Panda3D task manager. In my App I’m using Panda3D and wxPython. I want Panda3D own the main task so I call Showbase.run() and I add a task to execute my code.
This works good! But I have realized that if I click with the mouse on a wxPython Menu, the windows frame or I move the frame… the task is not called during the time the mouse button is down or the menu open. I have been testing a little bit and using wxPython to call my task seems to work fine… Can someone help me telling me what I’m doing wrong?
(This code shows the issue, and it is possible to test both situations changing usePanda3D = True/False)

Thanks!

from direct.showbase.ShowBase import ShowBase
import wx
import time

class MyApp(): 
  def __init__(self):
    print time.clock(),"Simumatic3D Created"

  def mainLoop(self, task=None):
    print time.clock(),"MainLoop"
    if task:
      return task.cont
    else:
      wx.CallLater(10, self.mainLoop)

class Panda3DWorld(ShowBase):     
  def __init__(self):
    print time.clock(),"Panda3DWorld Created"
    ShowBase.__init__(self)

class wxWorld(wx.App):
  def __init__(self):
    print time.clock(),"wxWorld Created"
    wx.App.__init__(self,False)
    frame = wx.Frame(None, wx.ID_ANY, "Hello World")
    # Menu Bar
    menubar = wx.MenuBar()
    filemenu= wx.Menu()
    filemenu.Append(wx.ID_ANY,"New")
    menubar.Append(filemenu, "File")
    frame.SetMenuBar(menubar)
    frame.Show(True)

app = MyApp()
gui = wxWorld()
graphics = Panda3DWorld()

# Test
usePanda3D = True
if (usePanda3D):
  graphics.taskMgr.add(app.mainLoop, "mainloop")
else:
  app.mainLoop()

graphics.run()
 

OBS: I don’t know if it can help, but I am running under Windows 7 and python 2.7.

This is a consequence of the way Windows messages are handled. While you hold down the mouse button on the window frame or whatnot, Windows blocks the call to PeekMessage() and other related message queue functions. Since Panda makes these calls in the main thread, it means that while you hold down the mouse button, Windows blocks Panda’s main thread.

It might be theoretically possible to make these Windows calls in a child thread, but Panda’s not really set up to work that way. On the other hand, you could put your task in a child thread, which would be much easier (but you will then have to deal with all of the issues that come along with having multiple threads in one application).

David

Thanks David!
So I am not able to draw Panda3D on that situations when the mouse clicks the frame…, but I can do the rest of my code if instead of using a Panda3D task, I use for example a wx.Timer for my loop. I have test that and it looks strange but is better than blocking all the app.

But, could it also draw panda if I would use a child thread? (this is something I do not understand) :frowning:
Could you explain that again?

It won’t draw panda in a child thread. The draw routine is handled in the main thread. You can only do computation updates in a child thread, but you won’t see results onscreen.

If you’re not already familiar with multithreaded programming, I don’t think it’s a good idea to pursue it to solve this problem. If you’re interested, you can learn about multiprogramming on your own time when you have a few months to get into it.

David