Can i somehow instance ipython (or even better, ipython-qtconsole) and step trough its's (IPython's) main loop manually?
I want to edit panda3d programs on the fly.
EDIT1: Here is code sample which should clarify a bit what i want to do.
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from direct.showbase.ShowBase import ShowBase
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.qtApp = QApplication(sys.argv)
label = QLabel("Hello World")
label.show()
self.m = loader.loadModel("frowney")
self.m.reparentTo(render)
while 1:
self.qtApp.processEvents() #manual step trough Qt loop
taskMgr.step() #manual step trough Panda3D loop
app = MyApp()
So you can see how i can manually step trough panda and qt, i want to do same with ipython if its possible.
ANSWER Complete file:
from direct.showbase.ShowBase import ShowBase
from IPython.lib import inputhook
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.m = loader.loadModel("frowney")
self.m.reparentTo(render)
def stepMe(self):
taskMgr.step() #manual step trough Panda3D loop
return 0
if __name__ == "__main__":
app = MyApp()
inputhook.set_inputhook(app.stepMe)
In your cmd line, just go to directory where file is and do
ipython
run file.py
app.m.setPos(1,1,1)
Run the script in the ipython debugger using
The
-b40
parameter sets a breakpoint in the script on line 40 (which should be the first line of the loop you want to debug). Typec
at the prompt to start the script which will stop at the breakpoint. Typeh
to get help on the debugger.By "edit panda3d programs on the fly", do you just mean changing things in order to test your running program? Or actually making persistent edits to your program's structure in the interactive environment?
Simply stepping over your loop in an interactive python session is quite easy. You can just replace
while 1:
with a method declaration such asdef step(self):
, then call it for each step.With
if __name__ == "__main__"
for the main loop, your file will still work as it should when run standalone. But now you can import it into an interactive session and modify things in between steps.Now to add it to IPython's event loop, so it will be run as you use the interpreter, you can use
IPython.lib.inputhook.set_inputhook()
(new in IPython 0.11).This should cause your program to run while the interpreter is idle, but still allow manipulation as usual.