29 lines
748 B
Python
29 lines
748 B
Python
|
|
"""Tool Supporting Basic Editor Functions"""
|
||
|
|
from typing import cast, Protocol
|
||
|
|
from PySide6.QtWidgets import QTextEdit, QVBoxLayout
|
||
|
|
|
||
|
|
import trovedb.trove as tr
|
||
|
|
from .tool import Tool
|
||
|
|
|
||
|
|
|
||
|
|
class ToolBasicEditor(Tool):
|
||
|
|
def __init__(self, note, parent=None):
|
||
|
|
super().__init__(note, parent)
|
||
|
|
|
||
|
|
layout = QVBoxLayout(self)
|
||
|
|
layout.setContentsMargins(0, 0, 0, 0)
|
||
|
|
layout.setSpacing(0)
|
||
|
|
|
||
|
|
self._text_edit = QTextEdit()
|
||
|
|
layout.addWidget(self._text_edit)
|
||
|
|
self.refresh()
|
||
|
|
|
||
|
|
def _refresh_blob(self, note: tr.Blob):
|
||
|
|
self._text_edit.setPlainText(note.read().decode("utf-8"))
|
||
|
|
|
||
|
|
def refresh(self):
|
||
|
|
if isinstance(self.note, tr.Blob):
|
||
|
|
self._refresh_blob(cast(tr.Blob, self.note))
|
||
|
|
|
||
|
|
|