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)
56 self._label_pen.setJoinStyle(Qt.RoundJoin)
58 self._ellipse_pen.setWidth(1)
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()
107 self._incoming_edges.add(edge)
110 self._outgoing_edges.add(edge)
116 self._brush.setColor(color)
117 self._ellipse_pen.setColor(color)
118 self._label_pen.setColor(color)
121 self._label.setBrush(self.
_brush)
131 incoming_nodes = set()
132 for incoming_edge
in self._incoming_edges.difference(cyclic_edges):
135 if incoming_edge.from_node != self:
136 incoming_nodes.add(incoming_edge.from_node)
138 outgoing_nodes = set()
139 for outgoing_edge
in self._outgoing_edges.difference(cyclic_edges):
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)