Start of the icon editor
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from collections.abc import Callable
|
||||
from functools import partial
|
||||
from typing import Protocol
|
||||
|
||||
from PySide6.QtCore import QObject, QPoint, Qt
|
||||
@@ -9,6 +10,7 @@ from bedit_core.models import Document as CoreDocument
|
||||
from bedit_gui.documents import Document
|
||||
from bedit_gui.views.dialogs.interface_editor_dialog import InterfaceEditorDialog
|
||||
from bedit_gui.views.dialogs.param_editor_dialog import ParamEditorDialog
|
||||
from bedit_gui.views.icon_editor_window import IconEditorWindow
|
||||
from bedit_gui.views.main_window import MainWindow
|
||||
from bedit_gui.views.models.document_tree_model import DocumentTreeModel
|
||||
|
||||
@@ -48,6 +50,7 @@ class DocumentTreeController(QObject):
|
||||
self.model = DocumentTreeModel()
|
||||
self.interface_editor_factory = interface_editor_factory
|
||||
self.param_editor_factory = param_editor_factory
|
||||
self._icon_editors: list[IconEditorWindow] = []
|
||||
|
||||
window.ui.documentTree.setModel(self.model)
|
||||
document.model_changed.connect(self._on_document_changed)
|
||||
@@ -81,6 +84,7 @@ class DocumentTreeController(QObject):
|
||||
menu = QMenu(self.window.ui.documentTree)
|
||||
edit_interface = menu.addAction("Edit Interface")
|
||||
edit_params = menu.addAction("Edit Parameters")
|
||||
edit_icon = menu.addAction("Edit Icon")
|
||||
selected = menu.exec(
|
||||
self.window.ui.documentTree.viewport().mapToGlobal(position)
|
||||
)
|
||||
@@ -88,6 +92,8 @@ class DocumentTreeController(QObject):
|
||||
self._edit_interface(component)
|
||||
elif selected is edit_params:
|
||||
self._edit_params(component)
|
||||
elif selected is edit_icon:
|
||||
self._edit_icon(component)
|
||||
|
||||
def _edit_interface(self, component: Component) -> None:
|
||||
dialog = self.interface_editor_factory(
|
||||
@@ -105,3 +111,14 @@ class DocumentTreeController(QObject):
|
||||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
self.document.update_component_params(component, dialog.params())
|
||||
|
||||
def _edit_icon(self, component: Component) -> None:
|
||||
component_id = self.document.component_id(component)
|
||||
editor = IconEditorWindow(self.document.component_icon(component_id), self.window)
|
||||
editor.saved.connect(partial(self.document.change_icon, component_id))
|
||||
editor.destroyed.connect(partial(self._icon_editor_closed, editor))
|
||||
self._icon_editors.append(editor)
|
||||
editor.show()
|
||||
|
||||
def _icon_editor_closed(self, editor: IconEditorWindow, *_args: object) -> None:
|
||||
if editor in self._icon_editors:
|
||||
self._icon_editors.remove(editor)
|
||||
|
||||
Reference in New Issue
Block a user