124 lines
4.3 KiB
Python
124 lines
4.3 KiB
Python
|
|
import sys
|
||
|
|
from PySide6.QtWidgets import (
|
||
|
|
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
|
||
|
|
QTableWidget, QTableWidgetItem, QLabel, QPushButton, QHeaderView
|
||
|
|
)
|
||
|
|
from PySide6.QtCore import Qt, QTimer
|
||
|
|
from PySide6.QtGui import QIcon, QColor
|
||
|
|
from src.file_system import FileSystemReader, FileInfo
|
||
|
|
|
||
|
|
|
||
|
|
class FileSystemBrowser(QMainWindow):
|
||
|
|
"""Main application window for file system browser"""
|
||
|
|
|
||
|
|
def __init__(self, target_path: str = "C://OEM"):
|
||
|
|
super().__init__()
|
||
|
|
self.target_path = target_path
|
||
|
|
self.file_reader = FileSystemReader(target_path)
|
||
|
|
self.init_ui()
|
||
|
|
self.load_files()
|
||
|
|
|
||
|
|
def init_ui(self):
|
||
|
|
"""Initialize the user interface"""
|
||
|
|
self.setWindowTitle("File System Browser")
|
||
|
|
|
||
|
|
# Central widget
|
||
|
|
central_widget = QWidget()
|
||
|
|
self.setCentralWidget(central_widget)
|
||
|
|
main_layout = QVBoxLayout(central_widget)
|
||
|
|
main_layout.setContentsMargins(10, 10, 10, 10)
|
||
|
|
main_layout.setSpacing(10)
|
||
|
|
|
||
|
|
# Header section
|
||
|
|
header_layout = QHBoxLayout()
|
||
|
|
self.path_label = QLabel(f"Path: {self.target_path}")
|
||
|
|
self.path_label.setStyleSheet("font-weight: bold; font-size: 12px;")
|
||
|
|
header_layout.addWidget(self.path_label)
|
||
|
|
header_layout.addStretch()
|
||
|
|
|
||
|
|
# Refresh button
|
||
|
|
refresh_button = QPushButton("Refresh")
|
||
|
|
refresh_button.clicked.connect(self.load_files)
|
||
|
|
header_layout.addWidget(refresh_button)
|
||
|
|
|
||
|
|
main_layout.addLayout(header_layout)
|
||
|
|
|
||
|
|
# Table widget
|
||
|
|
self.table = QTableWidget()
|
||
|
|
self.table.setColumnCount(4)
|
||
|
|
self.table.setHorizontalHeaderLabels(["Name", "Type", "Size", "Modified"])
|
||
|
|
|
||
|
|
# Set column resize modes for better adaptive layout
|
||
|
|
header = self.table.horizontalHeader()
|
||
|
|
header.setSectionResizeMode(0, QHeaderView.Stretch) # Name column stretches
|
||
|
|
header.setSectionResizeMode(1, QHeaderView.ResizeToContents) # Type column fits content
|
||
|
|
header.setSectionResizeMode(2, QHeaderView.ResizeToContents) # Size column fits content
|
||
|
|
header.setSectionResizeMode(3, QHeaderView.ResizeToContents) # Modified column fits content
|
||
|
|
|
||
|
|
self.table.setAlternatingRowColors(True)
|
||
|
|
self.table.setSelectionBehavior(QTableWidget.SelectRows)
|
||
|
|
main_layout.addWidget(self.table)
|
||
|
|
|
||
|
|
# Status bar
|
||
|
|
self.status_label = QLabel("Ready")
|
||
|
|
self.status_label.setStyleSheet("padding: 5px;")
|
||
|
|
main_layout.addWidget(self.status_label)
|
||
|
|
|
||
|
|
# Set window to maximize on startup
|
||
|
|
self.showMaximized()
|
||
|
|
|
||
|
|
def load_files(self):
|
||
|
|
"""Load and display files and folders"""
|
||
|
|
self.status_label.setText("Loading...")
|
||
|
|
QApplication.processEvents()
|
||
|
|
|
||
|
|
try:
|
||
|
|
files = self.file_reader.get_files_and_folders()
|
||
|
|
|
||
|
|
# Clear existing rows
|
||
|
|
self.table.setRowCount(0)
|
||
|
|
|
||
|
|
# Populate table
|
||
|
|
for file_info in files:
|
||
|
|
row_position = self.table.rowCount()
|
||
|
|
self.table.insertRow(row_position)
|
||
|
|
|
||
|
|
# Name column
|
||
|
|
name_item = QTableWidgetItem(file_info.name)
|
||
|
|
if file_info.is_dir:
|
||
|
|
name_item.setForeground(QColor(0, 0, 255))
|
||
|
|
self.table.setItem(row_position, 0, name_item)
|
||
|
|
|
||
|
|
# Type column
|
||
|
|
type_item = QTableWidgetItem(file_info.file_type)
|
||
|
|
self.table.setItem(row_position, 1, type_item)
|
||
|
|
|
||
|
|
# Size column
|
||
|
|
size_text = "—" if file_info.is_dir else file_info.size_readable
|
||
|
|
size_item = QTableWidgetItem(size_text)
|
||
|
|
size_item.setTextAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
||
|
|
self.table.setItem(row_position, 2, size_item)
|
||
|
|
|
||
|
|
# Modified time column
|
||
|
|
time_item = QTableWidgetItem(file_info.modified_time)
|
||
|
|
self.table.setItem(row_position, 3, time_item)
|
||
|
|
|
||
|
|
self.status_label.setText(
|
||
|
|
f"Total items: {len(files)} | Path: {self.target_path}"
|
||
|
|
)
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
self.status_label.setText(f"Error: {str(e)}")
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
app = QApplication(sys.argv)
|
||
|
|
window = FileSystemBrowser()
|
||
|
|
# Window will be maximized in init_ui, but show() is still needed
|
||
|
|
window.show()
|
||
|
|
sys.exit(app.exec())
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|