Simple text editor for basic notes
This commit is contained in:
parent
bd4d571c95
commit
160de4c526
5 changed files with 96 additions and 15 deletions
32
trovedb/qgui/note_tool_stack.py
Normal file
32
trovedb/qgui/note_tool_stack.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from typing import Generator
|
||||
|
||||
from PySide6.QtCore import Property, Slot
|
||||
from PySide6.QtWidgets import QStackedWidget, QWidget, QLabel
|
||||
|
||||
import trovedb.trove as tr
|
||||
|
||||
from .tool import Tool
|
||||
from .tool_basic_editor import ToolBasicEditor
|
||||
|
||||
|
||||
class NoteToolStack(QStackedWidget):
|
||||
def __init__(self, parent: QWidget | None = None):
|
||||
super().__init__(parent)
|
||||
self.setContentsMargins(0, 0, 0, 0)
|
||||
self.addWidget(QLabel("No note selected"))
|
||||
|
||||
@Slot(object)
|
||||
def onNoteSelected(self, note: tr.Note):
|
||||
for tool in self._iter_tools():
|
||||
if tool.note == note:
|
||||
self.setCurrentWidget(tool)
|
||||
return
|
||||
tool = ToolBasicEditor(note)
|
||||
self.addWidget(tool)
|
||||
self.setCurrentWidget(tool)
|
||||
|
||||
def _iter_tools(self) -> Generator[Tool, None, None]:
|
||||
for i in range(self.count()):
|
||||
widget = self.widget(i)
|
||||
if isinstance(widget, Tool):
|
||||
yield widget
|
||||
Loading…
Add table
Add a link
Reference in a new issue