Skip to content

Commit 80b95ed

Browse files
author
Daniel O'Connor
committed
Try PySide then PyQt4 for Qt4 examples.
Use the correct connect method for PySide. This should make the examples work with both PyQt4 and PySide (I can only test the later)
1 parent 575de44 commit 80b95ed

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

examples/animation/old_animation/animation_blit_qt4.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
from matplotlib.figure import Figure
1212
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
1313

14-
from PyQt4 import QtCore, QtGui
14+
try:
15+
from PySide import QtCore, QtGui
16+
except ImportError:
17+
from PyQt4 import QtCore, QtGui
1518

1619
ITERS = 1000
1720

examples/user_interfaces/embedding_in_qt4.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111

1212
from __future__ import unicode_literals
1313
import sys, os, random
14-
from PyQt4 import QtGui, QtCore
14+
try:
15+
from PySide import QtGui, QtCore
16+
usepyside = True
17+
except ImportError:
18+
from PyQt4 import QtGui, QtCore
19+
usepyside = False
1520

1621
from numpy import arange, sin, pi
1722
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
@@ -57,7 +62,10 @@ class MyDynamicMplCanvas(MyMplCanvas):
5762
def __init__(self, *args, **kwargs):
5863
MyMplCanvas.__init__(self, *args, **kwargs)
5964
timer = QtCore.QTimer(self)
60-
QtCore.QObject.connect(timer, QtCore.SIGNAL("timeout()"), self.update_figure)
65+
if usepyside:
66+
timer.timeout.connect(self.update_figure)
67+
else:
68+
QtCore.QObject.connect(timer, QtCore.SIGNAL("timeout()"), self.update_figure)
6169
timer.start(1000)
6270

6371
def compute_initial_figure(self):

examples/user_interfaces/embedding_in_qt4_wtoolbar.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
from matplotlib.backends.backend_qt4agg import (
99
FigureCanvasQTAgg as FigureCanvas,
1010
NavigationToolbar2QTAgg as NavigationToolbar)
11-
from PyQt4.QtCore import *
12-
from PyQt4.QtGui import *
11+
try:
12+
from PySide.QtCore import *
13+
from PySide.QtGui import *
14+
except ImportError:
15+
from PyQt4.QtCore import *
16+
from PyQt4.QtGui import *
1317

1418

1519
class AppForm(QMainWindow):

0 commit comments

Comments
 (0)