Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix embedding_in_qt4_wtoolbar.py on Python 3 #976

Merged
merged 1 commit into from

4 participants

@cgohlke

No description provided.

@pelson
Collaborator

+1. Tested it works with 2.6?

@cgohlke

Not tested with 2.6 and 2.7 yet.

@WeatherGod
Collaborator

It "works" in 2.7, but I wonder if this example needs an overhaul. The toolbar is placed at the bottom, which doesn't seem to be the default location anymore for Qt4Agg. Also, the display of the cursor coordinates in the corner only works for a brief period before it only shows empty quotes.

@pelson
Collaborator

Is that a regression as a result of this PR? If not, I would suggest merging this and opening an issue (If @cgohlke is ready and willing to be an assignee, that would be even better :-) )

@WeatherGod
Collaborator

Looks like it is not a regression. The current version of the script also have the same problems.

@efiring efiring merged commit 63e406b into matplotlib:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 30, 2012
  1. @cgohlke
This page is out of date. Refresh to see the latest.
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()
Something went wrong with that request. Please try again.