PySide6 preocessing of dropped files/folders locks source Explorer window

38 Views Asked by At

I have implemented Drag and Drop feature for my app that analyzes video files.

When dropping a folder, I show a dialog and then start processing the videos. During that the Explorer window I dragged the folder from is totally unresponsive, I cannot click anything and it doesn't update file changes.

Other explorer windows are working normally.

What is causing that? Im using Python 3.11.4 and PySide6.4.2
This is the code for my drag and drop:

class Analyzer(QMainWindow):
    file_drop_event = Signal(list)
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.file_drop_event.connect(self.file_dropped)
    
    def dragEnterEvent(self, event: QtGui.QDragEnterEvent) -> None:
        if event.mimeData().hasUrls:
            event.accept()
        else:
            event.ignore()

    def dragMoveEvent(self, event):
        if event.mimeData().hasUrls:
            event.setDropAction(Qt.CopyAction)
            event.accept()
        else:
            event.ignore()

    def dropEvent(self, event: QtGui.QDropEvent) -> None:
        if event.mimeData().hasUrls:
            event.setDropAction(Qt.CopyAction)
            event.accept()
            links = []
            for url in event.mimeData().urls():
                links.append(str(url.toLocalFile()))
            self.file_drop_event.emit(links)
        else:
            event.ignore()

    @Slot(list)
    def file_dropped(self, files):
        if len(files) == 1:
            file = Path(files[0])
            if file.is_file():
                logging.info(f"Loading file {str(file)}")
                if file.suffix in [".json", ".csv"]:
                    self.data_control.load_data(file)
                    self.tabWidget.setCurrentIndex(1)
                else:
                    self.videoController.load_video(str(file))
                    self.tabWidget.setCurrentIndex(0)
            elif file.is_dir():
                # function that does not return until everything is processed
                # calls  QApplication.processEvents() regularly
                self.start_batch_process(str(file))
        elif len(files) > 1:
            QMessageBox.critical(self, "Invalid Drop", "Only drop single files or folders!")
        else:
            QMessageBox.critical(self, "Invalid Path", "Dropped file path is invalid!")
0

There are 0 best solutions below