src/eric7/UI/UserInterface.py

branch
eric7
changeset 9624
b47dfa7a137d
parent 9579
7c5d443a2544
child 9653
e67609152c5e
diff -r 9c1f429cb56b -r b47dfa7a137d src/eric7/UI/UserInterface.py
--- a/src/eric7/UI/UserInterface.py	Sun Dec 18 14:19:10 2022 +0100
+++ b/src/eric7/UI/UserInterface.py	Sun Dec 18 19:33:46 2022 +0100
@@ -83,6 +83,13 @@
 from eric7.Project.Project import Project
 from eric7.QScintilla.SpellChecker import SpellChecker
 from eric7.Sessions.SessionFile import SessionFile
+from eric7.SystemUtilities import (
+    DesktopUtilities,
+    FileSystemUtilities,
+    OSUtilities,
+    PythonUtilities,
+    QtUtilities,
+)
 from eric7.Tasks.TasksFile import TasksFile
 from eric7.Testing.TestingWidget import clearSavedHistories
 from eric7.Utilities.BackgroundService import BackgroundService
@@ -1625,7 +1632,7 @@
         # flag indicating '--' options was found
         ddseen = False
 
-        argChars = ["-", "/"] if Utilities.isWindowsPlatform() else ["-"]
+        argChars = ["-", "/"] if OSUtilities.isWindowsPlatform() else ["-"]
 
         for arg in args:
             # handle a request to start with last session
@@ -1810,7 +1817,9 @@
         @param project project name to be displayed (string)
         """
         if editor is not None and self.captionShowsFilename:
-            self.capEditor = Utilities.compactPath(editor, self.maxFilePathLen)
+            self.capEditor = FileSystemUtilities.compactPath(
+                editor, self.maxFilePathLen
+            )
         if project is not None:
             self.capProject = project
 
@@ -2884,16 +2893,17 @@
         self.actions.append(self.testProjectAct)
 
         # check for Qt5 designer and linguist
-        if Utilities.isWindowsPlatform():
+        if OSUtilities.isWindowsPlatform():
             designerExe = os.path.join(
-                Utilities.getQtBinariesPath(),
-                "{0}.exe".format(Utilities.generateQtToolName("designer")),
-            )
-        elif Utilities.isMacPlatform():
-            designerExe = Utilities.getQtMacBundle("designer")
+                QtUtilities.getQtBinariesPath(),
+                "{0}.exe".format(QtUtilities.generateQtToolName("designer")),
+            )
+        elif OSUtilities.isMacPlatform():
+            designerExe = QtUtilities.getQtMacBundle("designer")
         else:
             designerExe = os.path.join(
-                Utilities.getQtBinariesPath(), Utilities.generateQtToolName("designer")
+                QtUtilities.getQtBinariesPath(),
+                QtUtilities.generateQtToolName("designer"),
             )
         if os.path.exists(designerExe):
             self.designer4Act = EricAction(
@@ -2914,16 +2924,17 @@
         else:
             self.designer4Act = None
 
-        if Utilities.isWindowsPlatform():
+        if OSUtilities.isWindowsPlatform():
             linguistExe = os.path.join(
-                Utilities.getQtBinariesPath(),
-                "{0}.exe".format(Utilities.generateQtToolName("linguist")),
-            )
-        elif Utilities.isMacPlatform():
-            linguistExe = Utilities.getQtMacBundle("linguist")
+                QtUtilities.getQtBinariesPath(),
+                "{0}.exe".format(QtUtilities.generateQtToolName("linguist")),
+            )
+        elif OSUtilities.isMacPlatform():
+            linguistExe = QtUtilities.getQtMacBundle("linguist")
         else:
             linguistExe = os.path.join(
-                Utilities.getQtBinariesPath(), Utilities.generateQtToolName("linguist")
+                QtUtilities.getQtBinariesPath(),
+                QtUtilities.generateQtToolName("linguist"),
             )
         if os.path.exists(linguistExe):
             self.linguist4Act = EricAction(
@@ -3709,7 +3720,7 @@
         Private slot to initialize the actions to show the PySide
         documentation.
         """
