diff --git a/ryvencore-qt/ryvencore_qt/src/GUIBase.py b/ryvencore-qt/ryvencore_qt/src/GUIBase.py index f9f0da39..0adbcf84 100644 --- a/ryvencore-qt/ryvencore_qt/src/GUIBase.py +++ b/ryvencore-qt/ryvencore_qt/src/GUIBase.py @@ -1,19 +1,7 @@ -import typing from ryvencore.Base import Base -from qtpy.QtCore import QPropertyAnimation from qtpy.QtWidgets import QGraphicsObject, QGraphicsItem -class PrettyName: - """Interface for representing an object by string""" - - @staticmethod - def generate_name(obj, name: str, detail: bool): - return f'{name}:[{id(obj)}]' if detail else name - - def pretty_name(self, detail: bool = False): - """abstract function for name inspection""" - pass - + class GUIBase: """Base class for GUI items that represent specific core components""" @@ -70,7 +58,7 @@ def on_move(self): pass # if the __doc__ is incorrect, this class should be removed -class QGraphicsItemWrapper(QGraphicsObject): +class QGraphicsItemAnimated(QGraphicsObject): """ Serves as a proxy for animating any kind fo QGraphicsItem. This was created because there is no apparent way to animate diff --git a/ryvencore-qt/ryvencore_qt/src/flows/FlowCommands.py b/ryvencore-qt/ryvencore_qt/src/flows/FlowCommands.py index a56b97fa..46bf036e 100644 --- a/ryvencore-qt/ryvencore_qt/src/flows/FlowCommands.py +++ b/ryvencore-qt/ryvencore_qt/src/flows/FlowCommands.py @@ -12,7 +12,6 @@ from ryvencore.NodePort import NodePort, NodeInput, NodeOutput from ryvencore.Flow import Flow from .connections.ConnectionItem import ConnectionItem -from ..GUIBase import PrettyName def undo_text_multi(items:list, command: str, get_text=None): """Generates a text for an undo command that has zero, one or multiple items""" @@ -28,7 +27,7 @@ def undo_text_multi(items:list, command: str, get_text=None): def get_text_default(obj): """Default function for the undo text""" - return obj.pretty_name(True) if isinstance(obj, PrettyName) else str(obj) + return f'{obj}' class FlowUndoCommand(QObject, QUndoCommand): """ @@ -150,7 +149,7 @@ def redo_(self): self.flow.add_node(self.node) else: self.node = self.flow.create_node(self.node_class) - self.setText(f'Create {self.node.gui.item.pretty_name(True)}') + self.setText(f'Create {self.node.gui.item}') class PlaceDrawing_Command(FlowUndoCommand): @@ -172,7 +171,7 @@ def undo_(self): def redo_(self): self.flow_view.add_drawing(self.drawing, self.drawing_obj_pos) - self.setText(self.drawing.pretty_name(True)) + self.setText(self.drawing(True)) class SelectComponents_Command(FlowUndoCommand): def __init__(self, flow_view, new_items, prev_items): @@ -320,11 +319,11 @@ def redo_(self): else: # connection hasn't been created yet self.connection = self.flow.connect_nodes(self.out, self.inp) - self.setText(f'Connect {self.flow_view.connection_items[self.connection].pretty_name(True)}') + self.setText(f'Connect {self.flow_view.connection_items[self.connection]}') else: # remove existing connection - self.setText(f'Disconnect {self.flow_view.connection_items[self.connection].pretty_name(True)}') + self.setText(f'Disconnect {self.flow_view.connection_items[self.connection]}') self.flow.remove_connection(self.connection) diff --git a/ryvencore-qt/ryvencore_qt/src/flows/connections/ConnectionItem.py b/ryvencore-qt/ryvencore_qt/src/flows/connections/ConnectionItem.py index dea1cdb8..6d0b2f00 100644 --- a/ryvencore-qt/ryvencore_qt/src/flows/connections/ConnectionItem.py +++ b/ryvencore-qt/ryvencore_qt/src/flows/connections/ConnectionItem.py @@ -10,7 +10,7 @@ QGraphicsObject, ) -from ...GUIBase import GUIBase, PrettyName, QGraphicsItemWrapper +from ...GUIBase import GUIBase, QGraphicsItemAnimated from ...utils import sqrt from ...utils import pythagoras @@ -18,7 +18,7 @@ from enum import Enum -class ConnectionItem(GUIBase, PrettyName, QGraphicsPathItem): +class ConnectionItem(GUIBase, QGraphicsPathItem): """The GUI representative for a connection. The classes ExecConnectionItem and DataConnectionItem will be ready for reimplementation later, so users can add GUI for the enhancements of DataConnection and ExecConnection, like input fields for weights.""" @@ -57,11 +57,11 @@ def __init__(self, connection, session_design): self.recompute() - def pretty_name(self, detail: bool = False): + def __str__(self): out, inp = self.connection - node_in_name = inp.node.gui.item.pretty_name(detail) + node_in_name = f'{inp.node.gui.item}' node_in_index = inp.node.inputs.index(inp) - node_out_name = out.node.gui.item.pretty_name(detail) + node_out_name = f'{out.node.gui.item}' node_out_index = out.node.outputs.index(out) return f'{node_out_index}->{node_in_index} ({node_out_name}, {node_in_name})' @@ -280,7 +280,7 @@ def __init__( ): super().__init__() - self.items:List[QGraphicsItemWrapper] = [QGraphicsItemWrapper(item, self) for item in items] + self.items:List[QGraphicsItemAnimated] = [QGraphicsItemAnimated(item, self) for item in items] self.connection = connection self._frames = frames self._duration = duration diff --git a/ryvencore-qt/ryvencore_qt/src/flows/drawings/DrawingObject.py b/ryvencore-qt/ryvencore_qt/src/flows/drawings/DrawingObject.py index c4ee70c2..4ccc711d 100644 --- a/ryvencore-qt/ryvencore_qt/src/flows/drawings/DrawingObject.py +++ b/ryvencore-qt/ryvencore_qt/src/flows/drawings/DrawingObject.py @@ -1,11 +1,9 @@ from qtpy.QtWidgets import QGraphicsItem from qtpy.QtGui import QPen, QPainter, QColor, QPainterPath from qtpy.QtCore import Qt, QRectF, QPointF, QLineF -from ....src.GUIBase import PrettyName -from ...utils import MovementEnum +from ...utils import MovementEnum, generate_name - -class DrawingObject(QGraphicsItem, PrettyName): +class DrawingObject(QGraphicsItem): """GUI implementation for 'drawing objects' in the scene, written by hand using a stylus pen""" def __init__(self, flow_view, load_data=None): @@ -56,8 +54,8 @@ def __init__(self, flow_view, load_data=None): self.color = QColor(load_data['color']) self.base_stroke_weight = load_data['base stroke weight'] - def pretty_name(self, detail: bool = False): - return PrettyName.generate_name(self, 'Drawing', detail) + def __str__(self): + return generate_name(self, 'Drawing') def paint(self, painter, option, widget=None): diff --git a/ryvencore-qt/ryvencore_qt/src/flows/nodes/NodeItem.py b/ryvencore-qt/ryvencore_qt/src/flows/nodes/NodeItem.py index 9ff5a6e8..25c173b4 100644 --- a/ryvencore-qt/ryvencore_qt/src/flows/nodes/NodeItem.py +++ b/ryvencore-qt/ryvencore_qt/src/flows/nodes/NodeItem.py @@ -7,17 +7,16 @@ from .NodeErrorIndicator import NodeErrorIndicator from .NodeGUI import NodeGUI -from ...GUIBase import GUIBase, PrettyName +from ...GUIBase import GUIBase from ryvencore.NodePort import NodeInput, NodeOutput from .NodeItemAction import NodeItemAction from .NodeItemAnimator import NodeItemAnimator from .NodeItemWidget import NodeItemWidget from .PortItem import InputPortItem, OutputPortItem -from ...utils import serialize, deserialize -from ...utils import MovementEnum +from ...utils import serialize, deserialize, MovementEnum, generate_name -class NodeItem(GUIBase, PrettyName, QGraphicsObject): # QGraphicsItem, QObject): +class NodeItem(GUIBase, QGraphicsObject): # QGraphicsItem, QObject): """The GUI representative for nodes. Unlike the Node class, this class is not subclassed individually and works the same for every node.""" @@ -133,10 +132,10 @@ def initialize(self): self.update() # ... not sure if I need that - def pretty_name(self, detail: bool = False): + def __str__(self): name = self.node.__class__.title if self.node else f'{NodeItem.__name__}' obj = self.node if self.node else self - return PrettyName.generate_name(self, name, detail) + return generate_name(obj, name) # UI STUFF diff --git a/ryvencore-qt/ryvencore_qt/src/utils.py b/ryvencore-qt/ryvencore_qt/src/utils.py index e0ba074b..e0d3d89a 100644 --- a/ryvencore-qt/ryvencore_qt/src/utils.py +++ b/ryvencore-qt/ryvencore_qt/src/utils.py @@ -10,7 +10,9 @@ from ryvencore.utils import serialize, deserialize from .GlobalAttributes import * - +def generate_name(obj, name): + return f'{name}:[{id(obj)}]' + def pythagoras(a, b): return sqrt(a ** 2 + b ** 2)