Running modules from a menu

I have built three Panda3d modules each with a different simulations. The idea is to display a menu and have the user select which simulation to run. If the menu is setup in Panda3d and the choice is “Imported” in a function a thread exception occurs.

If the modules are imported at the top of the menu script the modules run.

I need some way to call the modules to run, terminate, the return to the menu.

Any ideas out there?

it should (and I know for a fact it does) work that way.

Could you show some code?
what is the error you’re getting?

First the error:

2 implicit pages:
/c/Panda3D-1.6.2/etc/Config.prc
/c/Panda3D-1.6.2/etc/Confauto.prc

ConfigVariable direct-gui-edit:
direct-gui-edit 1 (from /c/Panda3D-1.6.2/etc/Config.prc)
direct-gui-edit 0 (default value)

DConfig

Assertion failed: _num_busy_threads == 0 at line 865 of c:\p\p3d\panda3d-1.6.2\panda\src\event\asyncTaskChain.cxx
Traceback (most recent call last):
File “C:\Panda3D-1.6.2\direct\showbase\EventManager.py”, line 61, in eventLoopTask
self.doEvents()
File “C:\Panda3D-1.6.2\direct\showbase\EventManager.py”, line 55, in doEvents
processFunc(self.eventQueue.dequeueEvent())
File “C:\Panda3D-1.6.2\direct\showbase\EventManager.py”, line 122, in processEvent
messenger.send(eventName, paramList)
File “C:\Panda3D-1.6.2\direct\showbase\Messenger.py”, line 309, in send
self.__dispatch(acceptorDict, event, sentArgs, foundWatch)
File “C:\Panda3D-1.6.2\direct\showbase\Messenger.py”, line 371, in __dispatch
method ((extraArgs + sentArgs))
File “C:\Panda3D-1.6.2\direct\gui\DirectButton.py”, line 103, in commandFunc
apply(self[‘command’], self[‘extraArgs’])
File “C:\workspace\plab\src\Main2.py”, line 77, in init
import treadmillwalk4
File “C:\workspace\plab\src\treadmillwalk4.py”, line 860, in
run()
File “C:\Panda3D-1.6.2\direct\showbase\ShowBase.py”, line 2423, in run
self.taskMgr.run()
File “C:\Panda3D-1.6.2\direct\task\TaskNew.py”, line 471, in run
self.step()
File “C:\Panda3D-1.6.2\direct\task\TaskNew.py”, line 429, in step
self.mgr.poll()
AssertionError: _num_busy_threads == 0 at line 865 of c:\p\p3d\panda3d-1.6.2\panda\src\event\asyncTaskChain.cxx
:task(error): Exception occurred in PythonTask eventManager
Traceback (most recent call last):
File “C:\workspace\plab\src\Main2.py”, line 92, in
run()
File “C:\Panda3D-1.6.2\direct\showbase\ShowBase.py”, line 2423, in run
self.taskMgr.run()
File “C:\Panda3D-1.6.2\direct\task\TaskNew.py”, line 471, in run
self.step()
File “C:\Panda3D-1.6.2\direct\task\TaskNew.py”, line 429, in step
self.mgr.poll()
File “C:\Panda3D-1.6.2\direct\showbase\EventManager.py”, line 61, in eventLoopTask
self.doEvents()
File “C:\Panda3D-1.6.2\direct\showbase\EventManager.py”, line 55, in doEvents
processFunc(self.eventQueue.dequeueEvent())
File “C:\Panda3D-1.6.2\direct\showbase\EventManager.py”, line 122, in processEvent
messenger.send(eventName, paramList)
File “C:\Panda3D-1.6.2\direct\showbase\Messenger.py”, line 309, in send
self.__dispatch(acceptorDict, event, sentArgs, foundWatch)
File “C:\Panda3D-1.6.2\direct\showbase\Messenger.py”, line 371, in __dispatch
method (
(extraArgs + sentArgs))
File “C:\Panda3D-1.6.2\direct\gui\DirectButton.py”, line 103, in commandFunc
apply(self[‘command’], self[‘extraArgs’])
File “C:\workspace\plab\src\Main2.py”, line 77, in init
import treadmillwalk4
File “C:\workspace\plab\src\treadmillwalk4.py”, line 860, in
run()
File “C:\Panda3D-1.6.2\direct\showbase\ShowBase.py”, line 2423, in run
self.taskMgr.run()
File “C:\Panda3D-1.6.2\direct\task\TaskNew.py”, line 471, in run
self.step()
File “C:\Panda3D-1.6.2\direct\task\TaskNew.py”, line 429, in step
self.mgr.poll()
AssertionError: _num_busy_threads == 0 at line 865 of c:\p\p3d\panda3d-1.6.2\panda\src\event\asyncTaskChain.cxx


