IPython config integration

Hi,

I like IPython interactive shell but I run into problems regularly when I am using it to develop for Panda3d and I have to restart IPython too often for my taste.

I found that I have to use: base.destroy() or app.destroy() to avoid starting a new ShowBase instance but I still have problems with loading the latest changes from my editor (sometimes the changes are updated, some other times not).

I’d like to have suggestions from IPython users about the settings in the IPython config file
for a smoother integration of IPython with Panda3d.
brd

I think such problems are expected if you use shell with code where there is cyclic code execution. I haven’t really experimented with this much before. The built-in solution was enough for me:

from direct.showbase.ShowBase import ShowBase
from direct.stdpy import threading
from code import InteractiveConsole

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        ic_thread = threading.Thread(target=InteractiveConsole(globals()).interact)
        ic_thread.start()

        self.model = loader.load_model("models/panda-model")
        self.model.reparent_to(render)
        self.model.set_scale(0.005)
        
app = MyApp()
app.run()
Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> app.model.hide()
>>>

As a starting point, you can study the sources of this idea of @rdb, I think you need to clarify with him how it works, by the way, it’s a very good way to study Panda3D interactively.

If you’re trying to develop an application interactively, you can just call base.task_mgr.stop to break out of the main loop, and restart it as usual with base.run.

I had hoped that an experienced IPython user, who had created a profile, say with:
ipython profile create panda
would have posted the diff between his/her ipython_config.py and the default one.

If you can complete this task in your interactive console, then Panda3D really has a problem, and if you can’t, then…

x = "Replace me in the interactive console"
while True:
    print(x)

At least using the built-in interactive console works correctly.

If you are constantly doing push, then obviously you need to somehow bypass the creation of a ShowBase instance. Or just delete this part of the code when doing a push.

app = MyApp()
app.run()

It’s just a logic problem, I’m wondering if there’s a solution for it… you may need to configure the configuration file. This is a joke, of course.

import threading
from code import InteractiveConsole

ic_thread = threading.Thread(target=InteractiveConsole(globals()).interact)
ic_thread.start()

a = "Replace me after"

while True:
    b = "Replace me first"
    if not a == "Replace me after":
        print(a, " and ", b)

It is funny that you brought up a logic problem. I just got in touch with an old friend that I hadn’t seen in more than twenty years. We, both, did our PhDs in math logic in the
late 80s. At one time, we were grad students, and my friend’s sister boyfriend was doing his doctorate in sociology and asked what we were doing exactly. After trying to explain,
in simple terms, what we were doing for a short time, he said: if I understand correctly, that’s intellectual masturbation. My friend and I looked at each other, started to laugh and answered, that’s about right.

To get back to my original post, you can do all kinds of weird stuff using meta-programming. But in my post, I am only interested in its use with the IPython package.

I think that during this conversation, two people have already told you what’s wrong with your approach to using an interactive console.

The code that you are going to interact with must be run once.Because when you restart, you update/create all variables and instances of the class. This leads to a simple logical conclusion: how can configuring the configuration file for Panda3D fix this situation? You can use IPython to change variable b, since I intentionally removed the dependency on Panda3D.

a = "Replace me after"

while True:
    b = "Replace me first"
    if not a == "Replace me after":
        print(a, " and ", b)

Perhaps IPython will handle this somehow.