From d3c1712166c52ddc364908b8a258d3683f1e214f Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sat, 30 Nov 2024 20:50:53 +0100 Subject: [PATCH] Before you open a file, the editor now checks if it isn't too big. --- file.py | 7 +++++++ utils.py | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/file.py b/file.py index 72f5266..69d20de 100644 --- a/file.py +++ b/file.py @@ -1,8 +1,11 @@ #!/usr/bin/python3 +import os.path from PyQt6.QtWidgets import QFileDialog from editor import BitEditor +MAX_FILE_SIZE = 262144 # 2^18 + class FileActions: def __init__(self, app): @@ -18,6 +21,10 @@ class FileActions: if dialog.exec(): for file_path in dialog.selectedFiles(): 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]) def save_current_file(self): diff --git a/utils.py b/utils.py index ff16230..16585d2 100644 --- a/utils.py +++ b/utils.py @@ -2,6 +2,7 @@ import sys from pathlib import Path +from PyQt6.QtCore import Qt from PyQt6.QtWidgets import QMessageBox from file import File @@ -22,6 +23,15 @@ class Utils: 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): button = self.usc_popup.exec()