From ea896cc88f5be6c0250892a8c11881e5037ebd0c Mon Sep 17 00:00:00 2001 From: OpenCode Bot Date: Sun, 24 May 2026 22:59:26 +0800 Subject: [PATCH] fix: improve thread handling and cleanup --- temp_file_trans_client/main.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/temp_file_trans_client/main.py b/temp_file_trans_client/main.py index 36bfa90..38750d7 100644 --- a/temp_file_trans_client/main.py +++ b/temp_file_trans_client/main.py @@ -1,4 +1,5 @@ import sys +import os from PySide6.QtWidgets import QApplication, QMessageBox, QMainWindow from PySide6.QtCore import QThread, Signal from ui import UiCreator @@ -51,7 +52,7 @@ class MainWindow: def on_file_selected(self, filepath): self.selected_file = filepath - filename = filepath.split('/')[-1] if '/' in filepath else filepath.split('\\')[-1] + filename = os.path.basename(filepath) self.window.drop_label.setText(f"已选择: {filename}") self.window.status_label.setText(f"状态: 已选择文件: {filename}") @@ -59,15 +60,19 @@ class MainWindow: if not self.selected_file: self.window.status_label.setText("状态: 请先选择文件") return - + + if self.upload_thread is not None and self.upload_thread.isRunning(): + self.window.status_label.setText("状态: 上传进行中,请等待") + return + expiry = self.window.expiry_combo.currentText() self.window.progress_bar.setVisible(True) - self.window.progress_bar.setValue(30) self.window.upload_btn.setEnabled(False) self.window.status_label.setText("状态: 上传中...") - + self.upload_thread = UploadThread(self.selected_file, expiry, self.server_url) self.upload_thread.finished.connect(self.on_upload_success) + self.upload_thread.finished.connect(self.upload_thread.deleteLater) self.upload_thread.error.connect(self.on_upload_error) self.upload_thread.progress.connect(self.window.progress_bar.setValue) self.upload_thread.start()