Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
- Pretty name replaced by the typical __str__ method
- added a generate_name function in utils
  • Loading branch information
HeftyCoder committed Dec 4, 2023
1 parent e67e06b commit e08369d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 39 deletions.
16 changes: 2 additions & 14 deletions ryvencore-qt/ryvencore_qt/src/GUIBase.py
Original file line number Diff line number Diff line change
@@ -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"""

Expand Down Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions ryvencore-qt/ryvencore_qt/src/flows/FlowCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
QGraphicsObject,
)

from ...GUIBase import GUIBase, PrettyName, QGraphicsItemWrapper
from ...GUIBase import GUIBase, QGraphicsItemAnimated
from ...utils import sqrt
from ...utils import pythagoras

from ...flows.nodes.PortItem import PortItem

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."""
Expand Down Expand Up @@ -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})'

Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions ryvencore-qt/ryvencore_qt/src/flows/drawings/DrawingObject.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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):

Expand Down
11 changes: 5 additions & 6 deletions ryvencore-qt/ryvencore_qt/src/flows/nodes/NodeItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion ryvencore-qt/ryvencore_qt/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit e08369d

Please sign in to comment.