Switching focus between panda window and wx

Hello,

I have an application with a panda3d window embedded in a wx frame.
I use the following code to capture all button events:

base.buttonThrowers[0].node().setButtonDownEvent('button')
base.buttonThrowers[0].node().setButtonUpEvent('buttonUp')
base.buttonThrowers[0].node().setButtonRepeatEvent('buttonRepeat')
self.accept("button", self._onButtonDown)
self.accept("buttonRepeat", self._onButtonRepeat)
self.accept("buttonUp", self._onButtonUp)

The problem I have is that I cannot write inside the text controls in the wx frame as the events are grabbed by panda.

I thought about disabling input detection when the mouse goes outside the panda window and reenabling it when the mouse re-enter, so I’ve written a task that checks if the mouse watcher node has the mouse. That works, but I still cannot properly disable input detection.

I tried using ignoreAll and using the ButtonThrower methods clearThrowButtons and removeThrowButtons, but I still can’t write inside the text controls (which are editable).

Anybody has an idea how to “shift” the input detection to wx ?

I don’t see how whether you have called accept() on a button event has anything to do with whether wx gets to process the event or not. Panda doesn’t have the ability to “steal” events from any other window. This is really up to the operating system: Panda will process all of the button events that get delivered to the Panda window, while wx will process all of the button events that get delivered to the wx window.

If the operating system is sending button events to the wrong window, that’s more a question of specifying the right keyboard focus to the operating system. Which OS are you running on?

David

Linux.

I made a small example to better explain the problem.
The example has a wx frame with a panda window embedded inside and a text ctrl.
What I don’t understand is why I can’t edit inside the text box. I’m pretty new also to wx so maybe I’m missing something obvious, anyway here it is…

# -*- coding: utf-8-*-

import wx, string

from pandac.PandaModules import loadPrcFileData
loadPrcFileData("", "want-wx 1")

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import WindowProperties


class TestApp(wx.App):
    def OnInit(self):
        self.frame = wx.Frame(None, -1, "Test", size=(400,300))
        self.SetTopWindow(self.frame)
        self.frame.Center()
        self.frame.Show(True)
        
        self.surfaceHandle=self.frame.GetHandle()
        self.evtLoop = wx.EventLoop()
        self.oldLoop = wx.EventLoop.GetActive()
        wx.EventLoop.SetActive(self.evtLoop)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.frame.SetSizer(sizer)
        sizer.Add(wx.Panel(self.frame), 1, wx.EXPAND | wx.ALL)
        textCtrl = wx.TextCtrl(self.frame, -1, "Can't change", size=(200,-1))
        textCtrl.SetEditable(True)
        sizer.Add(textCtrl,0 , wx.ALL)
        
        self.frame.Layout()
        
        taskMgr.add(self.MainLoop, "wx-mainloop")
        
        return True
    

    def MainLoop(self, task = None):
        while self.evtLoop.Pending(): 
            self.evtLoop.Dispatch()
        self.ProcessIdle()
        
        if task != None: return task.cont
        
        return True


class World(DirectObject):
    def __init__(self):
        t = TestApp()
        
        self.accept("escape", self.exit)
        self.accept("a", self.test)
        
        wp = WindowProperties().getDefault()
        wp.setOrigin(0,0)
        wp.setSize(400, 260)
        wp.setParentWindow(t.surfaceHandle)
        base.openDefaultWindow(props=wp)
    
        self.isRunning = True
    
    def test(self):
        print "Pressed a" 
    
    def exit(self):
        self.isRunning = False
    
    def run(self):
        import time
        while self.isRunning:
            taskMgr.step()
            time.sleep(0.001)
       
if __name__ == '__main__':
    w = World()
    w.run()

Hmm, works fine for me, on my old Fedora 4 box. I can edit the contents of the text box to my heart’s content.

Maybe something with your window manager is not allowing window focus to change? Has anyone else ever had a problem like this?

David

I’m using Ubuntu Gnome and 8.10.
I just discovered that if I alt+tab to switch to another app and then I alt+tab again I’m able to edit the box. That’s weird…

Using Gnome, Ubuntu 8.10 and yesterday’s cvs I can confirm this. I’m not able to edit the text box until I press alt+tab twice.