加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.py 1.91 KB
一键复制 编辑 原始数据 按行查看 历史
yyt 提交于 2023-12-13 19:56 . 编写Readme
import os
import psutil
import win32clipboard
import win32con
from notifier import notifier
def avoid_duplicate_filename(save_path, filename):
base_filename, extension = os.path.splitext(filename)
counter = 1
while os.path.exists(os.path.join(save_path, filename)):
filename = f"{base_filename} ({counter}){extension}"
counter += 1
return filename
def is_program_running():
program_name = "AirDropPlus.exe"
count: int = 0
for process in psutil.process_iter((['name'])):
if process.info['name'] == program_name:
count += 1
if count >= 2: # 自身也占用一个
return True
return False
def get_clipboard_files():
win32clipboard.OpenClipboard()
try:
file_path_list = win32clipboard.GetClipboardData(win32con.CF_HDROP)
file_path_list = [file for file in file_path_list if os.path.exists(file) and not os.path.isdir(file)]
except Exception as e:
notifier.notify('错误', f'获取文件列表出错: {e}')
file_path_list = ()
finally:
win32clipboard.CloseClipboard()
return file_path_list
def get_clipboard_content():
win32clipboard.OpenClipboard()
text_data = ''
try:
if win32clipboard.IsClipboardFormatAvailable(win32con.CF_UNICODETEXT):
text_data = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)
except Exception as e:
notifier.notify('错误', f'获取剪贴板出错: {e}')
finally:
win32clipboard.CloseClipboard()
return text_data
def set_clipboard_content(text: str):
win32clipboard.OpenClipboard()
try:
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT, text)
except Exception as e:
notifier.notify('错误', f'设置剪贴板出错: {e}')
return False, e
finally:
win32clipboard.CloseClipboard()
return True, None
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化