The settings get now stored.

This commit is contained in:
The Wobbler 2024-11-21 18:54:32 +01:00
parent fdc9f86f92
commit 7b1a90c02f
4 changed files with 34 additions and 1 deletions

View file

@ -1,22 +1,29 @@
#!/usr/bin/python3 #!/usr/bin/python3
import sys import sys
from wobbl_tools.data_file import save_dataclass_json, load_dataclass_json
from utils import Utils from utils import Utils
from file import FileActions, File from file import FileActions, File, BitEditor
from ui import GUI from ui import GUI
from settings import Settings
class BreadEditor: class BreadEditor:
def __init__(self): 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.utils = Utils(self)
self.file_actions = FileActions(self) self.file_actions = FileActions(self)
self.gui = GUI(self) self.gui = GUI(self)
self.BitEditor = BitEditor
self.gui.connect_gui(self) self.gui.connect_gui(self)
self.open_files: dict[str, File] = {} self.open_files: dict[str, File] = {}
def run(self): def run(self):
self.gui.post_setup()
self.utils.popup_init() self.utils.popup_init()
self.gui.QTMainWindow.show() self.gui.QTMainWindow.show()

8
settings.py Normal file
View file

@ -0,0 +1,8 @@
#!/usr/bin/python3
from dataclasses import dataclass
@dataclass
class Settings:
square_bits: bool = False

9
ui.py
View file

@ -2,6 +2,7 @@
import sys import sys
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
@ -22,3 +23,11 @@ class GUI:
def setup_gui(self): def setup_gui(self):
self.main_window.setupUi(self.QTMainWindow) self.main_window.setupUi(self.QTMainWindow)
self.main_window.settingsDock.hide() 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)

View file

@ -70,13 +70,22 @@ class Utils:
match save_or_not: match save_or_not:
case "save": case "save":
self.app.file_actions.save_all_files() self.app.file_actions.save_all_files()
self.close()
case "cancel": case "cancel":
event.ignore() event.ignore()
case "discard":
self.close()
def close(self):
print("Bye!") print("Bye!")
self.app.settings.save()
def update_font_in_all_bit_editors(self): 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: for file_path in self.app.open_files:
editor = self.app.open_files[file_path].bit_editor editor = self.app.open_files[file_path].bit_editor