Skip to content
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

issues with unicode_literals and pysides.QtCore.Slot #2378

Closed
tacaswell opened this issue Sep 4, 2013 · 5 comments
Closed

issues with unicode_literals and pysides.QtCore.Slot #2378

tacaswell opened this issue Sep 4, 2013 · 5 comments

Comments

@tacaswell
Copy link
Member

If I use PySides as the qt4 backend:

tcaswell@mara:~$ ipython --pylab
Python 2.7.5+ (default, Aug  4 2013, 10:07:17) 
Type "copyright", "credits" or "license" for more information.

IPython 2.0.0-dev -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
Segmentation fault

git bisect points me to commit f4adec7 as the first bad commit.

It works (that is, does not seg-fault) if pyqt is used instead.

I spent a bit of time trying to track down exactly where it was blowing up and it seems to bad a bad interaction between from __future__ import unicode_literals and the pyside version of @QtCore.Slot().

@tacaswell
Copy link
Member Author

also see https://code.google.com/p/spyderlib/issues/detail?id=1466 -> discussion at -https://code.google.com/p/spyderlib/source/detail?r=d12c3026caee -> https://bugreports.qt-project.org/browse/PYSIDE-100

so it looks like this is long standing but unfixed upstream issue.

@tacaswell
Copy link
Member Author

And it looks like the 'fix' is to convert all of the Qt calls to new style calls.

If we look at the top of backend.qt4_editor/formlayout.py (which just happens to be the first place that @QtCore.Slot() is encountered when importing stuff) if we change it to:

from __future__ import absolute_import, division, print_function, unicode_literals

import six
from six.moves import xrange

# History:
# 1.0.10: added float validator (disable "Ok" and "Apply" button when not valid)
# 1.0.7: added support for "Apply" button
# 1.0.6: code cleaning

__version__ = '1.0.10'
__license__ = __doc__

DEBUG = False

import sys
STDERR = sys.stderr

from matplotlib.colors import is_color_like
from matplotlib.colors import rgb2hex
from matplotlib.colors import colorConverter

from matplotlib.backends.qt4_compat import QtGui, QtCore
if not hasattr(QtGui, 'QFormLayout'):
    raise ImportError("Warning: formlayout requires PyQt4 >v4.3 or PySide")

import datetime

class ColorButton(QtGui.QPushButton):
    """
    Color choosing push button
    """
    # __pyqtSignals__ = ("colorChanged(QColor)",)

    def __init__(self, parent=None):
        QtGui.QPushButton.__init__(self, parent)
        self.setFixedSize(20, 20)
        self.setIconSize(QtCore.QSize(12, 12))
        # self.connect(self, QtCore.SIGNAL("clicked()"), self.choose_color)
        self._color = QtGui.QColor()

    def choose_color(self):
        color = QtGui.QColorDialog.getColor(self._color,self.parentWidget(),'')
        if color.isValid():
            self.set_color(color)

    def get_color(self):
        return self._color

    @QtCore.Slot(QtGui.QColor)
    def set_color(self, color):
        if color != self._color:
            self._color = color
            # self.emit(QtCore.SIGNAL("colorChanged(QColor)"), self._color)
            pixmap = QtGui.QPixmap(self.iconSize())
            pixmap.fill(color)
            self.setIcon(QtGui.QIcon(pixmap))

    color = QtCore.Property(QtGui.QColor, get_color, set_color)

It does not segfault.

@tacaswell
Copy link
Member Author

Sorry for having a conversation with my self, but it doesn't look too bad to (only ~34 lines need to be changed in only two files (backend_qt4.py and formlayout.py). I will take a crack at this tonight.

@mdboom
Copy link
Member

mdboom commented Sep 4, 2013

Great. The change to not using 2to3 was just merged yesterday, and I'm glad it's already getting its tyres kicked, and thanks for finding a solution.

@mdboom
Copy link
Member

mdboom commented Sep 4, 2013

@tacaswell: Thanks. Sorry for the speedbump, but I think we're going to prefer not running 2to3 anymore in the long run.

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Sep 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants