46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
#!/usr/bin/python3
|
|
|
|
from PyQt6.QtWidgets import QWidget, QVBoxLayout
|
|
from PyQt6.QtGui import QFont, QTextCharFormat, QColor
|
|
from binary_text_edit import BinaryTextEdit
|
|
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))
|
|
|
|
def __init__(self, app, file):
|
|
self.app = app
|
|
self.file = file
|
|
|
|
self.setup_gui()
|
|
|
|
def setup_gui(self):
|
|
# widget that contains the text input
|
|
self.widget = QWidget(self.app.gui.main_window.openFileTabs, objectName=self.file.path)
|
|
self.widget_layout = QVBoxLayout()
|
|
|
|
self.input = BinaryTextEdit()
|
|
self.input.setOverwriteMode(True)
|
|
self.widget_layout.addWidget(self.input)
|
|
self.input.setPlainText(self.app.utils.bstring_to_oz(self.file.content))
|
|
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.widget.setLayout(self.widget_layout)
|
|
|
|
self.tab_index = self.app.gui.main_window.openFileTabs.addTab( # add a tab for the file in the top files list
|
|
self.widget,
|
|
self.file.name
|
|
)
|
|
|
|
def on_edit(self):
|
|
self.not_saved = True
|