| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- import sys
- from PyQt5.QtCore import Qt, QUrl, QDateTime
- from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QFileDialog, QMessageBox, QDateTimeEdit, QPushButton
- from PyQt5.QtGui import QDesktopServices
- from litter_helper import Ui_menu # 确保这个导入路径是正确的
- class ClickableLabel(QLabel):
- def __init__(self, parent=None):
- super().__init__(parent)
- def mousePressEvent(self, event):
- if event.button() == Qt.LeftButton:
- self.emit_click_event()
- def emit_click_event(self):
- self.parent().on_label_click()
- 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.startPushButton.clicked.connect(self.on_start_button_click)
- # 终止执行
- self.endPushButton.clicked.connect(self.on_stop_button_click)
- # 编辑账号
- # 获取 QLabel 控件并替换为 ClickableLabel
- self.accountsLabel = self.findChild(QLabel, "accountsLabel")
- if self.accountsLabel:
- # 替换为 ClickableLabel
- self.clickableAccountsLabel = ClickableLabel(self)
- 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)
- 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):
- options = QFileDialog.Options()
- file_name, _ = QFileDialog.getOpenFileName(self, "Open Text File", "", "Text Files (*.txt);;All Files (*)",
- options=options)
- if file_name:
- try:
- QDesktopServices.openUrl(QUrl.fromLocalFile(file_name))
- except Exception as e:
- QMessageBox.critical(self, "Error", f"Could not open file: {e}")
- 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')}")
- # 获取并发数
- if self.concurrencyLineEdit:
- print(f"并发数为: {self.concurrencyLineEdit.text()}")
- # 终止执行
- def on_stop_button_click(self):
- print(f"终止执行! 目标网址: {self.urlLineEdit.text()}")
- def edit_accounts(self):
- # 编辑账号
- print(f"编辑账号: {self.accountsLabel.show()}")
- def on_watch_button_click(self):
- # 获取项目当前路径
- current_path = sys.path[0]
- # 拼接 txt 文件路径
- file_path = f"{current_path}/results/2024-05-27.txt"
- try:
- QDesktopServices.openUrl(QUrl.fromLocalFile(file_path))
- except Exception as e:
- QMessageBox.critical(self, "Error", f"Could not open file: {e}")
- if __name__ == "__main__":
- app = QApplication(sys.argv)
- # 创建窗口并传递参数
- window = MainWindow("Hello", "World")
- window.show()
- sys.exit(app.exec_())
|