Interactive development with emacs in pyhton interpreter

Hi, I found the interactive cosole from Hypnos. That looks very interessting. I’m very impressed. Is this the only way to develop with panda interactive in python? I personally like it to start a python interpreter in emacs and keep it alive the whole day :slight_smile:. Then just “replace” new classes while the programm is running. I’v tried this with panda, but not to my satisfaction gg.

Here is a simple example of what I try to do:

from direct.showbase.ShowBase import ShowBase
from direct.task.Task import Task

from direct.stdpy.threading2 import Thread
from pandac.PandaModules import Thread as PandaThread

class Character(object):
    def __init__(self):
        self.model = loader.loadModel("panda")
        self.model.setScale(.2,.2,.2)
        self.model.reparentTo(camera)
        self.model.setPos(0,8,-1)
    
    def walk(self):
        print "walk"

#    def walk_fast(self):
#        print "walk fast"

class MainApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        base.setFrameRateMeter(True)
        self.hero = Character()

    def sayHello(self):
        print "Hello"
        
class tt(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.app = MainApp()
        print "Support panda threading: " , PandaThread.isThreadingSupported()
        self.setName("tt")

    def run(self):
        self.app.run()
        print "Helper Thread done :-)"

This is what I expected:
1.) open emacs and start a python interpreter (C-c C-z).
2.) evaluate Buffer (C-c C-C)
3.) Start panda (in python interpreter)

t = tt()
Known pipe types:
glxGraphicsPipe
(all display modules loaded.)
Support panda threading: 1

t.start()
4.) implement new method in Character: walk_fast()
5.) evaluate Buffer again (=> load to running python interpreter)
6.) “reload” Class and test new method

t.app.hero.class = Character # Use new class
t.app.hero.walk_fast()
walk fast

Or move a object in the console

t.app.hero.model.setPos(-1,-1,-1)
7.) and so on, …

The console output is as expected :slight_smile:. Sadly MainApp stucks. The Framemeter is at 0.00. When I join the Thread in the interpreter it MyApp starts. But I can’t type anything… You can give join a timeout. Then MainApp runs properly until the timeout gg.

t.join(5)

Is there a better way to develop interactive? Have I missunderstood ShowBase?

Sure, we do this all the time. You might want to use the python-model.el that we provide in direct/src/directscripts (copy it into your emacs site-lisp directory).

You can use the interrupt key (control-C, by default) to interrupt the running Python process and return to a prompt at any time, then type run() (or press control-D at the prompt) to start the process running again.

You can make changes to a class and then use control-C control-V with the cursor within the class body, to paste in the changes to the live Python interpreter and update all (or almost all) references to methods in the Python interpreter so that your new methods are called instead of the old method.

David

Thank you drwr! That helped me a lot!

I used the python mode, that was shipped with emacs 23.1.1

That mode works slightly different. But I found the commands, I need :slight_smile:.

I’s:
C-c C-c to interrupt pyhton (in the pyhton shell)

You saved my day :slight_smile: