feat(dialogs): add file extension filters for exe and image selection to File Explorer

Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
This commit is contained in:
2025-06-26 14:35:24 +05:00
parent 4af4d1f0b0
commit 88e9d1d7c5
2 changed files with 9 additions and 4 deletions

View File

@ -89,9 +89,10 @@ class FileSelectedSignal(QObject):
class FileExplorer(QDialog): class FileExplorer(QDialog):
def __init__(self, parent=None): def __init__(self, parent=None, file_filter=None):
super().__init__(parent) super().__init__(parent)
self.file_signal = FileSelectedSignal() self.file_signal = FileSelectedSignal()
self.file_filter = file_filter # Store the file filter
self.setup_ui() self.setup_ui()
# Настройки окна # Настройки окна
@ -187,7 +188,11 @@ class FileExplorer(QDialog):
items = os.listdir(self.current_path) items = os.listdir(self.current_path)
dirs = [d for d in items if os.path.isdir(os.path.join(self.current_path, d))] dirs = [d for d in items if os.path.isdir(os.path.join(self.current_path, d))]
# Apply file filter if provided
files = [f for f in items if os.path.isfile(os.path.join(self.current_path, f))] files = [f for f in items if os.path.isfile(os.path.join(self.current_path, f))]
if self.file_filter:
files = [f for f in files if f.lower().endswith(self.file_filter)]
for d in sorted(dirs): for d in sorted(dirs):
self.file_list.addItem(f"{d}/") self.file_list.addItem(f"{d}/")
@ -307,7 +312,7 @@ class AddGameDialog(QDialog):
def browseExe(self): def browseExe(self):
"""Открывает файловый менеджер для выбора exe-файла""" """Открывает файловый менеджер для выбора exe-файла"""
try: try:
file_explorer = FileExplorer(self) file_explorer = FileExplorer(self, file_filter='.exe')
file_explorer.file_signal.file_selected.connect(self.onExeSelected) file_explorer.file_signal.file_selected.connect(self.onExeSelected)
if self.parent(): if self.parent():
@ -332,7 +337,7 @@ class AddGameDialog(QDialog):
def browseCover(self): def browseCover(self):
"""Открывает файловый менеджер для выбора изображения обложки""" """Открывает файловый менеджер для выбора изображения обложки"""
try: try:
file_explorer = FileExplorer(self) file_explorer = FileExplorer(self, file_filter=('.png', '.jpg', '.jpeg', '.bmp'))
file_explorer.file_signal.file_selected.connect(self.onCoverSelected) file_explorer.file_signal.file_selected.connect(self.onCoverSelected)
if self.parent(): if self.parent():

View File

@ -209,7 +209,7 @@ class InputManager(QObject):
self.stick_value = speed_factor self.stick_value = speed_factor
self.stick_activated = True self.stick_activated = True
if t self.nav_timer.isActive(): if not self.nav_timer.isActive():
self.file_explorer.move_selection(self.current_direction) self.file_explorer.move_selection(self.current_direction)
self.last_nav_time = current_time self.last_nav_time = current_time
self.nav_timer.start(int(self.initial_nav_delay * 1000)) self.nav_timer.start(int(self.initial_nav_delay * 1000))