20 lines
588 B
Python
20 lines
588 B
Python
#!/usr/bin/python3
|
|
|
|
from PyQt6.QtWidgets import QPlainTextEdit
|
|
|
|
|
|
class BinaryTextEdit(QPlainTextEdit): # rewrite QPlainTextEdit.keyPressEvent because it has no .setValidator()
|
|
def keyPressEvent(self, event):
|
|
allowed_keys = {"", "0", "1"}
|
|
|
|
if event.text() in allowed_keys:
|
|
cursor = self.textCursor()
|
|
pos = cursor.position()
|
|
|
|
if (pos + 1) % 9 == 0 and event.text() not in {'', None}: # dont overwrite the separator character
|
|
return
|
|
|
|
super().keyPressEvent(event)
|
|
|
|
else:
|
|
event.ignore()
|