How can I get handle to second window render and render2d nodepaths?

I really need a way to get hold of that camera so that I may attach a 3d scene to it. At this point I’m not certain how to create a new camera and given that self.camList[1] gives None and is out of bounds when I try to access it I wonder how to add that second camera to that second window.

Pardon me I am just trying to accomplish my goals. I don’t expect you to figure out everything for me I just haven’t found anything that is specific enough in the manual.

In fact, the second window does not mean that it is a different rendering and other nodes.

from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):

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

        self.scene = self.loader.loadModel("models/environment")
        self.scene.reparentTo(self.render)

        Window2 = self.openWindow()

app = MyApp()
app.run()

Good to know, I managed to find this out recently. Another question: please tell me there’s some way to keep both windows in focus at the same time??

I don’t think this is the OS coverage area.

What?? Is there a section for that?

I mean, the OS manages this state.

I don’t suppose there’s a way I might make this happen via modifying the engine code? I mean anything can be possible that way I’d assume but I’m not sure I want to undertake that endeavor…

I say that it is not the Panda that decides, but the OS. It is unacceptable for her to have two Windows with focus, maybe you have seen this case? When there are two Windows with focus…

You can switch focus using a mouse event, otherwise you don’t need it.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import NodePath, WindowProperties
from direct.gui.DirectGui import DirectButton
from direct.task import Task

class MyApp(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)
        
        self.win_focus = None

        scene = self.loader.loadModel("models/environment")
        scene.reparentTo(self.render)

        window_properties = WindowProperties()
        window_properties.setSize(800, 600)
        window_properties.setTitle('win2')

        self.win2 = self.openWindow(props = window_properties)

        render2d2 = NodePath('render2d2')
        camera2d_win2 = self.makeCamera2d(self.win2)
        camera2d_win2.reparentTo(render2d2)

        button_win = DirectButton(text = ("OK_win", "click!", "rolling over", "disabled"), scale = 0.07, command = None)

        self.taskMgr.add(self.focus_task, "focus_task")

    def active_win(self, windows):
        self.setupMouse(windows)

    def focus_task(self, task):
        if self.win.getProperties().getForeground() == True:
            if self.win_focus != 'win':
                self.win_focus = 'win'
                self.active_win(self.win)

        if self.win2.getProperties().getForeground() == True:
            if self.win_focus != 'win2':
                self.win_focus = 'win2'
                self.active_win(self.win2)

        return Task.cont
        
app = MyApp()
app.run()

This is a short example, there is still a lot to implement to fully support the second window.

What are you trying to achieve by giving both windows focus? Perhaps there’s another way to go about it that will produce the same or similar effects…

I am working on an independent study at University to develop a robotics simulator. It would be really great if I could do something a lot like Unity3d, where the 3d window can be popped in and out of place and always be on top…

Aah, I see. Hmm… I’m not sure of how double-focus would help there, but that’s besides the point.

As for having a window be always-on-top, I don’t know offhand whether Panda offers such functionality. You may end up looking to OS-specific code for that.

As for popping a window in-and-out of place, I might suggest spawning a new window when popping out, and destroying the window when popping in, transferring the contents as appropriate.

Hmm… In the case of Unity, can you move those separate windows independently of the main window? That is, covering an entirely different rectangle of the desktop? If not, then the implementation is much simpler–Panda has the means to make a frame within a window be always-on-top, I believe, and dockable panels should be possible to implement.

Yes, the window Z-order can be set using:

WindowProperties.setZOrder(WindowProperties.Z_top)

See also this topic for a discussion about that.

Actually, I once requested a feature that would keep a secondary window always above a primary window, so it would never get lost below other, non-related windows. It might still be on the devs’ todo-list. Here is the relevant post.

And yeah, whether we like it or not, window managers decide what to do with the window(s) of our application, not the other way around.

2 Likes

My memory may not be serving me. I was pretty sure about what I said but I actually think now they don’t do anything too special. I think the windows that get “popped out” just sit there until they lose focus then reappear when focused again. It doesn’t have to be exactly the same as Unity I just wanted a useful/intuitive interface.

EDIT: So I thought of something (I really ought to have planned this) but the main reason is because that 3d window I want to be an actual window pinned within the editor. I could do a display region type thing but IDK if I want to do that. I might have to draw a custom border around it and pop out the window by creating a new window directly over top of it as was mentioned here before…

Ah, that’s neat–I didn’t know that we had this feature! :slight_smile:

Hmm… How do they gain focus if they’ve disappeared?

But I suppose that that’s a tangent, so nevermind that! Thank you for the explanation given.

If I may, what is the advantage of having the panel in question be a separate window, instead of just a separate panel within a single window? Do you intend for the panel to leave the confines of the editor-window?

But yeah, if you do intend for the panel to leave the confines of the window, then I stand by my suggestion of spawning and destroying windows as called for.

Good advice! The only reason for this is to be able to rearrange windows for a custom UI. Its not strictly a make or break feature its just that no window layout will work with every display. People have differing preferences.

That’s fair–and I suppose that using multiple windows could be useful when dealing with unusual configurations of multiple monitors.