Modified the last implementation to work on Windows as well and made the code more robust against errors. eric7

Sun, 10 Dec 2023 17:49:42 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 10 Dec 2023 17:49:42 +0100
branch
eric7
changeset 10397
f60464a5f7ea
parent 10396
2f72e9330af2
child 10398
ef1ea18994d5

Modified the last implementation to work on Windows as well and made the code more robust against errors.

src/eric7/SystemUtilities/FileSystemUtilities.py file | annotate | diff | comparison | revisions
src/eric7/UI/Browser.py file | annotate | diff | comparison | revisions
--- a/src/eric7/SystemUtilities/FileSystemUtilities.py	Sun Dec 10 17:06:00 2023 +0100
+++ b/src/eric7/SystemUtilities/FileSystemUtilities.py	Sun Dec 10 17:49:42 2023 +0100
@@ -740,18 +740,19 @@
     """
     filePath = str(filePath)
 
-    if OSUtilities.isWindowsPlatform():
-        return os.startfile(filePath)  # secok
-
-    elif OSUtilities.isMacPlatform():
-        return subprocess.call(("open", filePath))  # secok
+    with contextlib.suppress(OSError):
+        if OSUtilities.isWindowsPlatform():
+            os.startfile(filePath)  # secok
+            return True
 
-    elif OSUtilities.isLinuxPlatform() or OSUtilities.isFreeBsdPlatform():
-        return subprocess.call(("xdg-open", filePath))  # secok
+        elif OSUtilities.isMacPlatform():
+            return subprocess.call(("open", filePath)) == 0  # secok
 
-    else:
-        # unsupported platform
-        return False
+        elif OSUtilities.isLinuxPlatform() or OSUtilities.isFreeBsdPlatform():
+            return subprocess.call(("xdg-open", filePath)) == 0  # secok
+
+    # unsupported platform or OSError
+    return False
 
 
 ################################################################################
--- a/src/eric7/UI/Browser.py	Sun Dec 10 17:06:00 2023 +0100
+++ b/src/eric7/UI/Browser.py	Sun Dec 10 17:49:42 2023 +0100
@@ -599,9 +599,20 @@
         )
         for itm in itmList:
             if isinstance(itm, BrowserDirectoryItem):
-                QDesktopServices.openUrl(QUrl(itm.dirName()))
+                directory = itm.dirName()
             else:
-                QDesktopServices.openUrl(QUrl(os.path.dirname(itm.fileName())))
+                directory = os.path.dirname(itm.fileName())
+            ok = FileSystemUtilities.startfile(directory)
+
+            if not ok:
+                EricMessageBox.warning(
+                    self,
+                    self.tr("Show in File Manager"),
+                    self.tr(
+                        "<p>The directory of the selected item (<b>{0}</b>could not be"
+                        " shown in a file manager application.</p>"
+                    ).format(directory),
+                )
 
     def __showMimeType(self):
         """

eric ide

mercurial