优化程序
This commit is contained in:
1 parent
68e8eb91a7
commit
6df29c9254
27 files changed
+1974
-203
No files matched your search
+35
-5
@@ -265,6 +265,7 @@ class ItemWidget(QWidget):
|
||||
menu.setStyleSheet(menu_style)
|
||||
|
||||
open_act = menu.addAction(qta.icon("fa5s.play", color="#4a9eff"), "打开")
|
||||
open_folder_act = menu.addAction(qta.icon("fa5s.folder-open", color="#aaa"), "打开文件夹位置")
|
||||
menu.addSeparator()
|
||||
|
||||
item_id = self.item_data.get("id")
|
||||
@@ -291,6 +292,8 @@ class ItemWidget(QWidget):
|
||||
|
||||
if action == open_act:
|
||||
self._launch()
|
||||
elif action == open_folder_act:
|
||||
self._open_folder()
|
||||
elif action == rename_act:
|
||||
self._rename()
|
||||
elif repath_act and action == repath_act:
|
||||
@@ -423,13 +426,40 @@ class ItemWidget(QWidget):
|
||||
except OSError:
|
||||
try:
|
||||
import subprocess
|
||||
creationflags = getattr(subprocess, "CREATE_NO_WINDOW", 0)
|
||||
if sys.platform == "win32":
|
||||
# shell=True 无法直接“运行” .lnk,需交给 start 做关联打开
|
||||
subprocess.Popen(
|
||||
["cmd", "/c", "start", "", path],
|
||||
creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0),
|
||||
)
|
||||
# 尝试直接启动(适用于 .exe / .bat / .cmd)
|
||||
ext = os.path.splitext(path)[1].lower()
|
||||
if ext in (".exe", ".bat", ".cmd"):
|
||||
subprocess.Popen([path], creationflags=creationflags)
|
||||
else:
|
||||
# .lnk / .url 等走 start 关联打开
|
||||
subprocess.Popen(
|
||||
["cmd", "/c", "start", "", path],
|
||||
creationflags=creationflags,
|
||||
)
|
||||
else:
|
||||
subprocess.Popen(["xdg-open", path])
|
||||
except Exception as e:
|
||||
print(f"启动失败: {path!r} -> {e}")
|
||||
|
||||
def _open_folder(self):
|
||||
"""在系统资源管理器中打开文件所在文件夹并选中该文件。"""
|
||||
path = (self.item_data.get("path") or "").strip()
|
||||
if not path:
|
||||
return
|
||||
path = os.path.normpath(path)
|
||||
try:
|
||||
if sys.platform == "win32":
|
||||
# explorer /select,"路径" —— /select,"..." 必须作为一个整体参数
|
||||
import ctypes
|
||||
ctypes.windll.shell32.ShellExecuteW(
|
||||
None, "open", "explorer.exe",
|
||||
'/select,"{}"'.format(path),
|
||||
None, 1, # SW_SHOWNORMAL
|
||||
)
|
||||
else:
|
||||
folder = os.path.dirname(path)
|
||||
subprocess.Popen(["xdg-open", folder])
|
||||
except Exception as e:
|
||||
print(f"打开文件夹失败: {path!r} -> {e}")
|
||||
Reference in new issue
Block a user