From 7b1a90c02f2a6b9df3b2c92c278920f11840c546 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Thu, 21 Nov 2024 18:54:32 +0100 Subject: [PATCH] The settings get now stored. --- main.py | 9 ++++++++- settings.py | 8 ++++++++ ui.py | 9 +++++++++ utils.py | 9 +++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 settings.py diff --git a/main.py b/main.py index ef19760..1b5919a 100755 --- a/main.py +++ b/main.py @@ -1,22 +1,29 @@ #!/usr/bin/python3 import sys +from wobbl_tools.data_file import save_dataclass_json, load_dataclass_json from utils import Utils -from file import FileActions, File +from file import FileActions, File, BitEditor from ui import GUI +from settings import Settings 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 + self.gui.connect_gui(self) self.open_files: dict[str, File] = {} def run(self): + self.gui.post_setup() self.utils.popup_init() self.gui.QTMainWindow.show() diff --git a/settings.py b/settings.py new file mode 100644 index 0000000..4db7b86 --- /dev/null +++ b/settings.py @@ -0,0 +1,8 @@ +#!/usr/bin/python3 + +from dataclasses import dataclass + + +@dataclass +class Settings: + square_bits: bool = False diff --git a/ui.py b/ui.py index e34e72c..81d91e8 100644 --- a/ui.py +++ b/ui.py @@ -2,6 +2,7 @@ import sys from PyQt6.QtWidgets import QApplication, QMainWindow +from PyQt6.QtGui import QFont from gui.main_window import Ui_MainWindow from connect_gui import connect_gui @@ -22,3 +23,11 @@ class GUI: def setup_gui(self): self.main_window.setupUi(self.QTMainWindow) self.main_window.settingsDock.hide() + + 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) + + self.app.BitEditor.font.setLetterSpacing(QFont.SpacingType.PercentageSpacing, spacing) diff --git a/utils.py b/utils.py index 40cf792..12e3c31 100644 --- a/utils.py +++ b/utils.py @@ -70,13 +70,22 @@ class Utils: match save_or_not: case "save": self.app.file_actions.save_all_files() + self.close() case "cancel": event.ignore() + case "discard": + self.close() + + def close(self): print("Bye!") + self.app.settings.save() + def update_font_in_all_bit_editors(self): + self.app.settings.square_bits = self.app.gui.main_window.bitsAreSquaresSetting.isChecked() + for file_path in self.app.open_files: editor = self.app.open_files[file_path].bit_editor