Fixed 2 bugs and OOPed everything a little more.
This commit is contained in:
parent
f6ed881764
commit
6922e3dc9b
5 changed files with 27 additions and 41 deletions
|
@ -6,5 +6,5 @@ def connect_gui(app):
|
|||
app.gui.main_window.openFileTabs.tabCloseRequested.connect(app.file_actions.close_current_file)
|
||||
app.gui.QTMainWindow.closeEvent = app.utils.on_close
|
||||
app.gui.main_window.menuSettings.triggered.connect(app.gui.main_window.settingsDock.show)
|
||||
app.gui.main_window.bitsAreSquaresSetting.stateChanged.connect(app.utils.update_font_in_all_bit_editors)
|
||||
app.gui.main_window.highlightOnesSetting.stateChanged.connect(app.utils.update_font_in_all_bit_editors)
|
||||
app.gui.main_window.bitsAreSquaresSetting.stateChanged.connect(app.utils.update_style_in_all_bit_editors)
|
||||
app.gui.main_window.highlightOnesSetting.stateChanged.connect(app.utils.update_style_in_all_bit_editors)
|
||||
|
|
20
editor.py
20
editor.py
|
@ -8,7 +8,6 @@ from highlighting import Higlighter
|
|||
|
||||
class BitEditor:
|
||||
font = QFont("Ubuntu Mono", 12)
|
||||
font.setLetterSpacing(QFont.SpacingType.PercentageSpacing, 200)
|
||||
one_format = QTextCharFormat()
|
||||
one_format.setBackground(QColor(200, 150, 100))
|
||||
|
||||
|
@ -33,11 +32,10 @@ class BitEditor:
|
|||
|
||||
self.input.textChanged.connect(self.on_edit)
|
||||
|
||||
self.input.setFont(self.font)
|
||||
|
||||
self.bit_highlighter = Higlighter()
|
||||
self.bit_highlighter.add_mapping("1", self.one_format)
|
||||
self.bit_highlighter.setDocument(self.input.document())
|
||||
|
||||
self.update_style()
|
||||
|
||||
self.widget.setLayout(self.widget_layout)
|
||||
|
||||
|
@ -48,3 +46,17 @@ class BitEditor:
|
|||
|
||||
def on_edit(self):
|
||||
self.not_saved = True
|
||||
|
||||
def update_style(self):
|
||||
square = self.app.settings.square_bits
|
||||
|
||||
spacing = 200 if square else 100 # add spacing when setting is checked
|
||||
|
||||
self.font.setLetterSpacing(QFont.SpacingType.PercentageSpacing, spacing)
|
||||
self.input.setFont(self.font)
|
||||
|
||||
highlight_ones = self.app.settings.highlight_ones
|
||||
|
||||
highlighter_document = self.input.document() if highlight_ones else None
|
||||
|
||||
self.bit_highlighter.setDocument(highlighter_document)
|
||||
|
|
11
main.py
11
main.py
|
@ -3,7 +3,7 @@
|
|||
import sys
|
||||
from wobbl_tools.data_file import save_dataclass_json, load_dataclass_json
|
||||
from utils import Utils
|
||||
import file
|
||||
from file import File, FileActions
|
||||
from ui import GUI
|
||||
from settings import Settings
|
||||
|
||||
|
@ -12,19 +12,12 @@ 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"))
|
||||
print(self.settings.highlight_ones)
|
||||
|
||||
# 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.file_actions = FileActions(self)
|
||||
self.gui = GUI(self)
|
||||
|
||||
self.gui.connect_gui(self)
|
||||
|
||||
self.open_files: dict[str, File] = {}
|
||||
|
||||
def run(self):
|
||||
|
|
14
ui.py
14
ui.py
|
@ -24,18 +24,10 @@ class GUI:
|
|||
self.main_window.settingsDock.hide()
|
||||
|
||||
def post_setup(self):
|
||||
self.main_window.bitsAreSquaresSetting.blockSignals(True)
|
||||
self.main_window.bitsAreSquaresSetting.setChecked(self.app.settings.square_bits)
|
||||
self.main_window.bitsAreSquaresSetting.blockSignals(False)
|
||||
|
||||
spacing = 200 if self.app.settings.square_bits else 100
|
||||
|
||||
self.app.file.BitEditor.font.setLetterSpacing(QFont.SpacingType.PercentageSpacing, spacing)
|
||||
|
||||
print(self.app.settings.highlight_ones)
|
||||
self.main_window.highlightOnesSetting.setChecked(self.app.settings.highlight_ones)
|
||||
|
||||
for file_path in self.app.open_files:
|
||||
editor = self.app.open_files[file_path].bit_editor
|
||||
|
||||
highlighter_document = editor.input.document() if self.app.settings.highlight_ones else None
|
||||
|
||||
editor.bit_highlighter.setDocument(highlighter_document)
|
||||
self.app.utils.update_style_in_all_bit_editors()
|
||||
|
|
19
utils.py
19
utils.py
|
@ -3,7 +3,7 @@
|
|||
import sys
|
||||
from pathlib import Path
|
||||
from PyQt6.QtWidgets import QMessageBox
|
||||
from PyQt6.QtGui import QFont
|
||||
from file import File
|
||||
|
||||
|
||||
class Utils:
|
||||
|
@ -87,29 +87,18 @@ class Utils:
|
|||
|
||||
self.app.settings.save()
|
||||
|
||||
def update_font_in_all_bit_editors(self):
|
||||
def update_style_in_all_bit_editors(self):
|
||||
self.app.settings.highlight_ones = self.app.gui.main_window.highlightOnesSetting.isChecked()
|
||||
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
|
||||
|
||||
highlight_ones = self.app.settings.highlight_ones
|
||||
|
||||
highlighter_document = editor.input.document() if highlight_ones else None
|
||||
|
||||
editor.bit_highlighter.setDocument(highlighter_document)
|
||||
|
||||
square = self.app.settings.square_bits
|
||||
|
||||
spacing = 200 if square else 100 # add spacing when setting is checked
|
||||
|
||||
editor.font.setLetterSpacing(QFont.SpacingType.PercentageSpacing, spacing)
|
||||
editor.input.setFont(editor.font)
|
||||
editor.update_style()
|
||||
|
||||
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])
|
||||
file = File(self.app, file_path, file_path.split("/")[-1])
|
||||
self.app.open_files[file_path] = file
|
||||
|
|
Loading…
Reference in a new issue