python-webkit2png icon indicating copy to clipboard operation
python-webkit2png copied to clipboard

Support to Qt5.9

Open rgcarrasqueira opened this issue 7 years ago • 4 comments

Hi!

I've made some adjustments to support Qt5.9

rgcarrasqueira avatar Jul 22 '17 22:07 rgcarrasqueira

This fails if both PyQt4 and PyQt4 are available bu only PyQt5.QtWebEngineWidgets is unavailable (I guess it's only available in 5.9?):

> python
Python 2.7.13 (default, Mar 22 2017, 12:31:17) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5.QtCore import *
>>> from PyQt4.QtCore import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: the PyQt4.QtCore and PyQt5.QtCore modules both wrap the QObject class

ghost avatar Jul 24 '17 11:07 ghost

Additionally, QtWebKit is available for PyQt5, too (however, I don't know if it has been marked as deprecated). I would suggest to use find_spec from importlib to validate the dependencies instead of try..except:

if importlib.util.find_spec("PyQt5") is None:
    import PyQt4...
else:
    import PyQt5...
    if importlib.util.find_spec("PyQt5.QtWebEngineWidgets") is None:
        import PyQt5.QtWebKit
    else:
        import PyQt5.QtWebEngine

(Edit: Sorry, using find_spec would break Python 2.x support)

Cybso avatar Jul 24 '17 12:07 Cybso

Yeah! The Problem is the qt developer changed a lot of things on calling some libraries and methods, for example WebPage was changed to WebPageEngine and it messed up everything.

rgcarrasqueira avatar Jul 24 '17 12:07 rgcarrasqueira

The easiest solution would be to move the import of QtWebEngine into the first line and only support QtWebKit for Qt4 and QtWebEngine for Qt5.

Cybso avatar Jul 24 '17 12:07 Cybso