def dropEvent(self, e: QDropEvent): if e.dropAction() != Qt.CopyAction: e.ignore() e.acceptProposedAction() self.stopAnimation() files = [url.toLocalFile() for url in e.mimeData().urls()] self._dragInProgress = False self.update() self.filesDropped.emit(files)
def dropEvent(self, a0: QDropEvent) -> None: data = a0.mimeData() action = a0.dropAction() if action == Qt.IgnoreAction: a0.ignore() return if not data.hasFormat('text/uri-list'): a0.ignore() return a0.accept() self.setCursor(Qt.WaitCursor) self.model.clear() QCoreApplication.processEvents() ul = data.data('text/uri-list').data().decode().splitlines() ul = map(str.strip, ul) ul = filter(lambda _uri: not _uri.startswith('#'), ul) ul = [ 'file:/' + _uri[len('file:///'):] if _uri.startswith('file:///') else _uri for _uri in ul ] ul = list(ul) file_binds = [] dir_binds = [] # Ingest file and dirs from received uri-list for uri in ul: if uri.startswith('file:'): pathname = url2pathname(uri[len('file:'):]) if os.path.isdir(pathname): self._logger.info(f'RECURSIVELY ADDING {pathname}') out = self._py_db.ingest_file_directory(pathname) dir_binds.append(f'{uri}%') self._logger.debug( f'ingest_file_directory({pathname}) -> {out}') continue self._logger.info(f'ADDING {uri}') media_id, flags, ex = self._py_db.try_ingest_url(uri) if ex is not None: self._logger.exception(f'FAILING {uri}: {ex}') else: file_binds.append(uri) self._logger.debug(f'{media_id=} {flags=} {ex=}') self._py_db.notify_bg_manifold_build() self._py_db.thumbs_load() # Build WHERE expression with file and dir binds conditions = [] file_placeholders = ', '.join('?' * len(file_binds)) if file_placeholders: file_placeholders = f'url IN ({file_placeholders})' conditions.append(file_placeholders) conditions.extend(['url LIKE ?'] * len(dir_binds)) # Prepare query and bind values for file and dirs query = QSqlQuery() query.prepare( f'SELECT media_id FROM MediaLocations WHERE {" OR ".join(conditions)} ORDER BY url' ) i = -1 for i, bind in enumerate(file_binds): query.bindValue(i, bind) for j, bind in zip(range(i + 1, i + 1 + len(dir_binds)), dir_binds): query.bindValue(j, bind) query.exec() if not query.isActive(): self._logger.debug(f'results query: {query.lastQuery():s}') self._logger.error( f'results query error: {query.lastError().text():s}') self.model.setQuery(query) self.setCursor(Qt.ArrowCursor)