Implemented setting: highlight ones.

This commit is contained in:
The Wobbler 2024-11-21 20:19:37 +01:00
parent f0152cc2ce
commit f6ed881764
6 changed files with 75 additions and 13 deletions

View file

@ -7,3 +7,4 @@ def connect_gui(app):
app.gui.QTMainWindow.closeEvent = app.utils.on_close 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.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.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)

View file

@ -66,6 +66,18 @@
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>124</height>
</size>
</property>
<property name="accessibleName"> <property name="accessibleName">
<string/> <string/>
</property> </property>
@ -88,10 +100,22 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QTabWidget" name="settingsTabs"> <widget class="QTabWidget" name="settingsTabs">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="appearanceSettingsTab"> <widget class="QWidget" name="appearanceSettingsTab">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="accessibleName"> <property name="accessibleName">
<string/> <string/>
</property> </property>
@ -101,9 +125,28 @@
<attribute name="title"> <attribute name="title">
<string>Appearance</string> <string>Appearance</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_2"> <widget class="QCheckBox" name="highlightOnesSetting">
<item> <property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>111</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Highlight ones</string>
</property>
</widget>
<widget class="QCheckBox" name="bitsAreSquaresSetting"> <widget class="QCheckBox" name="bitsAreSquaresSetting">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>119</width>
<height>21</height>
</rect>
</property>
<property name="text"> <property name="text">
<string>Bits are squares</string> <string>Bits are squares</string>
</property> </property>
@ -111,8 +154,6 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item>
</layout>
</widget> </widget>
</widget> </widget>
</item> </item>

View file

@ -12,11 +12,13 @@ class BreadEditor:
def __init__(self): def __init__(self):
self.settings = load_dataclass_json(Settings, "settings.json") self.settings = load_dataclass_json(Settings, "settings.json")
setattr(self.settings, "save", lambda: save_dataclass_json(self.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 -- # 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. # variables that also need to be accesible from the other classes.
self.file = file self.file = file
File = file.File File = file.File
self.utils = Utils(self) self.utils = Utils(self)
self.file_actions = file.FileActions(self) self.file_actions = file.FileActions(self)
self.gui = GUI(self) self.gui = GUI(self)

View file

@ -7,4 +7,5 @@ from dataclasses import dataclass
@dataclass @dataclass
class Settings: class Settings:
last_opened_file: str=f"{os.path.dirname(os.path.abspath(__file__))}/example.txt" last_opened_file: str=f"{os.path.dirname(os.path.abspath(__file__))}/example.txt"
highlight_ones: bool=False
square_bits: bool=False square_bits: bool=False

10
ui.py
View file

@ -29,3 +29,13 @@ class GUI:
spacing = 200 if self.app.settings.square_bits else 100 spacing = 200 if self.app.settings.square_bits else 100
self.app.file.BitEditor.font.setLetterSpacing(QFont.SpacingType.PercentageSpacing, spacing) 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)

View file

@ -88,12 +88,19 @@ class Utils:
self.app.settings.save() self.app.settings.save()
def update_font_in_all_bit_editors(self): def update_font_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() 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
square = self.app.gui.main_window.bitsAreSquaresSetting.isChecked() 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 spacing = 200 if square else 100 # add spacing when setting is checked