Implemented size check for files opened via command line, simplified some code and added some comments.
This commit is contained in:
parent
7235736309
commit
46f49804a8
4 changed files with 25 additions and 25 deletions
18
file.py
18
file.py
|
@ -20,13 +20,7 @@ class FileActions:
|
||||||
dialog.setViewMode(QFileDialog.ViewMode.List)
|
dialog.setViewMode(QFileDialog.ViewMode.List)
|
||||||
|
|
||||||
if dialog.exec():
|
if dialog.exec():
|
||||||
for file_path in dialog.selectedFiles():
|
self.open_multiple_files(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 create_file(self, content: bin=b""):
|
def create_file(self, content: bin=b""):
|
||||||
file_path, extension = QFileDialog.getSaveFileName(
|
file_path, extension = QFileDialog.getSaveFileName(
|
||||||
|
@ -82,6 +76,16 @@ class FileActions:
|
||||||
for file_path in self.app.open_files:
|
for file_path in self.app.open_files:
|
||||||
self.app.open_files[file_path].save()
|
self.app.open_files[file_path].save()
|
||||||
|
|
||||||
|
def open_multiple_files(self, file_paths):
|
||||||
|
for file_path in file_paths:
|
||||||
|
if not file_path in self.app.open_files and os.path.isfile(file_path):
|
||||||
|
if os.path.getsize(file_path) > MAX_FILE_SIZE:
|
||||||
|
self.app.utils.ftb_popup.exec()
|
||||||
|
return
|
||||||
|
|
||||||
|
file = File(self.app, file_path, file_path.split("/")[-1])
|
||||||
|
self.app.open_files[file_path] = file
|
||||||
|
|
||||||
|
|
||||||
class File:
|
class File:
|
||||||
def __init__(self, app, path, name):
|
def __init__(self, app, path, name):
|
||||||
|
|
4
main.py
4
main.py
|
@ -38,10 +38,10 @@ class BreadEditor:
|
||||||
|
|
||||||
self.gui.post_setup()
|
self.gui.post_setup()
|
||||||
|
|
||||||
self.utils.on_start()
|
|
||||||
|
|
||||||
self.utils.popup_init()
|
self.utils.popup_init()
|
||||||
|
|
||||||
|
self.utils.on_start()
|
||||||
|
|
||||||
self.gui.QTMainWindow.show()
|
self.gui.QTMainWindow.show()
|
||||||
sys.exit(self.gui.qt_app.exec())
|
sys.exit(self.gui.qt_app.exec())
|
||||||
|
|
||||||
|
|
1
ui.py
1
ui.py
|
@ -1,7 +1,6 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
from PyQt6.QtWidgets import QApplication, QMainWindow
|
from PyQt6.QtWidgets import QApplication, QMainWindow
|
||||||
from PyQt6.QtGui import QFont
|
|
||||||
from gui.main_window import Ui_MainWindow
|
from gui.main_window import Ui_MainWindow
|
||||||
from connect_gui import connect_gui
|
from connect_gui import connect_gui
|
||||||
|
|
||||||
|
|
27
utils.py
27
utils.py
|
@ -33,7 +33,7 @@ class Utils:
|
||||||
"https://teapot.informationsanarchistik.de/Wobbl/Bread_Editor"
|
"https://teapot.informationsanarchistik.de/Wobbl/Bread_Editor"
|
||||||
)
|
)
|
||||||
|
|
||||||
def unsaved_changes_popup(self):
|
def unsaved_changes_popup(self): # show popup and simplify return values
|
||||||
button = self.usc_popup.exec()
|
button = self.usc_popup.exec()
|
||||||
|
|
||||||
match button:
|
match button:
|
||||||
|
@ -69,14 +69,14 @@ class Utils:
|
||||||
def on_close(self, event):
|
def on_close(self, event):
|
||||||
changes = False
|
changes = False
|
||||||
|
|
||||||
for file_path in self.app.open_files:
|
for file_path in self.app.open_files: # check for files that have unsaved changes
|
||||||
file = self.app.open_files[file_path]
|
file = self.app.open_files[file_path]
|
||||||
|
|
||||||
if file.bit_editor.not_saved:
|
if file.bit_editor.not_saved:
|
||||||
changes = True
|
changes = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if changes:
|
if changes: # show a popup that informs the user that there are unsaved changes and ask them what to do
|
||||||
save_or_not = self.unsaved_changes_popup()
|
save_or_not = self.unsaved_changes_popup()
|
||||||
|
|
||||||
match save_or_not:
|
match save_or_not:
|
||||||
|
@ -94,8 +94,7 @@ class Utils:
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
print("Bye!")
|
# get paths of open files and save them to the settings to reopen them automatically on next start
|
||||||
|
|
||||||
file_keys = self.app.open_files.keys()
|
file_keys = self.app.open_files.keys()
|
||||||
open_files = []
|
open_files = []
|
||||||
|
|
||||||
|
@ -106,7 +105,10 @@ class Utils:
|
||||||
|
|
||||||
self.app.settings.save(f"{self.editor_path}/settings.json")
|
self.app.settings.save(f"{self.editor_path}/settings.json")
|
||||||
|
|
||||||
|
print("Bye!")
|
||||||
|
|
||||||
def update_style_in_all_bit_editors(self):
|
def update_style_in_all_bit_editors(self):
|
||||||
|
# update the highlighting and character spacing when a setting has changed
|
||||||
self.app.settings.highlight_ones = self.app.gui.main_window.highlightOnesSetting.isChecked()
|
self.app.settings.highlight_ones = self.app.gui.main_window.highlightOnesSetting.isChecked()
|
||||||
self.app.settings.square_bits = self.app.gui.main_window.bitsAreSquaresSetting.isChecked()
|
self.app.settings.square_bits = self.app.gui.main_window.bitsAreSquaresSetting.isChecked()
|
||||||
|
|
||||||
|
@ -116,23 +118,18 @@ class Utils:
|
||||||
editor.update_style()
|
editor.update_style()
|
||||||
|
|
||||||
def on_start(self):
|
def on_start(self):
|
||||||
|
# either open the lastly opened files or open the files specified by the parameters
|
||||||
if len(sys.argv) == 1: # if no parameters were passed to the editor
|
if len(sys.argv) == 1: # if no parameters were passed to the editor
|
||||||
self.load_files(self.app.settings.last_opened_files)
|
file_paths = self.app.settings.last_opened_files
|
||||||
|
|
||||||
else:
|
else:
|
||||||
file_paths = sys.argv[1:]
|
file_paths = sys.argv[1:]
|
||||||
|
|
||||||
self.load_files(file_paths)
|
self.app.file_actions.open_multiple_files(file_paths)
|
||||||
|
|
||||||
def load_files(self, file_paths):
|
|
||||||
for file_path in file_paths:
|
|
||||||
if not file_path in self.app.open_files and os.path.isfile(file_path):
|
|
||||||
file = File(self.app, file_path, file_path.split("/")[-1])
|
|
||||||
self.app.open_files[file_path] = file
|
|
||||||
|
|
||||||
def check_file_queue(self):
|
def check_file_queue(self):
|
||||||
if not len(self.app.open_files_queue) == 0:
|
if not self.app.open_files_queue == []: # check for file paths in the queue that the ipc server put there
|
||||||
filenames = self.app.open_files_queue
|
filenames = self.app.open_files_queue
|
||||||
self.app.open_files_queue = []
|
self.app.open_files_queue = []
|
||||||
|
|
||||||
self.load_files(filenames)
|
self.app.file_actions.open_multiple_files(filenames)
|
||||||
|
|
Loading…
Add table
Reference in a new issue