Implemented setting: highlight ones.
This commit is contained in:
parent
f0152cc2ce
commit
f6ed881764
6 changed files with 75 additions and 13 deletions
|
@ -7,3 +7,4 @@ def connect_gui(app):
|
|||
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)
|
||||
|
|
|
@ -66,6 +66,18 @@
|
|||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</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">
|
||||
<string/>
|
||||
</property>
|
||||
|
@ -88,10 +100,22 @@
|
|||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="settingsTabs">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="appearanceSettingsTab">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="accessibleName">
|
||||
<string/>
|
||||
</property>
|
||||
|
@ -101,9 +125,28 @@
|
|||
<attribute name="title">
|
||||
<string>Appearance</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="highlightOnesSetting">
|
||||
<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">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>30</y>
|
||||
<width>119</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Bits are squares</string>
|
||||
</property>
|
||||
|
@ -111,8 +154,6 @@
|
|||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
2
main.py
2
main.py
|
@ -12,11 +12,13 @@ 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.gui = GUI(self)
|
||||
|
|
|
@ -7,4 +7,5 @@ from dataclasses import dataclass
|
|||
@dataclass
|
||||
class Settings:
|
||||
last_opened_file: str=f"{os.path.dirname(os.path.abspath(__file__))}/example.txt"
|
||||
highlight_ones: bool=False
|
||||
square_bits: bool=False
|
||||
|
|
10
ui.py
10
ui.py
|
@ -29,3 +29,13 @@ class GUI:
|
|||
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)
|
||||
|
|
9
utils.py
9
utils.py
|
@ -88,12 +88,19 @@ class Utils:
|
|||
self.app.settings.save()
|
||||
|
||||
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()
|
||||
|
||||
for file_path in self.app.open_files:
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue