Made the font background of ones orange.
This commit is contained in:
parent
df0cce9060
commit
2317aeeea5
2 changed files with 28 additions and 1 deletions
9
file.py
9
file.py
|
@ -1,8 +1,9 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from PyQt6.QtWidgets import QWidget, QFileDialog, QVBoxLayout
|
||||
from PyQt6.QtGui import QFont
|
||||
from PyQt6.QtGui import QFont, QTextCharFormat, QColor
|
||||
from binary_text_edit import BinaryTextEdit
|
||||
from highlighting import Higlighter
|
||||
|
||||
|
||||
class FileActions:
|
||||
|
@ -89,6 +90,12 @@ class File:
|
|||
self.content_binary_input.setFont(QFont("Ubuntu Mono", 12))
|
||||
self.content_binary_input.textChanged.connect(self.on_edit)
|
||||
|
||||
self.bit_highlighter = Higlighter()
|
||||
self.one_format = QTextCharFormat()
|
||||
self.one_format.setBackground(QColor(200, 150, 100))
|
||||
self.bit_highlighter.add_mapping("1", self.one_format)
|
||||
self.bit_highlighter.setDocument(self.content_binary_input.document())
|
||||
|
||||
self.content_widget.setLayout(self.content_widget_layout)
|
||||
|
||||
self.app.main_window.openFileTabs.addTab( # add a tab for the file in the top files list
|
||||
|
|
20
highlighting.py
Normal file
20
highlighting.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import re
|
||||
from PyQt6.QtGui import QSyntaxHighlighter
|
||||
|
||||
|
||||
class Higlighter(QSyntaxHighlighter):
|
||||
def __init__(self, parent=None):
|
||||
QSyntaxHighlighter.__init__(self, parent)
|
||||
|
||||
self.mappings = {}
|
||||
|
||||
def add_mapping(self, pattern, format):
|
||||
self.mappings[pattern] = format
|
||||
|
||||
def highlightBlock(self, text):
|
||||
for pattern, format in self.mappings.items():
|
||||
for match in re.finditer(pattern, text):
|
||||
start, end = match.span()
|
||||
self.setFormat(start, end - start, format)
|
Loading…
Reference in a new issue