开发者

Allow a wxPanel dervied object to accept focus

开发者 https://www.devze.com 2023-03-29 23:42 出处:网络
I\'m using matplotlib to generate charts and displaying these in a WxPython based frontend using FigureCanvasWxAgg object (from matplotlib) which is derived from WxPane开发者_如何学Cl.

I'm using matplotlib to generate charts and displaying these in a WxPython based frontend using FigureCanvasWxAgg object (from matplotlib) which is derived from WxPane开发者_如何学Cl.

I want to add functionality to each chart to allow the arrow keys to control the position of an overlay if that chart is selected. In order to do this I need the chart to accept focus so I can bind to each charts wx.EVT_KEY_DOWN.

At the moment using a timer to display what has focus once every second (using wx.Window.FindFocus()) shows that when the left mouse button is held down whilst hovering over one of the charts, > has focus (which is correct) but as soon as the button is released, focus returns to "None."

Any suggestions on how to make the wxPanel derived FigureCanvasWxAgg object keep focus?


wx.Panel doesn't really accept focus. It just passes the focus on to a widget that can. Only when it doesn't have a child can it accept focus. You may need to call SetFocus() on it though. This article tries to explain it: http://www.blog.pythonlibrary.org/2009/08/27/wxpython-learning-to-focus/

0

精彩评论

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

关注公众号