Open hamad-gamal opened 9 months ago
enable multi-file selection, we'll need to implement the following steps:
Given the content of files.py
, I'll provide code snippets to achieve the above steps:
You can add a button to the toolbar or a menu action. For simplicity, let's add a menu action:
file_selection_action = QAction('Select Multiple Files', self)
file_selection_action.triggered.connect(self.select_multiple_files)
self.file_menu.addAction(file_selection_action)
We'll create a method called select_multiple_files
:
def select_multiple_files(self):
file_names, _ = QFileDialog.getOpenFileNames(self, 'Select Files')
if file_names:
self.handle_selected_files(file_names)
Here, QFileDialog.getOpenFileNames
returns a tuple where the first element is a list of selected file paths.
Finally, implement the handle_selected_files
method to process the selected files:
def handle_selected_files(self, file_names: list):
# Implement your logic here
# For now, let's just print the selected files
print("Selected files:", file_names)
files.py
will enable multi-file selection in the GUI.please check if this working or not
`# ADB File Explorer
Copyright (C) 2
file_selection_action = QAction('Select Multiple Files', self) file_selection_action.triggered.connect(self.select_multiple_files) self.file_menu.addAction(file_selection_action) 022 Azat Aldeshov import sys from typing import Any
from PyQt5 import QtCore, QtGui from PyQt5.QtCore import Qt, QPoint, QModelIndex, QAbstractListModel, QVariant, QRect, QSize, QEvent, QObject from PyQt5.QtGui import QPixmap, QColor, QPalette, QMovie, QKeySequence from PyQt5.QtWidgets import QMenu, QAction, QMessageBox, QFileDialog, QStyle, QWidget, QStyledItemDelegate, \ QStyleOptionViewItem, QApplication, QListView, QVBoxLayout, QLabel, QSizePolicy, QHBoxLayout, QTextEdit, \ QMainWindow
from app.core.configurations import Resources from app.core.main import Adb from app.core.managers import Global from app.data.models import FileType, MessageData, MessageType from app.data.repositories import FileRepository from app.gui.explorer.toolbar import ParentButton, UploadTools, PathBar from app.helpers.tools import AsyncRepositoryWorker, ProgressCallbackHelper, read_string_from_file
class FileHeaderWidget(QWidget): def init(self, parent=None): super(FileHeaderWidget, self).init(parent) self.setLayout(QHBoxLayout(self)) policy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred)
class FileExplorerToolbar(QWidget): def init(self, parent=None): super(FileExplorerToolbar, self).init(parent) self.setLayout(QHBoxLayout(self)) policy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred) policy.setHorizontalStretch(1)
class FileItemDelegate(QStyledItemDelegate): def sizeHint(self, option: 'QStyleOptionViewItem', index: QtCore.QModelIndex) -> QtCore.QSize: result = super(FileItemDelegate, self).sizeHint(option, index) result.setHeight(40) return result
class FileListModel(QAbstractListModel): def init(self, parent=None): super().init(parent) self.items = []
class FileExplorerWidget(QWidget): FILES_WORKER_ID = 300 DOWNLOAD_WORKER_ID = 399
class TextView(QMainWindow): def init(self, filename, data): QMainWindow.init(self)
def select_multiple_files(self): filenames, = QFileDialog.getOpenFileNames(self, 'Select Files') if file_names: self.handle_selected_files(file_names)
def handle_selected_files(self, file_names: list):
Implement your logic here
` modified_files.zip