diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/Globals/__init__.py --- a/src/eric7/Globals/__init__.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Globals/__init__.py Wed Jul 13 14:55:47 2022 +0200 @@ -17,7 +17,12 @@ import sys from PyQt6.QtCore import ( - QDir, QByteArray, QCoreApplication, QT_VERSION, QProcess, qVersion + QDir, + QByteArray, + QCoreApplication, + QT_VERSION, + QProcess, + qVersion, ) from eric7config import getConfig @@ -47,7 +52,7 @@ def isWindowsPlatform(): """ Function to check, if this is a Windows platform. - + @return flag indicating Windows platform @rtype bool """ @@ -57,7 +62,7 @@ def isMacPlatform(): """ Function to check, if this is a Mac platform. - + @return flag indicating Mac platform @rtype bool """ @@ -67,7 +72,7 @@ def isLinuxPlatform(): """ Function to check, if this is a Linux platform. - + @return flag indicating Linux platform @rtype bool """ @@ -78,122 +83,122 @@ """ Function to determine the name of the desktop environment used (Linux only). - + @return name of the desktop environment @rtype str """ if not isLinuxPlatform(): return "" - + currDesktop = os.environ.get("XDG_CURRENT_DESKTOP", "") if currDesktop: return currDesktop - + currDesktop = os.environ.get("XDG_SESSION_DESKTOP", "") if currDesktop: return currDesktop - + currDesktop = os.environ.get("GDMSESSION", "") if currDesktop: return currDesktop - + currDesktop = os.environ.get("GNOME_DESKTOP_SESSION_ID", "") if currDesktop: return currDesktop - + currDesktop = os.environ.get("KDE_FULL_SESSION", "") if currDesktop: if currDesktop == "true": return "KDE" - + return currDesktop - + currDesktop = os.environ.get("DESKTOP_SESSION", "") if currDesktop: return currDesktop - + return "" def isKdeDesktop(): """ Function to check, if the current session is a KDE desktop (Linux only). - + @return flag indicating a KDE desktop @rtype bool """ if not isLinuxPlatform(): return False - + isKDE = False - + desktop = ( - os.environ.get("XDG_CURRENT_DESKTOP", "").lower() or - os.environ.get("XDG_SESSION_DESKTOP", "").lower() or - os.environ.get("DESKTOP_SESSION", "").lower() + os.environ.get("XDG_CURRENT_DESKTOP", "").lower() + or os.environ.get("XDG_SESSION_DESKTOP", "").lower() + or os.environ.get("DESKTOP_SESSION", "").lower() ) isKDE = ( "kde" in desktop or "plasma" in desktop - if desktop else - bool(os.environ.get("KDE_FULL_SESSION", "")) + if desktop + else bool(os.environ.get("KDE_FULL_SESSION", "")) ) - + return isKDE def isGnomeDesktop(): """ Function to check, if the current session is a Gnome desktop (Linux only). - + @return flag indicating a Gnome desktop @rtype bool """ if not isLinuxPlatform(): return False - + isGnome = False - + desktop = ( - os.environ.get("XDG_CURRENT_DESKTOP", "").lower() or - os.environ.get("XDG_SESSION_DESKTOP", "").lower() or - os.environ.get("GDMSESSION", "").lower() + os.environ.get("XDG_CURRENT_DESKTOP", "").lower() + or os.environ.get("XDG_SESSION_DESKTOP", "").lower() + or os.environ.get("GDMSESSION", "").lower() ) isGnome = ( "gnome" in desktop - if desktop else - bool(os.environ.get("GNOME_DESKTOP_SESSION_ID", "")) + if desktop + else bool(os.environ.get("GNOME_DESKTOP_SESSION_ID", "")) ) - + return isGnome def sessionType(): """ Function to determine the name of the running session (Linux only). - + @return name of the desktop environment @rtype str """ if not isLinuxPlatform(): return "" - + sessionType = os.environ.get("XDG_SESSION_TYPE", "").lower() if "x11" in sessionType: return "X11" elif "wayland" in sessionType: return "Wayland" - + sessionType = os.environ.get("WAYLAND_DISPLAY", "").lower() if "wayland" in sessionType: return "Wayland" - + return "" def isWaylandSession(): """ Function to check, if the current session is a wayland session. - + @return flag indicating a wayland session @rtype bool """ @@ -203,7 +208,7 @@ def getConfigDir(): """ Module function to get the name of the directory storing the config data. - + @return directory name of the config dir @rtype str """ @@ -220,7 +225,7 @@ def getInstallInfoFilePath(): """ Public method to get the path name of the install info file. - + @return file path of the install info file @rtype str """ @@ -238,7 +243,7 @@ def setConfigDir(d): """ Module function to set the name of the directory storing the config data. - + @param d name of an existing directory @type str """ @@ -249,7 +254,7 @@ def getPythonExecutable(): """ Function to determine the path of the (non-windowed) Python executable. - + @return path of the Python executable @rtype str """ @@ -264,49 +269,50 @@ def getPythonLibraryDirectory(): """ Function to determine the path to Python's library directory. - + @return path to the Python library directory @rtype str """ import sysconfig - return sysconfig.get_path('platlib') + + return sysconfig.get_path("platlib") def getPyQt6ModulesDirectory(): """ Function to determine the path to PyQt6 modules directory. - + @return path to the PyQt6 modules directory @rtype str """ import sysconfig - - pyqtPath = os.path.join(sysconfig.get_path('platlib'), "PyQt6") + + pyqtPath = os.path.join(sysconfig.get_path("platlib"), "PyQt6") if os.path.exists(pyqtPath): return pyqtPath - + return "" - + def getPyQtToolsPath(version=5): """ Module function to get the path of the PyQt tools. - + @param version PyQt major version @type int @return path to the PyQt tools @rtype str """ import Preferences - + toolsPath = "" - + # step 1: check, if the user has configured a tools path if version == 5: toolsPath = Preferences.getQt("PyQtToolsDir") elif version == 6: toolsPath = Preferences.getQt("PyQt6ToolsDir") - + # step 2: determine from used Python interpreter (pylupdate is test object) if not toolsPath: program = "pylupdate{0}".format(version) @@ -321,14 +327,14 @@ dirName = os.path.dirname(sys.executable) if os.path.exists(os.path.join(dirName, program)): toolsPath = dirName - + return toolsPath def getQtBinariesPath(libexec=False): """ Module function to get the path of the Qt binaries. - + @param libexec flag indicating to get the path of the executable library (defaults to False) @type bool (optional) @@ -336,9 +342,9 @@ @rtype str """ import Preferences - + binPath = "" - + # step 1: check, if the user has configured a tools path qtToolsDir = Preferences.getQt("QtToolsDir") if qtToolsDir: @@ -350,27 +356,28 @@ binPath = Preferences.getQt("QtToolsDir") if not os.path.exists(binPath): binPath = "" - + # step 2: try the qt6_applications package if not binPath: with contextlib.suppress(ImportError): # if qt6-applications is not installed just go to the next step import qt6_applications + if libexec: binPath = os.path.join( - os.path.dirname(qt6_applications.__file__), - "Qt", "libexec") + os.path.dirname(qt6_applications.__file__), "Qt", "libexec" + ) if not os.path.exists(binPath): binPath = os.path.join( - os.path.dirname(qt6_applications.__file__), - "Qt", "bin") + os.path.dirname(qt6_applications.__file__), "Qt", "bin" + ) else: binPath = os.path.join( - os.path.dirname(qt6_applications.__file__), - "Qt", "bin") + os.path.dirname(qt6_applications.__file__), "Qt", "bin" + ) if not os.path.exists(binPath): binPath = "" - + # step 3: determine from used Python interpreter (designer is test object) if not binPath: program = "designer" @@ -385,7 +392,7 @@ dirName = os.path.dirname(sys.executable) if os.path.exists(os.path.join(dirName, program)): binPath = dirName - + return QDir.toNativeSeparators(binPath) @@ -397,11 +404,11 @@ def versionToTuple(version, length=3): """ Module function to convert a version string into a tuple. - + Note: A version string consists of non-negative decimals separated by "." optionally followed by a suffix. Suffix is everything after the last decimal. - + @param version version string @type str @param length desired length of the version tuple @@ -410,28 +417,28 @@ @rtype tuple of int """ versionParts = [] - + # step 1: extract suffix version = re.split(r"[^\d.]", version)[0] for part in version.split("."): with contextlib.suppress(ValueError): versionParts.append(int(part.strip())) versionParts.extend([0] * length) - + return tuple(versionParts[:length]) def qVersionTuple(): """ Module function to get the Qt version as a tuple. - + @return Qt version as a tuple @rtype tuple of int """ return ( - (QT_VERSION & 0xff0000) >> 16, - (QT_VERSION & 0xff00) >> 8, - QT_VERSION & 0xff, + (QT_VERSION & 0xFF0000) >> 16, + (QT_VERSION & 0xFF00) >> 8, + QT_VERSION & 0xFF, ) @@ -444,7 +451,7 @@ """ Module function to group a string into sub-strings separated by a separator. - + @param txt text to be grouped @type str @param sep separator string @@ -455,7 +462,7 @@ @rtype str """ groups = [] - + while len(txt) // groupLen != 0: groups.insert(0, txt[-groupLen:]) txt = txt[:-groupLen] @@ -467,7 +474,7 @@ def strToQByteArray(txt): """ Module function to convert a Python string into a QByteArray. - + @param txt Python string to be converted @type str, bytes, bytearray @return converted QByteArray @@ -475,38 +482,33 @@ """ if isinstance(txt, str): txt = txt.encode("utf-8") - + return QByteArray(txt) def dataString(size): """ Module function to generate a formatted size string. - + @param size size to be formatted @type int @return formatted data string @rtype str """ if size < 1024: - return QCoreApplication.translate( - "Globals", "{0:4.2f} Bytes").format(size) + return QCoreApplication.translate("Globals", "{0:4.2f} Bytes").format(size) elif size < 1024 * 1024: size /= 1024 - return QCoreApplication.translate( - "Globals", "{0:4.2f} KiB").format(size) + return QCoreApplication.translate("Globals", "{0:4.2f} KiB").format(size) elif size < 1024 * 1024 * 1024: size /= 1024 * 1024 - return QCoreApplication.translate( - "Globals", "{0:4.2f} MiB").format(size) + return QCoreApplication.translate("Globals", "{0:4.2f} MiB").format(size) elif size < 1024 * 1024 * 1024 * 1024: size /= 1024 * 1024 * 1024 - return QCoreApplication.translate( - "Globals", "{0:4.2f} GiB").format(size) + return QCoreApplication.translate("Globals", "{0:4.2f} GiB").format(size) else: size /= 1024 * 1024 * 1024 * 1024 - return QCoreApplication.translate( - "Globals", "{0:4.2f} TiB").format(size) + return QCoreApplication.translate("Globals", "{0:4.2f} TiB").format(size) ############################################################################### @@ -517,7 +519,7 @@ def toBool(value): """ Module function to convert a value to bool. - + @param value value to be converted @type str @return converted data @@ -534,7 +536,7 @@ def toList(value): """ Module function to convert a value to a list. - + @param value value to be converted @type None, list or Any @return converted data @@ -551,7 +553,7 @@ def toByteArray(value): """ Module function to convert a value to a byte array. - + @param value value to be converted @type QByteArray or None @return converted data @@ -566,7 +568,7 @@ def toDict(value): """ Module function to convert a value to a dictionary. - + @param value value to be converted @type dict or None @return converted data @@ -586,21 +588,23 @@ def getWebBrowserSupport(): """ Module function to determine the supported web browser variant. - + @return string indicating the supported web browser variant ("QtWebEngine", or "None") @rtype str """ from eric7config import getConfig - scriptPath = os.path.join(getConfig("ericDir"), "Tools", - "webBrowserSupport.py") + + scriptPath = os.path.join(getConfig("ericDir"), "Tools", "webBrowserSupport.py") proc = QProcess() proc.start(getPythonExecutable(), [scriptPath, qVersion()]) variant = ( - str(proc.readAllStandardOutput(), "utf-8", 'replace').strip() - if proc.waitForFinished(10000) else - "None" + str(proc.readAllStandardOutput(), "utf-8", "replace").strip() + if proc.waitForFinished(10000) + else "None" ) return variant + + # # eflag: noqa = M801