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
Introduce renamed methods of QHeaderView in PyQt4 and PySide #65
Conversation
@tobiasgehring thanks for this :-) Question:
|
QHeaderView.sectionsClickable() -> bool | ||
""" | ||
return QHeaderView.isClickable(self) | ||
QHeaderView.sectionsClickable = sectionsClickable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why define a new method each time ? This code should be equivalent:
QHeaderView.sectionsClickable = QHeaderView.isClickable
I think there a re some differences, like the __name__
attribute would still be the one from the initial method. On the other hand the help should be more complete (instead of just the signature in the current state of this PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Nodd the signatures of pyqt are no better than what Tobias did
So it must be somehow else.
|
Can we also patch these obsolete methods then so that they raise an exception? (What do you think @Nodd?)
Oops, we dont have any documentation for that. You need to install |
thanks, the pytest-cov package was missing. When running the tests now, I get: ERROR: file not found: qtpy and then later on a coverage exception saying that it has no data to report. On 08/19/2016 09:26 AM, Gonzalo Peña-Castellanos wrote:
|
I need more info... what is your system.. what is your env... do you have qtpy installed ? as develop? How ar eyou running the tests...? |
I think I figured it out how to use the tests. Shall I or shall I not make the obsolete functions raise an exception? For PyQt5 it was apparently decided to just not include them. |
Hey @tobiasgehring glad you sorted it out. Well the idea of raising the error is, people using qtpy should be encouraged (gently :-p forced) to write code that looks like qt5 code, so if the have qt4 installed and try to access a method that is only available on qt4, it should raise an error, so they know which method to use. from qtpy.QtWidgets import SomeWidget
# User with qt4 installed
>>> SomeWidget.oldMethodOnlyOnQt4()
Exception: oldMethodOnlyOnQt4 only available on Qt4, use SomeWidget.newMethodOnQt5.
# User with qt5 installed
>>> SomeWidget.newMethodOnQt5()
:-) |
@tobiasgehring, this now has conflicts with @goanpeca, this looks good to me. Please merge when you consider it necessary :-) |
@tobiasgehring this is awesome work :-) thank you very much. Good to go, merging |
This approach causes issues for me with Python 3.5; for one reason or another, the monkey patch doesn't make it through from asking another class about it. widget = QtWidgets.QTreeView()
header = widget.header()
header.setSectionResizeMode(qheaderview.Fixed) # AttributeError! Do you support Python 3.5? Any ideas on what it could be? |
Let me give you a full reproducible, I'm unsure of how specific this problem is. Possibly it's related to this particular version of Python, binding and OS. # Ubuntu 16.04
$ apt-get update
$ apt-get install python3-pyside python3-pip
$ pip3 install qtpy
$ python3
>>> from PySide import QtGui
>>> # setSectionResizeMode is added by qtpy on import
>>> assert not hasattr(QtGui.QHeaderView, "setSectionResizeMode")
>>> import sys
>>> from qtpy import QtWidgets
>>> app = QtWidgets.QApplication(sys.argv)
>>> widget = QtWidgets.QTreeView()
>>> qheaderview = widget.header()
>>> qheaderview.setSectionResizeMode(qheaderview.Fixed)
AttributeError: 'PySide.QtGui.QHeaderView' object has no attribute 'setSectionResizeMode' The problem only occurs when I first import PySide. If I don't import it, it works. Like magic. Let me know what you think. |
Could you open a new issue for this @mottosso? |
Hold on, I'm not sure this is an issue yet, mainly testing the waters to see if it's something familiar to you or Tobias. I noticed this PR wasn't on PyPI yet, so it couldn't have worked in any Python distribution in my example above. This on the other hand does work. # Ubuntu 16.04
$ apt-get update
$ apt-get install python3-pyside git
$ git clone https://github.com/spyder-ide/qtpy.git
$ export PYTHONPATH=$(pwd)/qtpy
$ python3
>>> from PySide import QtGui
>>> # setSectionResizeMode is added by qtpy on import
>>> assert not hasattr(QtGui.QHeaderView, "setSectionResizeMode")
>>> import sys
>>> from qtpy import QtWidgets
>>> app = QtWidgets.QApplication(sys.argv)
>>> widget = QtWidgets.QTreeView()
>>> qheaderview = widget.header()
>>> qheaderview.setSectionResizeMode(qheaderview.Fixed) |
Even if its not yet, I think an issue is a better place to discuss it, not a PR :-) |
The exceptions that are thrown in case you use an obsolete method can break things when you mix packages that use Consider an application that uses Therefore, please don't throw exceptions in case an old method is used. That is, please revert commit 722e745. @goanpeca, you mention above that the purpose of the exceptions is to encourage the users to use the new methods. This may be admirable but I don't think it's necessary. They will notice the old method doesn't exist anymore as soon as they test their code under PyQt5. The exceptions might only notify them earlier but I don't think this is worth the risk of breaking things. |
Included qtpy instead of using a dependency. See spyder-ide/qtpy#65 (comment)
No description provided.