46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
|
#!/usr/bin/python3
|
||
|
|
||
|
from PyQt6.QtWidgets import QWidget, QLabel, QFileDialog
|
||
|
|
||
|
|
||
|
class FileActions:
|
||
|
def __init__(self, app):
|
||
|
self.app = app
|
||
|
|
||
|
def open_files(self):
|
||
|
dialog = QFileDialog(self.app.QTMainWindow)
|
||
|
dialog.setDirectory(self.app.utils.home_path)
|
||
|
dialog.setFileMode(QFileDialog.FileMode.ExistingFiles)
|
||
|
dialog.setNameFilters(["Binary (*.bin)", "Any (*)"])
|
||
|
dialog.setViewMode(QFileDialog.ViewMode.List)
|
||
|
|
||
|
if dialog.exec():
|
||
|
for file_path in dialog.selectedFiles():
|
||
|
self.app.open_files.append(File(self.app, file_path, file_path.split("/")[-1]))
|
||
|
|
||
|
|
||
|
class File:
|
||
|
def __init__(self, app, path, name):
|
||
|
self.app = app
|
||
|
|
||
|
self.path = path
|
||
|
self.name = name
|
||
|
|
||
|
file = open(path, "r")
|
||
|
file_content = file.read()
|
||
|
file.close()
|
||
|
|
||
|
self.content = file_content
|
||
|
|
||
|
# the widget that contains all the file content
|
||
|
self.content_widget = QWidget(self.app.main_window.openFileTabs)
|
||
|
self.content_label = QLabel(self.content_widget) # the label for the text in the file
|
||
|
self.content_label.setText(file_content)
|
||
|
|
||
|
self.app.main_window.openFileTabs.addTab( # add a tab for the file in the top files list
|
||
|
self.content_widget,
|
||
|
self.name
|
||
|
)
|
||
|
|
||
|
|