From: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - 2006-12-03 20:19:14
|
On 01/12/2006 05:29, Karl Knechtel wrote: > > Eventually I found a sample in some wxPython tutorials, from which I got > something that worked: > > # in on_initialize of the Background subclass > panel = wx.Panel(self, -1) > panel.Bind(wx.EVT_KEY_DOWN, self.on_keyDown) > panel.SetFocus() > > The key being creation of a separate Panel object. My questions are, (1) > why is this seemingly necessary? and (2) what is the -1 value passed to > the Panel constructor? (1) Well, I'm only a few chapters into the "wxPython In Action" book and trying to get event handling into my brain, so if anyone has a better explanation please chip in. Here's one possibility. Key press up and down events are wx.KeyEvent types, which can only be picked up by window objects that can get focus. Since the application object can not gain focus it cannot detect a KeyEvent. KeyEvents are not passed up the chain of objects either - they can only be detected by the window object with focus. Having said all that, I'm not sure how you were able to detect key-up events. (2) This is the window ID for the panel - if you specify -1, which is the default, you let wxPython/wxWidgets create an ID for you. Every GUI object has a window ID. <http://wxwidgets.org/manuals/2.6.3/wx_wxpanel.html#wxpanel> > I assume this is a wxPython problem; where might I report it? Or, have > any of you any good ideas about how to deal with it? (Right now I put in > some code to do it manually; I am planning to change it to do a > .Rescale(), check the resulting image via the data-buffer to detect the > problem, and correct it with some blitting logic when it happens.) > > - Any good ideas about how to control the key repeat rate for keyDown > messages? Can't help much, sorry, but you should have more luck on the wxPython site or using one of the wxPython mailing lists: <http://www.wxpython.org/maillist.php> > - Later, I will want to implement a scrolling canvas (I need this also for > the tile editor and engine). For the editors (not the engine ;) ) I want > to attach scroll bars to the canvas area, to indicate what part of the > image is drawn, and to scroll it. I thought about using Sliders, but they > don't look right, and don't indicate the relative size of the displayed > window, the way real scrollbars do. But I haven't found a scrollbar-widget > in PythonCard. Did I miss something? Or is there something I can use from > wxPython? Also, is there some benefit I can gain from making a "group" of > controls here (the canvas, horizontal scrollbar and vertical scrollbar)? wxPython has a drop-in replacement for the wx.Panel, called wx.ScrolledWindow , which has a method called SetScrollbars which allows you to set the overall size of the area. I'm not sure if they indicate the relative size. -- XXXXXXXXXXX |