示例#1
0
    def __init__(self, *args: int) -> None:
        self._ver = QVersionNumber(args)  # not *args, to support >3 components
        if self._ver.isNull():
            raise ValueError("Can't construct a null version")

        normalized = self._ver.normalized()
        if normalized != self._ver:
            raise ValueError(
                f"Refusing to construct non-normalized version from {args} "
                f"(normalized: {tuple(normalized.segments())}).")

        self.major = self._ver.majorVersion()
        self.minor = self._ver.minorVersion()
        self.patch = self._ver.microVersion()
        self.segments = self._ver.segments()
示例#2
0
    def parse(cls, s: str) -> 'VersionNumber':
        """Parse a version number from a string."""
        ver, _suffix = QVersionNumber.fromString(s)
        # FIXME: Should we support a suffix?

        if ver.isNull():
            raise ValueError(f"Failed to parse {s}")

        return cls(*ver.normalized().segments())
示例#3
0
 def isValid(self):
     if not self._nm.isValid():
         return False
     nm_version = self._get_nm_version()
     if nm_version < QVersionNumber(1, 2):
         logger.warning(
             'NetworkManager version 1.2 or later required, found %s',
             nm_version.toString())
         return False
     return True
示例#4
0
def check_qt_version():
    """Check if the Qt version is recent enough."""
    from PyQt5.QtCore import QT_VERSION, PYQT_VERSION, PYQT_VERSION_STR
    try:
        from PyQt5.QtCore import QVersionNumber, QLibraryInfo
        qt_ver = QLibraryInfo.version().normalized()
        recent_qt_runtime = qt_ver >= QVersionNumber(5, 12)  # type: ignore[operator]
    except (ImportError, AttributeError):
        # QVersionNumber was added in Qt 5.6, QLibraryInfo.version() in 5.8
        recent_qt_runtime = False

    if QT_VERSION < 0x050C00 or PYQT_VERSION < 0x050C00 or not recent_qt_runtime:
        text = ("Fatal error: Qt >= 5.12.0 and PyQt >= 5.12.0 are required, "
                "but Qt {} / PyQt {} is installed.".format(qt_version(),
                                                           PYQT_VERSION_STR))
        _die(text)

    if qt_ver == QVersionNumber(5, 12, 0):
        from qutebrowser.utils import log
        log.init.warning("Running on Qt 5.12.0. Doing so is unsupported "
                         "(newer 5.12.x versions are fine).")
示例#5
0
def check_qt_version():
    """Check if the Qt version is recent enough."""
    from PyQt5.QtCore import QT_VERSION, PYQT_VERSION, PYQT_VERSION_STR
    try:
        from PyQt5.QtCore import QVersionNumber, QLibraryInfo
        qt_ver = QLibraryInfo.version().normalized()
        recent_qt_runtime = qt_ver >= QVersionNumber(5, 12)  # type: ignore[operator]
    except (ImportError, AttributeError):
        # QVersionNumber was added in Qt 5.6, QLibraryInfo.version() in 5.8
        recent_qt_runtime = False

    if QT_VERSION < 0x050C00 or PYQT_VERSION < 0x050C00 or not recent_qt_runtime:
        text = ("Fatal error: Qt >= 5.12.0 and PyQt >= 5.12.0 are required, "
                "but Qt {} / PyQt {} is installed.".format(qt_version(),
                                                           PYQT_VERSION_STR))
        _die(text)
示例#6
0
class VersionNumber:
    """A representation of a version number."""
    def __init__(self, *args: int) -> None:
        self._ver = QVersionNumber(*args)
        if self._ver.isNull():
            raise ValueError("Can't construct a null version")

        normalized = self._ver.normalized()
        if normalized != self._ver:
            raise ValueError(
                f"Refusing to construct non-normalized version from {args} "
                f"(normalized: {tuple(normalized.segments())}).")

        self.major = self._ver.majorVersion()
        self.minor = self._ver.minorVersion()
        self.patch = self._ver.microVersion()
        self.segments = self._ver.segments()

        assert len(self.segments) <= 3, self.segments

    def __str__(self) -> str:
        return ".".join(str(s) for s in self.segments)

    def __repr__(self) -> str:
        args = ", ".join(str(s) for s in self.segments)
        return f'VersionNumber({args})'

    def strip_patch(self) -> 'VersionNumber':
        """Get a new VersionNumber with the patch version removed."""
        return VersionNumber(*self.segments[:2])

    @classmethod
    def parse(cls, s: str) -> 'VersionNumber':
        """Parse a version number from a string."""
        ver, _suffix = QVersionNumber.fromString(s)
        # FIXME: Should we support a suffix?

        if ver.isNull():
            raise ValueError(f"Failed to parse {s}")

        return cls(*ver.normalized().segments())

    def __hash__(self) -> int:
        return hash(self._ver)

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, VersionNumber):
            return NotImplemented
        return self._ver == other._ver

    def __ne__(self, other: object) -> bool:
        if not isinstance(other, VersionNumber):
            return NotImplemented
        return self._ver != other._ver

    def __ge__(self, other: 'VersionNumber') -> bool:
        return self._ver >= other._ver  # type: ignore[operator]

    def __gt__(self, other: 'VersionNumber') -> bool:
        return self._ver > other._ver  # type: ignore[operator]

    def __le__(self, other: 'VersionNumber') -> bool:
        return self._ver <= other._ver  # type: ignore[operator]

    def __lt__(self, other: 'VersionNumber') -> bool:
        return self._ver < other._ver  # type: ignore[operator]
示例#7
0
            print("打开内存失败!!!")
            self.LabRightInfo.setText(u"启动联合仿真失败")
        elif self.ret == -2:
            self.LabRightInfo.setText(u"启动联合仿真失败")
            print("指针指向失败!!!")
        else:
            self.ret = 0
            print("打开共享内存成功!!!")
            self.LabRightInfo.setText(u"已启动联合仿真")
        return self.ret


#  ============窗体测试程序 ================================
if __name__ == "__main__":
    app = 0  # 清除上次运行的残留
    v_compare = QVersionNumber(5, 6, 0)
    v_current, _ = QVersionNumber.fromString(QT_VERSION_STR)  # 获取当前Qt版本
    if QVersionNumber.compare(v_current, v_compare) >= 0:
        QApplication.setAttribute(
            Qt.AA_EnableHighDpiScaling)  # Qt从5.6.0开始,支持High-DPI
        app = QApplication(sys.argv)  #
    else:
        app = QApplication(sys.argv)
        font = QFont("宋体")
        pointSize = font.pointSize()
        font.setPixelSize(pointSize * 90 / 72)
        app.setFont(font)

    splash = SplashPanel()
    app.processEvents()  # 防止进程卡死
示例#8
0
 def _get_nm_version(self):
     version, _suffindex = QVersionNumber.fromString(
         read_dbus_property(self._nm, 'Version'))
     return version
示例#9
0
def parse_version(version: str) -> VersionNumber:
    """Parse a version string."""
    v_q, _suffix = QVersionNumber.fromString(version)
    return cast(VersionNumber, v_q.normalized())