main.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.startPushButton.clicked.connect(self.on_start_button_click)
  25. # 终止执行
  26. self.endPushButton.clicked.connect(self.on_stop_button_click)
  27. # 编辑账号
  28. # 获取 QLabel 控件并替换为 ClickableLabel
  29. self.accountsLabel = self.findChild(QLabel, "accountsLabel")
  30. if self.accountsLabel:
  31. # 替换为 ClickableLabel
  32. self.clickableAccountsLabel = ClickableLabel(self)
  33. self.clickableAccountsLabel.setObjectName("accountsLabel")
  34. self.clickableAccountsLabel.setText("编辑账号")
  35. self.clickableAccountsLabel.setGeometry(self.accountsLabel.geometry())
  36. self.clickableAccountsLabel.show()
  37. self.accountsLabel.deleteLater() # 删除原来的 QLabel 控件
  38. # 编辑IP代理池
  39. # 获取 QLabel 控件并替换为 ClickableLabel
  40. self.ipPoolLabel = self.findChild(QLabel, "ipPoolLabel")
  41. if self.ipPoolLabel:
  42. # 替换为 ClickableLabel
  43. self.clickableIpPoolLabel = ClickableLabel(self)
  44. self.clickableIpPoolLabel.setObjectName("ipPoolLabel")
  45. self.clickableIpPoolLabel.setText("编辑代理池")
  46. self.clickableIpPoolLabel.setGeometry(self.ipPoolLabel.geometry())
  47. self.clickableIpPoolLabel.show()
  48. self.ipPoolLabel.deleteLater() # 删除原来的 QLabel 控件
  49. # 获取 QDateTimeEdit 控件并设置显示格式
  50. self.startDateTimeEdit = self.findChild(QDateTimeEdit, "startDateTimeEdit")
  51. if self.startDateTimeEdit:
  52. self.startDateTimeEdit.setDisplayFormat("yyyy-MM-dd HH:mm:ss")
  53. # 设置当前时间
  54. self.startDateTimeEdit.setDateTime(QDateTime.currentDateTime())
  55. # 获取 QDateTimeEdit 控件并设置显示格式
  56. self.endDateTimeEdit = self.findChild(QDateTimeEdit, "endDateTimeEdit")
  57. if self.endDateTimeEdit:
  58. self.endDateTimeEdit.setDisplayFormat("yyyy-MM-dd HH:mm:ss")
  59. # 设置当前时间
  60. self.endDateTimeEdit.setDateTime(QDateTime.currentDateTime())
  61. # 连接 watchPushButton 点击事件到槽函数
  62. self.watchPushButton = self.findChild(QPushButton, "watchPushButton")
  63. if self.watchPushButton:
  64. self.watchPushButton.clicked.connect(self.on_watch_button_click)
  65. def on_label_click(self):
  66. options = QFileDialog.Options()
  67. file_name, _ = QFileDialog.getOpenFileName(self, "Open Text File", "", "Text Files (*.txt);;All Files (*)",
  68. options=options)
  69. if file_name:
  70. try:
  71. QDesktopServices.openUrl(QUrl.fromLocalFile(file_name))
  72. except Exception as e:
  73. QMessageBox.critical(self, "Error", f"Could not open file: {e}")
  74. def on_start_button_click(self):
  75. # 在按钮点击时执行的操作
  76. print(f"按钮被点击了!参数1: {self.param1}, 参数2: {self.param2}")
  77. # 获取 QDateTimeEdit 控件的值
  78. if self.startDateTimeEdit:
  79. date_time_value = self.startDateTimeEdit.dateTime()
  80. print(f"选中的日期和时间: {date_time_value.toString('yyyy-MM-dd HH:mm:ss')}")
  81. # 获取 QDateTimeEdit 控件的值
  82. if self.endDateTimeEdit:
  83. date_time_value = self.endDateTimeEdit.dateTime()
  84. print(f"选中的日期和时间: {date_time_value.toString('yyyy-MM-dd HH:mm:ss')}")
  85. # 获取并发数
  86. if self.concurrencyLineEdit:
  87. print(f"并发数为: {self.concurrencyLineEdit.text()}")
  88. # 终止执行
  89. def on_stop_button_click(self):
  90. print(f"终止执行! 目标网址: {self.urlLineEdit.text()}")
  91. def edit_accounts(self):
  92. # 编辑账号
  93. print(f"编辑账号: {self.accountsLabel.show()}")
  94. def on_watch_button_click(self):
  95. # 获取项目当前路径
  96. current_path = sys.path[0]
  97. # 拼接 txt 文件路径
  98. file_path = f"{current_path}/results/2024-05-27.txt"
  99. try:
  100. QDesktopServices.openUrl(QUrl.fromLocalFile(file_path))
  101. except Exception as e:
  102. QMessageBox.critical(self, "Error", f"Could not open file: {e}")
  103. if __name__ == "__main__":
  104. app = QApplication(sys.argv)
  105. # 创建窗口并传递参数
  106. window = MainWindow("Hello", "World")
  107. window.show()
  108. sys.exit(app.exec_())