On Wed, Mar 2, 2011 at 9:26 AM, Martin Teichmann <lkb.teichmann@gmail.com> wrote:
Hi list,

I'm using matplotlib as a library, in a program using the
new APIs of PyQt4, which will be the normal APIs for
Python 3. Unfortunately, the matplotlib Qt4 backend is
not compatible with this new API.

The problems are easy to fix: first QFileDialog.getSaveFileName
has changed, and is to be replaced with
QFileDialog.getSaveFileNameAndFilter, for example with the following
patch:

-----------------------------------------------------------------------------------------------
--- backend_qt4.py      2011-03-02 16:17:19.526831397 +0100
+++ backend_qt4_orig.py 2011-03-02 16:16:38.257797767 +0100
@@ -395,9 +395,8 @@
            filters.append(filter)
        filters = ';;'.join(filters)

-        fname, _ = QtGui.QFileDialog.getSaveFileNameAndFilter(
-            self, "Choose a filename to save to", start, filters,
-            selectedFilter)
+        fname = QtGui.QFileDialog.getSaveFileName(
+            self, "Choose a filename to save to", start, filters,
selectedFilter)
        if fname:
            try:
                self.canvas.print_figure( unicode(fname) )
-----------------------------------------------------------------------------------------------

secondly, QString is used in the new formlayout, wich can be avoided
using yet another patch, that I actually once filed as Path #3081405
in the matplotlib patch tracker.

-----------------------------------------------------------------------------------------------
--- formlayout.py       2010-10-05 11:45:01.000000000 +0200
+++ formlayout.py-orig  2010-10-01 12:28:34.000000000 +0200
@@ -56,7 +56,8 @@
                         QPixmap, QTabWidget, QApplication, QStackedWidget,
                         QDateEdit, QDateTimeEdit, QFont, QFontComboBox,
                         QFontDatabase, QGridLayout)
-from PyQt4.QtCore import Qt, SIGNAL, SLOT, QSize, pyqtSignature, pyqtProperty
+from PyQt4.QtCore import (Qt, SIGNAL, SLOT, QSize, QString,
+                          pyqtSignature, pyqtProperty)
 from datetime import date


@@ -101,7 +102,10 @@
    Avoid warning from Qt when an invalid QColor is instantiated
    """
    color = QColor()
-    text = unicode(text)
+    if isinstance(text, QString):
+        text = str(text)
+    if not isinstance(text, (unicode, str)):
+        return color
    if text.startswith('#') and len(text)==7:
        correct = '#0123456789abcdef'
        for char in text:
-----------------------------------------------------------------------------------------------------------

Greetings

Martin


Martin,

Thank you for letting us know about continuing issues with PyQT4.  First, I think your patches are "backwards", per se.  Can you double-check that they are what you mean?  Also, which version of matplotlib did you patch against?  I know that we recently made a fix involving QString:

https://github.com/matplotlib/matplotlib/commit/fa82c5adcc1493ec705728e4beb806cb4c84579f

I see we probably still need to fix the backend, but is everything else in order?

Ben Root