main.py 5.5 KB

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