|
From: John H. <jd...@gm...> - 2007-11-09 18:41:30
|
On Nov 9, 2007 12:37 PM, John Hunter <jd...@gm...> wrote: > On Nov 8, 2007 7:48 PM, sunzen w. <su...@gm...> wrote: > > Mike, > > Thank you for your suggestion. > > I found that pan mode doesn't work as expected in page of notebook. > > The sample code is attached. > > Thanks for your further guidance in advance. > > > Now that is a well focused question. A little googling revealed that > when a gtk drawing area (eg an matplotlib canvas) is placed in a gtk > notebook, it needs to have the focus to receive key press events. > > http://www.daa.com.au/pipermail/pygtk/2002-August/003190.html > > I had hoped it would be enough to do > > canvas.grab_focus() > > but apparently it is not (upon testing). But the suggestion from the > link above to use TAB to grab the focus worked in my tests. With a little more testing, I find if I grab the focus after showing the window that the notebook is in, it works as expected: notebook = gtk.Notebook() win.add(notebook) vbox = gtk.VBox() fig = mplfigure.Figure(figsize=(5,4), dpi=100) canvas = FigureCanvas(fig) # a gtk.DrawingArea vbox.pack_start(canvas) toolbar = NavigationToolbar(canvas, win) vbox.pack_start(toolbar, False, False) notebook.insert_page(vbox, gtk.Label('Graph')) win.show_all() # need to get the focus in a notebook to handle keypress # events canvas.grab_focus() |