31 from __future__
import print_function
35 from python_qt_binding.QtCore
import Qt
36 from python_qt_binding.QtGui
import QBrush, QPainterPath, QPen
37 from python_qt_binding.QtWidgets
import (QGraphicsEllipseItem,
39 QGraphicsSimpleTextItem)
48 self, highlight_level, bounding_box, label, shape, color=None,
49 parent=None, label_pos=None, tooltip=None):
50 super(NodeItem, self).
__init__(highlight_level, parent)
66 self.
_label = QGraphicsSimpleTextItem(label)
67 self.
_label.setFont(GraphItem._LABEL_FONT)
68 label_rect = self.
_label.boundingRect()
70 label_rect.moveCenter(bounding_box.center())
72 label_rect.moveCenter(label_pos)
73 self.
_label.setPos(label_rect.x(), label_rect.y())
74 self.addToGroup(self.
_label)
75 if tooltip
is not None:
76 self.setToolTip(tooltip)
80 self.setAcceptHoverEvents(
True)
85 if shape
in (
'box',
'rect',
'rectangle'):
87 elif shape
in (
'ellipse',
'oval',
'circle'):
89 elif shape
in (
'box3d', ):
92 print(
"Invalid shape '%s', defaulting to ellipse" % shape, file=sys.stderr)
100 path = QPainterPath()
104 return super(self.__class__, self).
shape()
116 self.
_brush.setColor(color)
131 incoming_nodes = set()
135 if incoming_edge.from_node != self:
136 incoming_nodes.add(incoming_edge.from_node)
138 outgoing_nodes = set()
142 if outgoing_edge.to_node != self:
143 outgoing_nodes.add(outgoing_edge.to_node)
145 for edge
in cyclic_edges:
149 cyclic_nodes = incoming_nodes.intersection(outgoing_nodes)
151 for incoming_node
in incoming_nodes.difference(cyclic_nodes):
154 for outgoing_node
in outgoing_nodes.difference(cyclic_nodes):
157 for node
in cyclic_nodes:
164 incoming_edge.set_node_color()
165 incoming_edge.set_label_color()
167 incoming_edge.from_node.set_node_color()
169 outgoing_edge.set_node_color()
170 outgoing_edge.set_label_color()
172 outgoing_edge.to_node.set_node_color()
def add_outgoing_edge(self, edge)
def __init__(self, highlight_level, bounding_box, label, shape, color=None, parent=None, label_pos=None, tooltip=None)
def set_node_color(self, color=None)
def hoverLeaveEvent(self, event)
def set_hovershape(self, newhovershape)
def parse_shape(self, shape, bounding_box)
def add_incoming_edge(self, edge)
def hoverEnterEvent(self, event)