Add a qt_version_check function to utils.misc.

We're usually only interested in the runtime version, not in the compile-time
version, so we use this rather than comparing to QT_VERSION/PYQT_VERSION.
This commit is contained in:
Florian Bruhin 2014-06-16 10:18:04 +02:00
parent d76226626f
commit 43490202ca
2 changed files with 15 additions and 2 deletions

View File

@ -17,6 +17,8 @@
"""The main browser widgets.""" """The main browser widgets."""
import operator
import sip import sip
from PyQt5.QtCore import QCoreApplication, pyqtSignal, pyqtSlot, PYQT_VERSION from PyQt5.QtCore import QCoreApplication, pyqtSignal, pyqtSlot, PYQT_VERSION
from PyQt5.QtNetwork import QNetworkReply from PyQt5.QtNetwork import QNetworkReply

View File

@ -27,11 +27,12 @@ import re
import sys import sys
import shlex import shlex
import os.path import os.path
import operator
import urllib.request import urllib.request
from urllib.parse import urljoin, urlencode from urllib.parse import urljoin, urlencode
from functools import reduce from functools import reduce
from distutils.version import StrictVersion as Version
from distutils.version import StrictVersion as Version
from PyQt5.QtCore import QCoreApplication, QStandardPaths, QEventLoop, qVersion from PyQt5.QtCore import QCoreApplication, QStandardPaths, QEventLoop, qVersion
from PyQt5.QtGui import QColor from PyQt5.QtGui import QColor
from pkg_resources import resource_string from pkg_resources import resource_string
@ -50,6 +51,16 @@ MINVALS = {
} }
def qt_version_check(version, op=operator.ge):
"""Check if the Qt runtime version is the version supplied or newer.
Args:
version: The version to check against.
op: The operator to use for the check.
"""
return op(Version(qVersion()), Version(version))
def elide(text, length): def elide(text, length):
"""Elide text so it uses a maximum of length chars.""" """Elide text so it uses a maximum of length chars."""
if length < 1: if length < 1:
@ -247,7 +258,7 @@ def actute_warning():
return return
# Qt >= 5.3 doesn't seem to be affected # Qt >= 5.3 doesn't seem to be affected
try: try:
if Version(qVersion()) >= Version('5.3.0'): if qt_version_check('5.3.0'):
return return
except ValueError: except ValueError:
pass pass