Implemented reopening last opened file.
This commit is contained in:
parent
490cf7df97
commit
f0152cc2ce
6 changed files with 34 additions and 11 deletions
|
@ -16,6 +16,8 @@ class BitEditor:
|
|||
self.app = app
|
||||
self.file = file
|
||||
|
||||
self.not_saved = False
|
||||
|
||||
self.setup_gui()
|
||||
|
||||
def setup_gui(self):
|
||||
|
@ -26,7 +28,9 @@ class BitEditor:
|
|||
self.input = BinaryTextEdit()
|
||||
self.input.setOverwriteMode(True)
|
||||
self.widget_layout.addWidget(self.input)
|
||||
|
||||
self.input.setPlainText(self.app.utils.bstring_to_oz(self.file.content))
|
||||
|
||||
self.input.textChanged.connect(self.on_edit)
|
||||
|
||||
self.input.setFont(self.font)
|
||||
|
|
2
file.py
2
file.py
|
@ -61,6 +61,8 @@ class File:
|
|||
|
||||
self.bit_editor = BitEditor(self.app, self)
|
||||
|
||||
self.app.settings.last_opened_file = self.path
|
||||
|
||||
def close(self):
|
||||
self.app.gui.main_window.openFileTabs.removeTab(self.bit_editor.tab_index)
|
||||
del self.app.open_files[self.path]
|
||||
|
|
16
main.py
16
main.py
|
@ -3,7 +3,7 @@
|
|||
import sys
|
||||
from wobbl_tools.data_file import save_dataclass_json, load_dataclass_json
|
||||
from utils import Utils
|
||||
from file import FileActions, File, BitEditor
|
||||
import file
|
||||
from ui import GUI
|
||||
from settings import Settings
|
||||
|
||||
|
@ -12,11 +12,14 @@ class BreadEditor:
|
|||
def __init__(self):
|
||||
self.settings = load_dataclass_json(Settings, "settings.json")
|
||||
setattr(self.settings, "save", lambda: save_dataclass_json(self.settings, "settings.json"))
|
||||
self.utils = Utils(self)
|
||||
self.file_actions = FileActions(self)
|
||||
self.gui = GUI(self)
|
||||
|
||||
self.BitEditor = BitEditor
|
||||
# save the file module to a variable because we need to use it in other classes but we change some file class --
|
||||
# variables that also need to be accesible from the other classes.
|
||||
self.file = file
|
||||
File = file.File
|
||||
self.utils = Utils(self)
|
||||
self.file_actions = file.FileActions(self)
|
||||
self.gui = GUI(self)
|
||||
|
||||
self.gui.connect_gui(self)
|
||||
|
||||
|
@ -24,6 +27,9 @@ class BreadEditor:
|
|||
|
||||
def run(self):
|
||||
self.gui.post_setup()
|
||||
|
||||
self.utils.open_last_file()
|
||||
|
||||
self.utils.popup_init()
|
||||
|
||||
self.gui.QTMainWindow.show()
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Settings:
|
||||
square_bits: bool = False
|
||||
last_opened_file: str=f"{os.path.dirname(os.path.abspath(__file__))}/example.txt"
|
||||
square_bits: bool=False
|
||||
|
|
8
ui.py
8
ui.py
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
from PyQt6.QtWidgets import QApplication, QMainWindow
|
||||
from PyQt6.QtGui import QFont
|
||||
from gui.main_window import Ui_MainWindow
|
||||
|
@ -11,7 +10,7 @@ class GUI:
|
|||
def __init__(self, app):
|
||||
self.app = app
|
||||
|
||||
self.qt_app = QApplication(sys.argv)
|
||||
self.qt_app = QApplication([])
|
||||
self.QTMainWindow = QMainWindow()
|
||||
|
||||
self.main_window = Ui_MainWindow()
|
||||
|
@ -27,7 +26,6 @@ class GUI:
|
|||
def post_setup(self):
|
||||
self.main_window.bitsAreSquaresSetting.setChecked(self.app.settings.square_bits)
|
||||
|
||||
spacing = 200 if self.app.settings.square_bits else 100 # add spacing when setting is checked
|
||||
print(self.app.settings.square_bits)
|
||||
spacing = 200 if self.app.settings.square_bits else 100
|
||||
|
||||
self.app.BitEditor.font.setLetterSpacing(QFont.SpacingType.PercentageSpacing, spacing)
|
||||
self.app.file.BitEditor.font.setLetterSpacing(QFont.SpacingType.PercentageSpacing, spacing)
|
||||
|
|
11
utils.py
11
utils.py
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from PyQt6.QtWidgets import QMessageBox
|
||||
from PyQt6.QtGui import QFont
|
||||
|
@ -78,6 +79,9 @@ class Utils:
|
|||
case "discard":
|
||||
self.close()
|
||||
|
||||
else:
|
||||
self.close()
|
||||
|
||||
def close(self):
|
||||
print("Bye!")
|
||||
|
||||
|
@ -95,3 +99,10 @@ class Utils:
|
|||
|
||||
editor.font.setLetterSpacing(QFont.SpacingType.PercentageSpacing, spacing)
|
||||
editor.input.setFont(editor.font)
|
||||
|
||||
def open_last_file(self):
|
||||
if len(sys.argv) == 1: # if no parameters were passed to the editor
|
||||
file_path = self.app.settings.last_opened_file
|
||||
|
||||
file = self.app.file.File(self.app, file_path, file_path.split("/")[-1])
|
||||
self.app.open_files[file_path] = file
|
||||
|
|
Loading…
Reference in a new issue