IPython iterates through the main loop manually?

Is it possible to somehow create an instance of ipython (or even better, ipython-qtconsole) and execute the main loop (IPython) manually?

I want to edit panda3d programs on the fly.

EDIT1: Here is an example code that 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 execute the panda and qt trough, I want to do the same with ipython, if possible.

ANSWER Full 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 the directory where the file is located and do

  • ipython
  • run file.py
  • app.m.setPos(1,1,1)
+5
source share
2 answers

" panda3d" ", , ? ?

python . while 1: , def step(self):, .

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)

    def step(self):
        self.qtApp.processEvents()  #manual step trough Qt loop
        taskMgr.step()              #manual step trough Panda3D loop
        return 0                    #PyOS_InputHook expects an integer

if __name__ == "__main__":
    app = MyApp()
    while 1: app.step()

if __name__ == "__main__" , . .

>>> import myfile
>>> app = myfile.MyApp()
>>> app.step()
>>> app.something = something_else
>>> app.step()

, IPython, , IPython.lib.inputhook.set_inputhook() ( IPython 0.11).

>>> from IPython.lib import inputhook
>>> inputhook.set_inputhook(app.step)

, , , , .

+2

script ipython,

%run -d -b40 myscript

-b40 script 40 ( , ). c , script, . h, .

+1

All Articles