fix: improve thread handling and cleanup
This commit is contained in:
@@ -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}")
|
||||
|
||||
@@ -60,14 +61,18 @@ class MainWindow:
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user