33 lines
965 B
Python
33 lines
965 B
Python
|
|
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
|