Keyboard lost control for multiple windows in wxPython

Hi, I needed some help. I created a panda program, which will dock two panda window in a wxFrame. However, when I created the second window to be docked into the wxFrame, all my keyboard key event seemed to be lost, i.e. I cannot control by using keyboard (which I already have code using self.accept, etc.)

Is this just window properties problem where the new window taking control over the default window?

Thanks for the help, and happy new year!

Hi, I guess I should post the code:

# docking the Panda view into pandaPanel
        base.windowType = 'onscreen'
        winProps = WindowProperties.getDefault()
        winProps.setParentWindow(self.pandaPanel.GetHandle())
        winProps.setOrigin(0,0)
        base.openDefaultWindow(props=winProps)
        # docking the fixedView into fixedViewPanel
        winProps2 = WindowProperties.getDefault()
        winProps2.setParentWindow(self.fixedViewPanel.GetHandle())
        winProps2.setOrigin(0,0)
        winProps2.setSize(325,200)
        base.openWindow(winProps2) 

Do you mean this case :
discourse.panda3d.org/viewtopic.php?t=4589 ??

something similiar, but actually I docked inside the wxPanel, instead of the MDI child. If creating only one panda window and dock it inside a wxPanel (which is the defaultWindow), I am fine and can use the keyboard. But when a new window is created to host another camera view, I will have problem.

So, is it the same? And also, enabling mouse also means enabling keyboard?

Well, I kind of fix the problem by re-opening the defaultWindow again, which is shown in the code below:

# docking the Panda view into pandaPanel
        base.windowType = 'onscreen'
        winProps = WindowProperties.getDefault()
        winProps.setParentWindow(self.pandaPanel.GetHandle())
        winProps.setOrigin(0,0)
        base.openDefaultWindow(props=winProps)
        
        # docking the fixedView into fixedViewPanel
        winProps2 = WindowProperties()
        winProps2.setParentWindow(self.fixedViewPanel.GetHandle())
        winProps2.setOrigin(0,0)
        winProps2.setSize(325,200)
        base.openWindow(props=winProps2)
        
        # reopening the default window to get keyboard input
        base.openDefaultWindow(props=winProps)

However, now I faced the other problem is that whenever I lost focus of the whole program, for example I minimize the main wxFrame, I will loose focus again. I guess I will need some wx binding on the wxFrame get focus, then re-open the main panda window again.

Is there any better option out there?

Yes, as discussed in the thread that ynjh_jo linked to. It sounds exactly like the problem you’re reporting, which has nothing to do with wxWidgets or anything; it’s not even a problem with “losing focus”. It’s just that, in order to receive button events for the keyboard and mouse buttons within a window, you need to have the appropriate Panda constructs in place to listen for them.

David