-        if Utilities.checkPyside(variant=2):
+        if QtUtilities.checkPyside(variant=2):
             self.pyside2DocAct = EricAction(
                 self.tr("PySide2 Documentation"),
                 self.tr("PySide2 Documentation"),
@@ -3735,7 +3746,7 @@
         else:
             self.pyside2DocAct = None
 
-        if Utilities.checkPyside(variant=6):
+        if QtUtilities.checkPyside(variant=6):
             self.pyside6DocAct = EricAction(
                 self.tr("PySide6 Documentation"),
                 self.tr("PySide6 Documentation"),
@@ -3767,7 +3778,7 @@
         """
         self.__menus = {}
         mb = self.menuBar()
-        if Utilities.isLinuxPlatform() and not Preferences.getUI("UseNativeMenuBar"):
+        if OSUtilities.isLinuxPlatform() and not Preferences.getUI("UseNativeMenuBar"):
             mb.setNativeMenuBar(False)
 
         ##############################################################
@@ -4576,8 +4587,8 @@
         )
 
         # desktop and session type
-        desktop = Globals.desktopName()
-        session = Globals.sessionType()
+        desktop = DesktopUtilities.desktopName()
+        session = DesktopUtilities.sessionType()
         if desktop or session:
             versionText += "<tr><td></td><td></td></tr>"
             if desktop:
@@ -4679,7 +4690,7 @@
         from .ErrorLogDialog import ErrorLogDialog
 
         if Preferences.getUI("CheckErrorLog"):
-            logFile = os.path.join(Utilities.getConfigDir(), self.ErrorLogFileName)
+            logFile = os.path.join(Globals.getConfigDir(), self.ErrorLogFileName)
             if os.path.exists(logFile):
                 dlg = ErrorLogDialog(logFile, False, self)
                 dlg.exec()
@@ -4690,7 +4701,7 @@
 
         @return flag indicating the existence of an error log file (boolean)
         """
-        logFile = os.path.join(Utilities.getConfigDir(), self.ErrorLogFileName)
+        logFile = os.path.join(Globals.getConfigDir(), self.ErrorLogFileName)
         return os.path.exists(logFile)
 
     def __showErrorLog(self):
@@ -4699,7 +4710,7 @@
         """
         from .ErrorLogDialog import ErrorLogDialog
 
-        logFile = os.path.join(Utilities.getConfigDir(), self.ErrorLogFileName)
+        logFile = os.path.join(Globals.getConfigDir(), self.ErrorLogFileName)
         if os.path.exists(logFile):
             dlg = ErrorLogDialog(logFile, True, self)
             dlg.show()
@@ -4951,7 +4962,7 @@
 
         if res and self.__shutdown():
             ericApp().closeAllWindows()
-            program = Globals.getPythonExecutable()
+            program = PythonUtilities.getPythonExecutable()
             args = ["-m", "eric7", "--start-session"]
             args.extend(self.__restartArgs)
             QProcess.startDetached(program, args)
@@ -5045,7 +5056,7 @@
         @type str
         """
         ericApp().closeAllWindows()
-        program = Globals.getPythonExecutable()
+        program = PythonUtilities.getPythonExecutable()
         ericStartArgs = ["-m", "eric7", "--start-session"]
         ericStartArgs.extend(self.__restartArgs)
 
@@ -5064,7 +5075,7 @@
         """
         if not Preferences.getUI("SingleApplicationMode"):
             # start eric without loading anything and without crash session
-            program = Globals.getPythonExecutable()
+            program = PythonUtilities.getPythonExecutable()
             eric7 = os.path.join(os.path.dirname(__file__), "..", "eric7_ide.py")
             args = [eric7, "--no-open", "--disable-crash"]
             QProcess.startDetached(program, args)
@@ -5984,13 +5995,14 @@
                 )
                 return
 
-        if Utilities.isMacPlatform():
-            designer, args = Utilities.prepareQtMacBundle("designer", args)
+        if OSUtilities.isMacPlatform():
+            designer, args = QtUtilities.prepareQtMacBundle("designer", args)
         else:
             designer = os.path.join(
-                Utilities.getQtBinariesPath(), Utilities.generateQtToolName("designer")
-            )
-            if Utilities.isWindowsPlatform():
+                QtUtilities.getQtBinariesPath(),
+                QtUtilities.generateQtToolName("designer"),
+            )
+            if OSUtilities.isWindowsPlatform():
                 designer += ".exe"
 
         if designer:
@@ -6051,13 +6063,14 @@
                 )
                 return
 
-        if Utilities.isMacPlatform():
-            linguist, args = Utilities.prepareQtMacBundle("linguist", args)
+        if OSUtilities.isMacPlatform():
+            linguist, args = QtUtilities.prepareQtMacBundle("linguist", args)
         else:
             linguist = os.path.join(
-                Utilities.getQtBinariesPath(), Utilities.generateQtToolName("linguist")
-            )
-            if Utilities.isWindowsPlatform():
+                QtUtilities.getQtBinariesPath(),
+                QtUtilities.generateQtToolName("linguist"),
+            )
+            if OSUtilities.isWindowsPlatform():
                 linguist += ".exe"
 
         if linguist:
@@ -6094,13 +6107,14 @@
             args.append("-showUrl")
             args.append(home)
 
-        if Utilities.isMacPlatform():
-            assistant, args = Utilities.prepareQtMacBundle("assistant", args)
+        if OSUtilities.isMacPlatform():
+            assistant, args = QtUtilities.prepareQtMacBundle("assistant", args)
         else:
             assistant = os.path.join(
-                Utilities.getQtBinariesPath(), Utilities.generateQtToolName("assistant")
-            )
-            if Utilities.isWindowsPlatform():
+                QtUtilities.getQtBinariesPath(),
+                QtUtilities.generateQtToolName("assistant"),
+            )
+            if OSUtilities.isWindowsPlatform():
                 assistant += ".exe"
 
         if assistant:
@@ -6226,7 +6240,7 @@
                 return
 
         if not os.path.isfile(viewer) or not proc.startDetached(
-            Globals.getPythonExecutable(), args
+            PythonUtilities.getPythonExecutable(), args
         ):
             EricMessageBox.critical(
                 self,
@@ -6285,7 +6299,7 @@
                         return
 
         if not os.path.isfile(viewer) or not proc.startDetached(
-            Globals.getPythonExecutable(), args
+            PythonUtilities.getPythonExecutable(), args
         ):
             EricMessageBox.critical(
                 self,
@@ -6308,7 +6322,7 @@
         args.append(browser)
 
         if not os.path.isfile(browser) or not proc.startDetached(
-            Globals.getPythonExecutable(), args
+            PythonUtilities.getPythonExecutable(), args
         ):
             EricMessageBox.critical(
                 self,
@@ -6398,7 +6412,7 @@
         args.append(snap)
 
         if not os.path.isfile(snap) or not proc.startDetached(
-            Globals.getPythonExecutable(), args
+            PythonUtilities.getPythonExecutable(), args
         ):
             EricMessageBox.critical(
                 self,
@@ -6575,7 +6589,7 @@
         """
         pythonDocDir = Preferences.getHelp("PythonDocDir")
         if not pythonDocDir:
-            if Utilities.isWindowsPlatform():
+            if OSUtilities.isWindowsPlatform():
                 venvName = Preferences.getDebugger("Python3VirtualEnv")
                 interpreter = (
                     ericApp()
@@ -6586,18 +6600,18 @@
                     default = os.path.join(os.path.dirname(interpreter), "doc")
                 else:
                     default = ""
-                pythonDocDir = Utilities.getEnvironmentEntry("PYTHON3DOCDIR", default)
+                pythonDocDir = OSUtilities.getEnvironmentEntry("PYTHON3DOCDIR", default)
             else:
-                pythonDocDir = Utilities.getEnvironmentEntry(
+                pythonDocDir = OSUtilities.getEnvironmentEntry(
                     "PYTHON3DOCDIR", "/usr/share/doc/packages/python3/html"
                 )
         if not pythonDocDir.startswith(("http://", "https://", "qthelp://")):
             if pythonDocDir.startswith("file://"):
                 pythonDocDir = pythonDocDir[7:]
             if not os.path.splitext(pythonDocDir)[1]:
-                home = Utilities.normjoinpath(pythonDocDir, "index.html")
-
-                if Utilities.isWindowsPlatform() and not os.path.exists(home):
+                home = FileSystemUtilities.normjoinpath(pythonDocDir, "index.html")
+
+                if OSUtilities.isWindowsPlatform() and not os.path.exists(home):
                     pyversion = sys.hexversion >> 16
                     vers = "{0:d}{1:d}".format(
                         (pyversion >> 8) & 0xFF, pyversion & 0xFF
@@ -6618,8 +6632,8 @@
                 return
 
             if not home.endswith(".chm"):
-                if Utilities.isWindowsPlatform():
-                    home = "file:///" + Utilities.fromNativeSeparators(home)
+                if OSUtilities.isWindowsPlatform():
+                    home = "file:///" + FileSystemUtilities.fromNativeSeparators(home)
                 else:
                     home = "file://" + home
         else:
@@ -6666,7 +6680,7 @@
             if qtDocDir.startswith("file://"):
                 qtDocDir = qtDocDir[7:]
             if not os.path.splitext(qtDocDir)[1]:
-                home = Utilities.normjoinpath(qtDocDir, "index.html")
+                home = FileSystemUtilities.normjoinpath(qtDocDir, "index.html")
             else:
                 home = qtDocDir
 
@@ -6681,8 +6695,8 @@
                 )
                 return
 
-            if Utilities.isWindowsPlatform():
-                home = "file:///" + Utilities.fromNativeSeparators(home)
+            if OSUtilities.isWindowsPlatform():
+                home = "file:///" + FileSystemUtilities.fromNativeSeparators(home)
             else:
                 home = "file://" + home
 
@@ -6710,7 +6724,7 @@
         """
         pyqtDocDir = Preferences.getHelp("PyQt{0}DocDir".format(variant))
         if not pyqtDocDir:
-            pyqtDocDir = Utilities.getEnvironmentEntry(
+            pyqtDocDir = OSUtilities.getEnvironmentEntry(
                 "PYQT{0}DOCDIR".format(variant), None
             )
 
@@ -6732,8 +6746,10 @@
                     pyqtDocDir = pyqtDocDir[7:]
                 if not os.path.splitext(pyqtDocDir)[1]:
                     possibleHomes = [
-                        Utilities.normjoinpath(pyqtDocDir, "index.html"),
-                        Utilities.normjoinpath(pyqtDocDir, "class_reference.html"),
+                        FileSystemUtilities.normjoinpath(pyqtDocDir, "index.html"),
+                        FileSystemUtilities.normjoinpath(
+                            pyqtDocDir, "class_reference.html"
+                        ),
                     ]
                     for possibleHome in possibleHomes:
                         if os.path.exists(possibleHome):
@@ -6753,8 +6769,8 @@
                 )
                 return
 
-            if Utilities.isWindowsPlatform():
-                home = "file:///" + Utilities.fromNativeSeparators(home)
+            if OSUtilities.isWindowsPlatform():
+                home = "file:///" + FileSystemUtilities.fromNativeSeparators(home)
             else:
                 home = "file://" + home
         else:
@@ -6781,7 +6797,7 @@
         """
         home = Preferences.getHelp("EricDocDir")
         if not home:
-            home = Utilities.normjoinpath(
+            home = FileSystemUtilities.normjoinpath(
                 getConfig("ericDocDir"), "Source", "index.html"
             )
 
@@ -6797,8 +6813,8 @@
                 )
                 return
 
-            if Utilities.isWindowsPlatform():
-                home = "file:///" + Utilities.fromNativeSeparators(home)
+            if OSUtilities.isWindowsPlatform():
+                home = "file:///" + FileSystemUtilities.fromNativeSeparators(home)
             else:
                 home = "file://" + home
 
@@ -6826,7 +6842,7 @@
         """
         pysideDocDir = Preferences.getHelp("PySide{0}DocDir".format(variant))
         if not pysideDocDir:
-            pysideDocDir = Utilities.getEnvironmentEntry(
+            pysideDocDir = OSUtilities.getEnvironmentEntry(
                 "PYSIDE{0}DOCDIR".format(variant), None
             )
 
@@ -6845,7 +6861,7 @@
             if pysideDocDir.startswith("file://"):
                 pysideDocDir = pysideDocDir[7:]
             if not os.path.splitext(pysideDocDir)[1]:
-                home = Utilities.normjoinpath(pysideDocDir, "index.html")
+                home = FileSystemUtilities.normjoinpath(pysideDocDir, "index.html")
             else:
                 home = pysideDocDir
             if not os.path.exists(home):
@@ -6859,8 +6875,8 @@
                 )
                 return
 
-            if Utilities.isWindowsPlatform():
-                home = "file:///" + Utilities.fromNativeSeparators(home)
+            if OSUtilities.isWindowsPlatform():
+                home = "file:///" + FileSystemUtilities.fromNativeSeparators(home)
             else:
                 home = "file://" + home
         else:
@@ -6945,7 +6961,7 @@
                     "--name={0}".format(self.__webBrowserSAName),
                     home,
                 ]
-                process.start(Globals.getPythonExecutable(), args)
+                process.start(PythonUtilities.getPythonExecutable(), args)
                 if not process.waitForStarted():
                     EricMessageBox.warning(
                         self,
@@ -7507,20 +7523,20 @@
         """
         Private slot to write the tasks data to a JSON file (.etj).
         """
-        fn = os.path.join(Utilities.getConfigDir(), "eric7tasks.etj")
+        fn = os.path.join(Globals.getConfigDir(), "eric7tasks.etj")
         self.__tasksFile.writeFile(fn)
 
     def __readTasks(self):
         """
         Private slot to read in the tasks file (.etj or .e6t).
         """
-        fn = os.path.join(Utilities.getConfigDir(), "eric7tasks.etj")
+        fn = os.path.join(Globals.getConfigDir(), "eric7tasks.etj")
         if os.path.exists(fn):
             # try new style JSON file first
             self.__tasksFile.readFile(fn)
         else:
             # try old style XML file second
-            fn = os.path.join(Utilities.getConfigDir(), "eric7tasks.e6t")
+            fn = os.path.join(Globals.getConfigDir(), "eric7tasks.e6t")
             if os.path.exists(fn):
                 f = QFile(fn)
                 if f.open(QIODevice.OpenModeFlag.ReadOnly):
@@ -7550,9 +7566,9 @@
         if filename:
             fn = filename
         elif crashSession:
-            fn = os.path.join(Utilities.getConfigDir(), "eric7_crash_session.esj")
+            fn = os.path.join(Globals.getConfigDir(), "eric7_crash_session.esj")
         else:
-            fn = os.path.join(Utilities.getConfigDir(), "eric7session.esj")
+            fn = os.path.join(Globals.getConfigDir(), "eric7session.esj")
 
         return self.__sessionFile.writeFile(fn)
 
@@ -7568,9 +7584,9 @@
         if filename:
             fn = filename
         else:
-            fn = os.path.join(Utilities.getConfigDir(), "eric7session.esj")
+            fn = os.path.join(Globals.getConfigDir(), "eric7session.esj")
             if not os.path.exists(fn):
-                fn = os.path.join(Utilities.getConfigDir(), "eric7session.e5s")
+                fn = os.path.join(Globals.getConfigDir(), "eric7session.e5s")
                 if not os.path.exists(fn):
                     EricMessageBox.critical(
                         self,
@@ -7619,7 +7635,7 @@
         sessionFile, selectedFilter = EricFileDialog.getSaveFileNameAndFilter(
             self,
             self.tr("Save Session"),
-            Utilities.getHomeDir(),
+            OSUtilities.getHomeDir(),
             self.tr("eric Session Files (*.esj)"),
             "",
         )
@@ -7642,7 +7658,7 @@
         sessionFile = EricFileDialog.getOpenFileName(
             self,
             self.tr("Load session"),
-            Utilities.getHomeDir(),
+            OSUtilities.getHomeDir(),
             self.tr("eric Session Files (*.esj);;eric XML Session Files (*.e5s)"),
         )
 
@@ -7656,7 +7672,7 @@
         Private slot to delete the crash session file.
         """
         for ext in (".esj", ".e5s"):
-            fn = os.path.join(Utilities.getConfigDir(), f"eric7_crash_session{ext}")
+            fn = os.path.join(Globals.getConfigDir(), f"eric7_crash_session{ext}")
             if os.path.exists(fn):
                 with contextlib.suppress(OSError):
                     os.remove(fn)
@@ -7685,7 +7701,7 @@
             and not self.__noCrashOpenAtStartup
             and Preferences.getUI("OpenCrashSessionOnStartup")
         ):
-            fn = os.path.join(Utilities.getConfigDir(), "eric7_crash_session.esj")
+            fn = os.path.join(Globals.getConfigDir(), "eric7_crash_session.esj")
             if os.path.exists(fn):
                 yes = EricMessageBox.yesNo(
                     self,
@@ -8312,7 +8328,7 @@
 
         workspace = Preferences.getMultiProject("Workspace")
         if workspace == "":
-            default = Utilities.getHomeDir()
+            default = OSUtilities.getHomeDir()
             workspace = EricFileDialog.getExistingDirectory(
                 None,
                 self.tr("Select Workspace Directory"),

eric ide

mercurial