main.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import sys
  2. import os
  3. from PyQt5.QtCore import Qt, QUrl, QDateTime
  4. from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QFileDialog, QMessageBox, QDateTimeEdit, QPushButton
  5. from PyQt5.QtGui import QDesktopServices
  6. from litter_helper import Ui_menu # 确保这个导入路径是正确的
  7. class ClickableLabel(QLabel):
  8. def __init__(self, parent=None, file_path=None):
  9. super().__init__(parent)
  10. self.file_path = file_path
  11. def mousePressEvent(self, event):
  12. if event.button() == Qt.LeftButton:
  13. self.emit_click_event()
  14. def emit_click_event(self):
  15. if self.file_path:
  16. self.parent().on_label_click(self.file_path)
  17. def get_resource_path(relative_path):
  18. """获取资源文件的绝对路径"""
  19. if getattr(sys, 'frozen', False): # 是否为PyInstaller打包的exe文件
  20. # 返回exe文件所在的绝对路径
  21. base_path = os.path.dirname(sys.executable)
  22. else: # 在开发环境下运行
  23. # 返回脚本文件所在的绝对路径
  24. base_path = os.path.dirname(__file__)
  25. return os.path.join(base_path, relative_path)
  26. class MainWindow(QMainWindow, Ui_menu):
  27. def __init__(self, param1, param2):
  28. super().__init__()
  29. self.setupUi(self)
  30. # 使用传递的参数
  31. self.param1 = param1
  32. self.param2 = param2
  33. # 设置标签的文本为传递的参数
  34. # self.label.setText(f"参数1: {self.param1}, 参数2: {self.param2}")
  35. # 登录账号
  36. self.loginPushButton.clicked.connect(self.on_login_button_click)
  37. # 开始下单
  38. self.startPushButton.clicked.connect(self.on_start_button_click)
  39. # 终止执行
  40. self.endPushButton.clicked.connect(self.on_stop_button_click)
  41. # 编辑账号
  42. # 获取 QLabel 控件并替换为 ClickableLabel
  43. self.accountsLabel = self.findChild(QLabel, "accountsLabel")
  44. if self.accountsLabel:
  45. # 替换为 ClickableLabel
  46. self.clickableAccountsLabel = ClickableLabel(self, file_path=get_resource_path("accounts.txt"))
  47. self.clickableAccountsLabel.setObjectName("accountsLabel")
  48. self.clickableAccountsLabel.setText("编辑账号")
  49. self.clickableAccountsLabel.setGeometry(self.accountsLabel.geometry())
  50. self.clickableAccountsLabel.show()
  51. self.accountsLabel.deleteLater() # 删除原来的 QLabel 控件
  52. # 编辑IP代理池
  53. # 获取 QLabel 控件并替换为 ClickableLabel
  54. self.ipPoolLabel = self.findChild(QLabel, "ipPoolLabel")
  55. if self.ipPoolLabel:
  56. # 替换为 ClickableLabel
  57. self.clickableIpPoolLabel = ClickableLabel(self, file_path=get_resource_path("proxy_list.txt"))
  58. self.clickableIpPoolLabel.setObjectName("ipPoolLabel")
  59. self.clickableIpPoolLabel.setText("编辑代理池")
  60. self.clickableIpPoolLabel.setGeometry(self.ipPoolLabel.geometry())
  61. self.clickableIpPoolLabel.show()
  62. self.ipPoolLabel.deleteLater() # 删除原来的 QLabel 控件
  63. # 获取 QDateTimeEdit 控件并设置显示格式
  64. self.startDateTimeEdit = self.findChild(QDateTimeEdit, "startDateTimeEdit")
  65. if self.startDateTimeEdit:
  66. self.startDateTimeEdit.setDisplayFormat("yyyy-MM-dd HH:mm:ss")
  67. # 设置当前时间
  68. self.startDateTimeEdit.setDateTime(QDateTime.currentDateTime())
  69. # 获取 QDateTimeEdit 控件并设置显示格式
  70. self.endDateTimeEdit = self.findChild(QDateTimeEdit, "endDateTimeEdit")
  71. if self.endDateTimeEdit:
  72. self.endDateTimeEdit.setDisplayFormat("yyyy-MM-dd HH:mm:ss")
  73. # 设置当前时间
  74. self.endDateTimeEdit.setDateTime(QDateTime.currentDateTime())
  75. # 连接 watchPushButton 点击事件到槽函数
  76. self.watchPushButton = self.findChild(QPushButton, "watchPushButton")
  77. if self.watchPushButton:
  78. self.watchPushButton.clicked.connect(self.on_watch_button_click)
  79. def on_label_click(self, file_path):
  80. if os.path.exists(file_path):
  81. try:
  82. QDesktopServices.openUrl(QUrl.fromLocalFile(file_path))
  83. except Exception as e:
  84. QMessageBox.critical(self, "Error", f"无法打开文件: {e}")
  85. else:
  86. QMessageBox.critical(self, "Error", f"文件不存在: {file_path}")
  87. def on_start_button_click(self):
  88. # 在按钮点击时执行的操作
  89. print(f"按钮被点击了!参数1: {self.param1}, 参数2: {self.param2}")
  90. # 获取 QDateTimeEdit 控件的值
  91. if self.startDateTimeEdit:
  92. date_time_value = self.startDateTimeEdit.dateTime()
  93. print(f"选中的日期和时间: {date_time_value.toString('yyyy-MM-dd HH:mm:ss')}")
  94. # 获取 QDateTimeEdit 控件的值
  95. if self.endDateTimeEdit:
  96. date_time_value = self.endDateTimeEdit.dateTime()
  97. print(f"选中的日期和时间: {date_time_value.toString('yyyy-MM-dd HH:mm:ss')}")
  98. # 获取并发数
  99. if self.concurrencyLineEdit:
  100. print(f"并发数为: {self.concurrencyLineEdit.text()}")
  101. # 登录账号
  102. def on_login_button_click(self):
  103. print(f"登录账号! {self.urlLineEdit.text()}")
  104. # 终止下单
  105. def on_stop_button_click(self):
  106. print(f"终止下单! 目标网址: {self.urlLineEdit.text()}")
  107. def edit_accounts(self):
  108. # 编辑账号
  109. print(f"编辑账号: {self.urlLineEdit.text()}")
  110. def on_watch_button_click(self):
  111. # 获取项目当前路径
  112. current_path = sys.path[0]
  113. # 拼接 txt 文件路径
  114. file_path = f"{current_path}/results/2024-05-27.txt"
  115. try:
  116. QDesktopServices.openUrl(QUrl.fromLocalFile(file_path))
  117. except Exception as e:
  118. QMessageBox.critical(self, "Error", f"无法打开文件: {e}")
  119. if __name__ == "__main__":
  120. app = QApplication(sys.argv)
  121. # 创建窗口并传递参数
  122. window = MainWindow("Hello", "World")
  123. window.show()
  124. sys.exit(app.exec_())