Before you open a file, the editor now checks if it isn't too big.

This commit is contained in:
The Wobbler 2024-11-30 20:50:53 +01:00
parent 6922e3dc9b
commit d3c1712166
2 changed files with 17 additions and 0 deletions

View file

@ -1,8 +1,11 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os.path
from PyQt6.QtWidgets import QFileDialog from PyQt6.QtWidgets import QFileDialog
from editor import BitEditor from editor import BitEditor
MAX_FILE_SIZE = 262144 # 2^18
class FileActions: class FileActions:
def __init__(self, app): def __init__(self, app):
@ -18,6 +21,10 @@ class FileActions:
if dialog.exec(): if dialog.exec():
for file_path in dialog.selectedFiles(): for file_path in dialog.selectedFiles():
if not file_path in self.app.open_files: # dont open file twice if not file_path in self.app.open_files: # dont open file twice
if os.path.getsize(file_path) > MAX_FILE_SIZE:
self.app.utils.ftb_popup.exec()
return
self.app.open_files[file_path] = File(self.app, file_path, file_path.split("/")[-1]) self.app.open_files[file_path] = File(self.app, file_path, file_path.split("/")[-1])
def save_current_file(self): def save_current_file(self):

View file

@ -2,6 +2,7 @@
import sys import sys
from pathlib import Path from pathlib import Path
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QMessageBox from PyQt6.QtWidgets import QMessageBox
from file import File from file import File
@ -22,6 +23,15 @@ class Utils:
QMessageBox.StandardButton.Cancel QMessageBox.StandardButton.Cancel
) )
self.ftb_popup = QMessageBox() # dialog that says that the file is too big
self.ftb_popup.setWindowTitle("File Too Big!")
self.ftb_popup.setText("The file you are trying to open is too big!")
self.ftb_popup.setDetailedText(
"I am way too lazy to make the editor capable of handling big files,\n"
"but you could improve the editor, if this annoys you.\n"
"https://teapot.informationsanarchistik.de/Wobbl/Bread_Editor"
)
def unsaved_changes_popup(self): def unsaved_changes_popup(self):
button = self.usc_popup.exec() button = self.usc_popup.exec()