开发者

wxPython Whole Window Focus Event

With wxPython, how does one trigger an event w开发者_JS百科henever the whole window goes into/out of focus?

To elaborate, I'm building a serial terminal GUI and would like to close down the connection whenever the user doesn't have my application selected, and re-open the connection whenever the user brings my app back into the foreground. My application is just a single window derived from wx.Frame.


The correct answer for this case is to use an EVT_ACTIVATE handler bound to the frame. There will be an event whenever the frame is activated (brought into the foreground relative to other windows currently open) or deactivated. You can use the event object's GetActive method to tell which just happened.


as WxPerl programmer i know there is

EVT_SET_FOCUS(

EVT_KILL_FOCUS(

if you initialize this event by listening to the frame as first parameter it should work as in Perl since the API is almost the same


Interesting article at http://www.blog.pythonlibrary.org/2009/08/27/wxpython-learning-to-focus/

Gist of it: wx.EVT_KILL_FOCUS works fine, but wx.EVT_SET_FOCUS behaves a little oddly for any panel containing widgets (the child's set-focus prevents the panel's set-focus event from firing as expected?)


In addition to what these fellows are saying, you might also want to try EVT_ENTER_WINDOW and EVT_LEAVE_WINDOW. I think these are fired when you move the mouse into and out of the frame widget, although I don't think the frame has to be in focus for those events to fire.

@ Hugh - thanks for the readership!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