Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #976 from cgohlke/patch-12

Fix embedding_in_qt4_wtoolbar.py on Python 3
  • Loading branch information...
commit 63e406b56972a3566c55ee1300acdf4c02afb3a8 2 parents 585e0fa + 7f9c849
@efiring efiring authored
Showing with 12 additions and 8 deletions.
  1. +12 −8 examples/user_interfaces/embedding_in_qt4_wtoolbar.py
View
20 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):
@@ -23,7 +26,7 @@ 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)
@@ -31,13 +34,13 @@ def create_main_frame(self):
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()
@@ -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()

0 comments on commit 63e406b

Please sign in to comment.
Something went wrong with that request. Please try again.