import ctypes import sys import os import time from datetime import datetime from PyQt5.QtCore import Qt, QUrl, QDateTime from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QFileDialog, QMessageBox, QDateTimeEdit, QPushButton from PyQt5.QtGui import QDesktopServices from app import login_account, run_threading_order, run_daily_job, run_manual_job from litter_helper import Ui_menu # 确保这个导入路径是正确的 from tools.utils import save_all_proxy_ip_v3 class ClickableLabel(QLabel): def __init__(self, parent=None, file_path=None): super().__init__(parent) self.file_path = file_path def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.emit_click_event() def emit_click_event(self): if self.file_path: self.parent().on_label_click(self.file_path) def get_resource_path(relative_path): """获取资源文件的绝对路径""" if getattr(sys, 'frozen', False): # 是否为PyInstaller打包的exe文件 # 返回exe文件所在的绝对路径 base_path = os.path.dirname(sys.executable) else: # 在开发环境下运行 # 返回脚本文件所在的绝对路径 base_path = os.path.dirname(__file__) return os.path.join(base_path, relative_path) class MainWindow(QMainWindow, Ui_menu): def __init__(self, param1, param2): super().__init__() self.setupUi(self) # 使用传递的参数 self.param1 = param1 self.param2 = param2 # 设置标签的文本为传递的参数 # self.label.setText(f"参数1: {self.param1}, 参数2: {self.param2}") self.concurrencyLineEdit.setText("1") self.urlLineEdit.setText("https://t.livepocket.jp/e/l3im7") # 登录账号 self.loginPushButton.clicked.connect(self.on_login_button_click) # 开始下单 self.startPushButton.clicked.connect(self.on_start_button_click) # 终止执行 self.endPushButton.clicked.connect(self.on_stop_button_click) # 定时开始 self.startTimePushButton.clicked.connect(self.on_start_time_button_click) # 编辑账号 # 获取 QLabel 控件并替换为 ClickableLabel self.accountsLabel = self.findChild(QLabel, "accountsLabel") if self.accountsLabel: # 替换为 ClickableLabel self.clickableAccountsLabel = ClickableLabel(self, file_path=get_resource_path("accounts.txt")) self.clickableAccountsLabel.setObjectName("accountsLabel") self.clickableAccountsLabel.setText("编辑账号") self.clickableAccountsLabel.setGeometry(self.accountsLabel.geometry()) self.clickableAccountsLabel.show() self.accountsLabel.deleteLater() # 删除原来的 QLabel 控件 # 编辑IP代理池 # 获取 QLabel 控件并替换为 ClickableLabel self.ipPoolLabel = self.findChild(QLabel, "ipPoolLabel") if self.ipPoolLabel: # 替换为 ClickableLabel self.clickableIpPoolLabel = ClickableLabel(self, file_path=get_resource_path("proxy_list.txt")) self.clickableIpPoolLabel.setObjectName("ipPoolLabel") self.clickableIpPoolLabel.setText("编辑代理池") self.clickableIpPoolLabel.setGeometry(self.ipPoolLabel.geometry()) self.clickableIpPoolLabel.show() self.ipPoolLabel.deleteLater() # 删除原来的 QLabel 控件 # 获取 QDateTimeEdit 控件并设置显示格式 self.startDateTimeEdit = self.findChild(QDateTimeEdit, "startDateTimeEdit") if self.startDateTimeEdit: self.startDateTimeEdit.setDisplayFormat("yyyy-MM-dd HH:mm:ss") # 设置当前时间 self.startDateTimeEdit.setDateTime(QDateTime.currentDateTime()) # 获取 QDateTimeEdit 控件并设置显示格式 self.endDateTimeEdit = self.findChild(QDateTimeEdit, "endDateTimeEdit") if self.endDateTimeEdit: self.endDateTimeEdit.setDisplayFormat("yyyy-MM-dd HH:mm:ss") # 设置当前时间 self.endDateTimeEdit.setDateTime(QDateTime.currentDateTime()) # 连接 watchPushButton 点击事件到槽函数 self.watchPushButton = self.findChild(QPushButton, "watchPushButton") if self.watchPushButton: self.watchPushButton.clicked.connect(self.on_watch_button_click) def on_label_click(self, file_path): if os.path.exists(file_path): try: QDesktopServices.openUrl(QUrl.fromLocalFile(file_path)) except Exception as e: QMessageBox.critical(self, "Error", f"无法打开文件: {e}") else: QMessageBox.critical(self, "Error", f"文件不存在: {file_path}") def on_start_button_click(self): # 在按钮点击时执行的操作 print(f"按钮被点击了!参数1: {self.param1}, 参数2: {self.param2}") # 获取 QDateTimeEdit 控件的值 if self.startDateTimeEdit: date_time_value = self.startDateTimeEdit.dateTime() print(f"选中的日期和时间: {date_time_value.toString('yyyy-MM-dd HH:mm:ss')}") # 获取 QDateTimeEdit 控件的值 if self.endDateTimeEdit: date_time_value = self.endDateTimeEdit.dateTime() print(f"选中的日期和时间: {date_time_value.toString('yyyy-MM-dd HH:mm:ss')}") # 获取并发数 thread_num = 1 if self.concurrencyLineEdit: print(f"并发数为: {self.concurrencyLineEdit.text()}") thread_num = self.concurrencyLineEdit.text() # url net_url = None if self.urlLineEdit: net_url = self.urlLineEdit.text() # 下单 run_threading_order(thread_num, get_resource_path("accounts.txt"), net_url) # 登录账号 def on_login_button_click(self): print(f"登录账号! {self.urlLineEdit.text()}") thread_num = 1 if self.concurrencyLineEdit.text(): thread_num = self.concurrencyLineEdit.text() pocket_url = None if self.urlLineEdit.text(): pocket_url = self.urlLineEdit.text() save_all_proxy_ip_v3(get_resource_path("proxy_list.txt")) login_account(thread_num, get_resource_path("accounts.txt"), pocket_url) else: QMessageBox.warning(self, '警告', '请输入URL') return # 定时开始 def on_start_time_button_click(self): print(f"定时开始:{time.time()}") net_url = None if self.urlLineEdit: net_url = self.urlLineEdit.text() start_time = self.startDateTimeEdit.text() print(f"start_time:{start_time}") # 使用datetime模块解析时间字符串 dt = datetime.strptime(start_time, '%Y-%m-%d %H:%M:%S') # 提取出时、分、秒 hour = dt.hour minute = dt.minute second = dt.second print(f"Hour: {hour}, Minute: {minute}, Second: {second}") run_manual_job(hour, minute, net_url) else: QMessageBox.warning(self, '警告', '请输入URL') return # 终止下单 def on_stop_button_click(self): print(f"终止下单! 目标网址: {self.urlLineEdit.text()}") def edit_accounts(self): # 编辑账号 print(f"编辑账号: {self.urlLineEdit.text()}") def on_watch_button_click(self): # 获取项目当前路径 current_path = sys.path[0] # 拼接 txt 文件路径 file_path = get_resource_path("results/2024-05-27.txt") try: QDesktopServices.openUrl(QUrl.fromLocalFile(file_path)) except Exception as e: QMessageBox.critical(self, "Error", f"无法打开文件: {e}") if __name__ == "__main__": app = QApplication(sys.argv) # 创建窗口并传递参数 window = MainWindow("Hello", "World") window.show() sys.exit(app.exec_())