Backend for Pyside

Please forgive me if I’m raising a heretical question with this
since I
understand the topic of competing Qt bindings for Python gets a
little
touchy in and of itself. Nonetheless, the elephant is in the
room. I
searched the archives and found only a few comments on the
subject:
"
target=“_new”>>
Has there been any additional discussion among the developers
about
creating a formal backend for Pyside?
Its actually a fairly easy to get the PyQt backend working with
PySide. It would have been laughably easy if not for a couple of
bugs in PySide that took awhile to track down.
To get it working PySide working you need to:
It might also be a good idea to convert all the signals/slots into
the new style but it seems to work just fine with only the above
changes.
Regards,
Gerald.

···

matplotlib-users@lists.sourceforge.net/msg18652.htmlhttp://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg18652.html

  • Obviously replace the reference to PyQt with PySide

  •     Remove the reference to PyQt/Pyside.Qt and Qt.qApp by
    

    replacing it with QtGui.qApp (I think this is already done in
    the most recent Git version)

  • Replace the toolbar message signal with a new style signal by:

  •       adding 'message = QtCore.Signal(str)' to the
    

    NavigationToolbar2QT class definition

  •       replacing: QtCore.QObject.connect(self.toolbar,
    

    QtCore.SIGNAL(“message”),

    self.window.statusBar().showMessage)

          with:self.toolbar.message.connect(self.window.statusBar().showMessage)
    
  • replacing: self.emit(QtCore.SIGNAL(“message”), s)

          with: self.message.emit(s)
    
  •     Work around the PySide bug with QImage and convert the string
    

    passed from the Agg backend into a python buffer with
    buffer(stringBuffer) or wait for PySide to fix bug 489.

  •     Work around a PySide bug (738) by creating functions to
    

    perform the slider.setMaxiumum/setMinimum tasks or ignore the
    runtime errors for now and wait for a bug fix.

  •     I haven't bothered with the figure options editor at this
    

    point - I just commented out the references to it.

It turns out that it was also trivial to get the figure options
editor working with PySide.

All that needed to be done was (in formlayout.py):
  • Replace the references to PyQt with PySide

  •     Change: from PyQt.QtCore import (Qt, SIGNAL, SLOT, QSize,
    

    QString,

                                  pyqtSignature, pyqtProperty)
    

    #QString,

                                  #pyqtSignature, pyqtProperty)
    
                                   Slot as pyqtSignature, Property as
    

    pyqtProperty)

  • Add the following after the import statements:

        # Hacks to emulate PyQt
    
        QString = str
    
        class QColorDialog(QColorDialog):
    
            @staticmethod
    
            def getRgba(color,parent):
    
                result =
    

    QColorDialog.getColor(QColor.fromRgba(color),parent,’’)

                return result.rgba(),result.isValid()
    

    Formlayout could probably be updated so it doesn’t need the hacks
    but I wanted to keep changes to a minimum.

    Gerald.

···

matplotlib-users@lists.sourceforge.net/msg18652.htmlhttp://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg18652.html

  • Obviously replace the reference to PyQt with PySide

  •       Remove the reference to PyQt/Pyside.Qt and Qt.qApp by
    

    replacing it with QtGui.qApp (I think this is already done in
    the most recent Git version)

  •       Replace the toolbar message signal with a new style signal
    

    by:

  •         adding 'message = QtCore.Signal(str)' to the
    

    NavigationToolbar2QT class definition

  •         replacing: QtCore.QObject.connect(self.toolbar,
    

    QtCore.SIGNAL(“message”),

    self.window.statusBar().showMessage)

    with:self.toolbar.message.connect(self.window.statusBar().showMessage)

  • replacing: self.emit(QtCore.SIGNAL(“message”), s)

            with: self.message.emit(s)
    
  •       Work around the PySide bug with QImage and convert the
    

    string passed from the Agg backend into a python buffer with
    buffer(stringBuffer) or wait for PySide to fix bug 489.

  •       Work around a PySide bug (738) by creating functions to
    

    perform the slider.setMaxiumum/setMinimum tasks or ignore the
    runtime errors for now and wait for a bug fix.

  •       I haven't bothered with the figure options editor at this
    

    point - I just commented out the references to it.

I’ve just noticed that its possible to use an external package as a
back end so I moved my changes into their own package. This is
sufficient for my own use but I’m guessing others may find is useful
as well (and it might speed official support).

Attached is the package.

Regards,

Gerald.

pysidempl.zip (17.9 KB)

···

On 17/03/2011 5:00 PM, Gerald Storer wrote:

  It turns out that it was also trivial to get the figure options

editor working with PySide.

  ...



  Gerald.