import warnings warnings.filterwarnings("ignore", category=DeprecationWarning) import sys import os from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QPushButton, QTreeView, QLabel, QStyle, QFileDialog, QHBoxLayout, QLineEdit, QProgressBar) from PyQt6.QtCore import Qt, QDir, QTimer from PyQt6.QtGui import QStandardItemModel, QStandardItem from testmid import MidPlay from ScanOrg100 import Organizer from timer_m import Timer_Ui class Fbrowser(QMainWindow): def __init__(self): super().__init__() self.midplay = None self.current_path = QDir.homePath() self.organizer = Organizer() self.init_ui() self.timer = Timer_Ui() def init_ui(self): self.setWindowTitle('File Browser') central_widget = QWidget() layout = QVBoxLayout(central_widget) # Address bar address_layout = QHBoxLayout() self.address_bar = QLineEdit(self.current_path) self.address_bar.returnPressed.connect(self.navigate_to_address) address_layout.addWidget(self.address_bar) # Navigation buttons back_button = QPushButton('Back') back_button.clicked.connect(self.go_back) address_layout.addWidget(back_button) layout.addLayout(address_layout) # Add a progress bar self.progress_bar = QProgressBar() layout.addWidget(self.progress_bar) # File view self.file_model = QStandardItemModel() self.file_tree = QTreeView() self.file_tree.setModel(self.file_model) self.file_tree.doubleClicked.connect(self.on_item_double_clicked) layout.addWidget(self.file_tree) # MidPlay button open_midplay_button = QPushButton('Open MidPlay') open_midplay_button.clicked.connect(self.open_midplay) layout.addWidget(open_midplay_button) self.setCentralWidget(central_widget) self.resize(800, 600) # Timer Button self.timer_button = QPushButton('Start Timer') self.timer_button.clicked.connect(self.open_timer) layout.addWidget(self.timer_button) self.scan_current_directory() def scan_current_directory(self): self.organizer.start_scan(self.current_path) self.progress_bar.setRange(0, 0) # Indeterminate progress self.organizer.scanner.scan_complete.connect(self.scan_finished) def scan_finished(self): self.progress_bar.setRange(0, 100) self.progress_bar.setValue(100) self.update_file_tree() def navigate_to_address(self): new_path = self.address_bar.text() if os.path.isdir(new_path): self.current_path = new_path self.scan_current_directory() else: self.address_bar.setText(self.current_path) def update_file_tree(self): self.file_model.clear() self.file_model.setHorizontalHeaderLabels(['Name']) root = self.file_model.invisibleRootItem() # Add directories for path in self.organizer.dir_list: name = os.path.basename(path) item = QStandardItem(name) item.setData(path, Qt.ItemDataRole.UserRole) item.setIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_DirIcon)) root.appendRow(item) # Add files for path in self.organizer.file_list: name = os.path.basename(path) item = QStandardItem(name) item.setData(path, Qt.ItemDataRole.UserRole) item.setIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_FileIcon)) root.appendRow(item) self.file_tree.sortByColumn(0, Qt.SortOrder.AscendingOrder) def on_item_double_clicked(self, index): item = self.file_model.itemFromIndex(index) path = item.data(Qt.ItemDataRole.UserRole) if os.path.isdir(path): self.current_path = path self.address_bar.setText(path) self.scan_current_directory() else: self.play_file(path) def playingcheck_and_stop(self): if self.midplay.is_playing(): self.midplay.stop() def play_file(self, file_path): if not self.midplay: self.midplay = MidPlay() #self.midplay.showUI() self.midplay.add_to_playlist(file_path) def go_back(self): parent_dir = os.path.dirname(self.current_path) if parent_dir != self.current_path: self.current_path = parent_dir self.address_bar.setText(parent_dir) self.scan_current_directory() def open_midplay(self): if not self.midplay: self.midplay = MidPlay() self.midplay.showUI() def open_timer(self): self.timer.showUI() if __name__ == '__main__': app = QApplication(sys.argv) ex = Fbrowser() ex.show() sys.exit(app.exec())