'''
Created on Oct 11, 2010

@author: dhnizdor
'''
#@PydevCodeAnalysisIgnore
import direct.directbase.DirectStart
import wx
import random
base.startWx()
from direct.task import Task
from direct.actor import Actor
import math
from pandac.PandaModules import WindowProperties
from direct.gui.DirectGui import *
from direct.gui.OnscreenText import OnscreenText
from pandac.PandaModules import TextNode
from direct.gui.OnscreenText import OnscreenText
from direct.actor import Actor
from pandac.PandaModules import *
from direct.showbase import DirectObject
from direct.interval.IntervalGlobal import *
from pandac.PandaModules import loadPrcFileData
from direct.showbase.PythonUtil import Functor 
import sys
#loadPrcFileData("", "load-display pandadx9") #use directx
#sys.path.append('/WalkModels')


base.disableMouse()
#
base.useDrive()
#base.useTrackball()
base.cam.setPos(0 ,-30,5)#camera.setHpr(0, 0, 0)
base.cam.setHpr(0,-5,0)



class MControl():
  b1 = DirectButton(text = ('Treadmill'), scale = (.5,.1,.15),text_scale = (.5,.5),clickSound=None,rolloverSound
     = None, textMayChange = 1, relief=None
     )
  b1.setPos( -0.0266667, 0 , 0.5)
  
  b2 = DirectButton(text = ('Cycle'), scale = (.5,.1,.15),text_scale = (.5,.5),clickSound=None,rolloverSound
     = None, textMayChange = 1, relief=None
     )
  b2.setPos( -0.0266667, 0 , 0.386667)
  
  b3 = DirectButton(text = ('Walk Test'), scale = (.5,.1,.15),text_scale = (.5,.5),clickSound=None,rolloverSound
     = None, textMayChange = 1, relief=None
     )
  b3.setPos( -0.0266667, 0 , 0.27)


  def printloc(self):
    print "b1 " + str(MControl().b1.getTransform())
    print "b2 " + str(MControl().b2.getTransform())
    print "b3 " + str(MControl().b3.getTransform())



m = MControl()

class startWalk():
    def __init__(self):
        import treadmillwalk4



#wk = startWalk()#m.b1.place()
#wk.destroy

#
m.b1["command"]= startWalk
#m.b2['command']= m.printloc
#m.b3['command']= m.printloc




run()

never call run() more than once.

You could try to do something like this:

#in the calling module --------------------
import treadmillwalk4
...
class startWalk(): 
  def __init__(self): 
    treadmillwalk4.main()
...
# in the called module treadmillwalk4.py --------------------
...
def main():
  # your "executable" instructions
if __name__ == "__main__":
  main()

Does this solve?

Thank you.
I didn’t get a chance to try the last code posted.
I took some time out from banging my head against a wall to do more research and this works:

class TreadMill():
def init(self):
runthis = ‘ppython /workspace/plab/sr/treadmillwalk4.py’

    s = os.popen(runthis).read()
    
    print s

Each menu item calls its own class and a new Pand3d window opens on top of the menu window with the program running.

The python os module is confusing in documentation and examples and to make it more fun was apparently decremented in 2.7 with process.