Skip to content

Commit

Permalink
rework inspector mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-thomm committed Dec 4, 2023
1 parent e08369d commit 51e8c6e
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 208 deletions.
Empty file.
22 changes: 22 additions & 0 deletions ryven-editor/ryven/example_nodes/inspector_example/gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from ryven.gui_env import *
from qtpy.QtWidgets import (
QWidget,
QVBoxLayout,
QLabel,
)
from .nodes import MyNode


class MyNodeInspector(NodeInspectorWidget, QWidget):
def __init__(self, params):
NodeInspectorWidget.__init__(self, params)
QWidget.__init__(self)

self.setLayout(QVBoxLayout())
self.layout().addWidget(QLabel('This is a custom inspector for MyNode.'))


@node_gui(MyNode)
class MyNodeGui(NodeGUI):
inspector_widget_class = MyNodeInspector
wrap_inspector_in_default = True
14 changes: 14 additions & 0 deletions ryven-editor/ryven/example_nodes/inspector_example/nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from ryven.node_env import *


class MyNode(Node):
title = 'My Node'


export_nodes(
[MyNode],
)

@on_gui_load
def on_load():
from . import gui
4 changes: 2 additions & 2 deletions ryven-editor/ryven/gui/flow_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from ryven.gui.code_editor.CodePreviewWidget import CodePreviewWidget
from ryven.gui.uic.ui_flow_window import Ui_FlowWindow
from ryvencore_qt.src.flows.FlowView import FlowView
from ryvencore_qt.src.flows.nodes.InspectorGUI import BaseNodeInspector, InspectorWidget
from ryvencore_qt.src.flows.nodes.NodeInspector import InspectorView
from typing import List


Expand Down Expand Up @@ -94,7 +94,7 @@ def __init__(self, main_window, flow: Flow, flow_view: FlowView):
self.ui.source_dock.setWidget(self.code_preview_widget)

# inspector widget
self.inspector_widget = InspectorWidget(self.flow_view)
self.inspector_widget = InspectorView(self.flow_view)
self.ui.inspector_dock.setWidget(self.inspector_widget)

#undo history widget
Expand Down
32 changes: 5 additions & 27 deletions ryven-editor/ryven/main/packages/gui_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
This module automatically imports all requirements for Gui definitions of a nodes package.
"""

import inspect
from typing import Type

import ryven.gui.std_input_widgets as inp_widgets

from ryvencore_qt import NodeInputWidget, NodeMainWidget, NodeGUI, BaseNodeInspector

from ryvencore import Data, Node, serialize, deserialize
from ryvencore.InfoMsgs import InfoMsgs

from ryvencore_qt import NodeInputWidget, NodeMainWidget, NodeGUI, NodeInspectorWidget

import ryven.gui.std_input_widgets as inp_widgets
from ryven.main.utils import in_gui_mode


__explicit_nodes: set = set() # for protection against setting the gui twice on the same node
__explicit_inspectors: set = set() # same as above

def init_node_guis_env():
pass
Expand Down Expand Up @@ -63,24 +62,3 @@ def register_gui(gui_cls: Type[NodeGUI]):
return gui_cls

return register_gui



def inspector_gui(node_cls: Type[Node]):
"""
Registers an inspector for a node class.
"""
if not issubclass(node_cls, Node):
raise Exception(f"{node_cls} is not of type {Node}")

def register_inspector(inspect_cls: Type[BaseNodeInspector]):
if node_cls in __explicit_inspectors:
InfoMsgs.write(f'{node_cls.__name__} has defined an explicit inspector {node_cls.inspector.__name__}')
return

node_cls.inspector = inspect_cls
__explicit_inspectors.add(inspect_cls)
InfoMsgs.write(f"Registered node inspector: {node_cls} for {inspect_cls}")
return inspect_cls

return register_inspector
3 changes: 1 addition & 2 deletions ryvencore-qt/ryvencore_qt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@

from .src.SessionGUI import SessionGUI
from .src.flows.nodes.NodeGUI import NodeGUI
from .src.flows.nodes.InspectorGUI import BaseNodeInspector, NodeInspector

# customer base classes
from ryvencore import Node
from .src.flows.nodes.WidgetBaseClasses import NodeMainWidget, NodeInputWidget
from .src.flows.nodes.WidgetBaseClasses import NodeMainWidget, NodeInputWidget, NodeInspectorWidget

# gui classes
from .src.widgets import *
Expand Down
6 changes: 3 additions & 3 deletions ryvencore-qt/ryvencore_qt/src/flows/FlowCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
This file contains the implementations of undoable actions for FlowView.
"""

from typing import Tuple

from qtpy.QtCore import QObject, QPointF
from qtpy.QtWidgets import QUndoCommand

from ryvencore.Flow import Flow

from .drawings.DrawingObject import DrawingObject
from .nodes.NodeItem import NodeItem
from typing import Tuple
from ryvencore.NodePort import NodePort, NodeInput, NodeOutput
from ryvencore.Flow import Flow
from .connections.ConnectionItem import ConnectionItem

def undo_text_multi(items:list, command: str, get_text=None):
Expand Down
172 changes: 0 additions & 172 deletions ryvencore-qt/ryvencore_qt/src/flows/nodes/InspectorGUI.py

This file was deleted.

19 changes: 17 additions & 2 deletions ryvencore-qt/ryvencore_qt/src/flows/nodes/NodeGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

from qtpy.QtCore import QObject, Signal

from .WidgetBaseClasses import NodeMainWidget, NodeInputWidget, NodeInspectorWidget
from .NodeInspector import NodeInspectorDefaultWidget


class NodeGUI(QObject):
"""
Expand All @@ -11,9 +14,11 @@ class NodeGUI(QObject):

# customizable gui attributes
description_html: str = None
main_widget_class: list = None
main_widget_class: Optional[NodeMainWidget] = None
main_widget_pos: str = 'below ports'
input_widget_classes: dict = {}
input_widget_classes: Dict[str, NodeInputWidget] = {}
inspector_widget_class: NodeInspectorWidget = NodeInspectorDefaultWidget
wrap_inspector_in_default: bool = False
init_input_widgets: dict = {}
style: str = 'normal'
color: str = '#c69a15'
Expand Down Expand Up @@ -62,6 +67,16 @@ def __init__(self, params):
self.node.input_removed.sub(self._on_input_removed)
self.node.output_removed.sub(self._on_output_removed)

# create the inspector widget
inspector_params = (self.node, self)
if self.wrap_inspector_in_default:
self.inspector_widget = NodeInspectorDefaultWidget(
child=self.inspector_widget_class((self.node, self)),
params=inspector_params,
)
else:
self.inspector_widget = self.inspector_widget_class(inspector_params)

def initialized(self):
"""
*VIRTUAL*
Expand Down
Loading

0 comments on commit 51e8c6e

Please sign in to comment.