Skip to content

Commit

Permalink
Merge pull request matplotlib#976 from cgohlke/patch-12
Browse files Browse the repository at this point in the history
Fix embedding_in_qt4_wtoolbar.py on Python 3
  • Loading branch information
efiring committed Jul 22, 2012
2 parents 585e0fa + 7f9c849 commit 63e406b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions examples/user_interfaces/embedding_in_qt4_wtoolbar.py
@@ -1,13 +1,16 @@
from __future__ import print_function

import sys

import numpy as np
from matplotlib.figure import Figure
from matplotlib.backend_bases import FigureManagerBase, key_press_handler
from matplotlib.backend_bases import key_press_handler
from matplotlib.backends.backend_qt4agg import (
FigureCanvasQTAgg as FigureCanvas,
NavigationToolbar2QTAgg as NavigationToolbar)
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar


class AppForm(QMainWindow):
def __init__(self, parent=None):
Expand All @@ -23,21 +26,21 @@ def create_main_frame(self):
self.fig = Figure((5.0, 4.0), dpi=100)
self.canvas = FigureCanvas(self.fig)
self.canvas.setParent(self.main_frame)
self.canvas.setFocusPolicy( Qt.StrongFocus )
self.canvas.setFocusPolicy(Qt.StrongFocus)
self.canvas.setFocus()

self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame)

self.canvas.mpl_connect('key_press_event', self.on_key_press)

vbox = QVBoxLayout()
vbox.addWidget(self.canvas) # the matplotlib canvas
vbox.addWidget(self.canvas) # the matplotlib canvas
vbox.addWidget(self.mpl_toolbar)
self.main_frame.setLayout(vbox)
self.setCentralWidget(self.main_frame)

def get_data2(self):
return np.arange(20).reshape([4,5]).copy()
return np.arange(20).reshape([4, 5]).copy()

def on_draw(self):
self.fig.clear()
Expand All @@ -48,11 +51,12 @@ def on_draw(self):
self.canvas.draw()

def on_key_press(self, event):
print 'you pressed', event.key
print('you pressed', event.key)
# implement the default mpl key press events described at
# http://matplotlib.sourceforge.net/users/navigation_toolbar.html#navigation-keyboard-shortcuts
key_press_handler(event, self.canvas, self.mpl_toolbar)


def main():
app = QApplication(sys.argv)
form = AppForm()
Expand Down

0 comments on commit 63e406b

Please sign in to comment.