Skip to content

Fix embedding_in_qt4_wtoolbar.py on Python 3 #976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions examples/user_interfaces/embedding_in_qt4_wtoolbar.py
Original file line number Diff line number Diff line change
@@ -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