-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlnetd_l1node.py
143 lines (116 loc) · 4.63 KB
/
lnetd_l1node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from graph import Graph
from node import Node
from interface import Interface
from utilities import *
import json
import math
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import Qt, QSize, QTimer, QPointF, QRectF, QMetaObject, QRect , QCoreApplication, QPoint, QLineF , pyqtSlot
from PyQt5.QtGui import QPainter, QBrush, QPen, QFont, QIcon, QTransform, QPalette, QColor
from PyQt5.QtWidgets import (
QApplication,
QWidget,
QVBoxLayout,
QFrame,
QCheckBox,
QHBoxLayout,
QLineEdit,
QPushButton,
QMessageBox,
QFileDialog,
QSizePolicy,
QMenu,
QSlider,
QDialog,
QComboBox,
QLabel,
QSpacerItem,
QMainWindow,
QMenuBar,
QOpenGLWidget
)
from lnetd_link import Link
import resources
class L1NodeItem(QtWidgets.QGraphicsItem):
def __init__(self, node):
super(L1NodeItem, self).__init__(parent=None)
self.icons = False
self.node = node
self.node_position = self.node.get_position()
self.node_radius = Vector(self.node.get_radius()).repeat(2)
self.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable)
self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable)
self.setFlag(QtWidgets.QGraphicsItem.ItemSendsGeometryChanges)
self.setCursor(Qt.ArrowCursor)
#node ontop
self.setZValue(1)
self.grayBrush = QtGui.QBrush(QtCore.Qt.gray)
self.redBrush = QtGui.QBrush(QtCore.Qt.red)
self.whiteBrush = QtGui.QBrush(QtCore.Qt.white)
#self.font_family: str = "Times New Roman"
self.font_family = "Roboto"
self.font_size: int = 18
def shape(self):
"""this is the selection area and colision detection"""
path = QtGui.QPainterPath()
path.addRect(QRectF(*(self.node_position - self.node_radius), *(2 * self.node_radius)))
return path
def boundingRect(self):
return QRectF(*(self.node_position - self.node_radius), *(2 * self.node_radius))
def paint(self, painter, option, widget=None):
#super(L1NodeItem, self).paint(painter, option, widget)
painter.save()
painter.setRenderHints( QtGui.QPainter.Antialiasing
| QtGui.QPainter.TextAntialiasing
| QtGui.QPainter.SmoothPixmapTransform
| QtGui.QPainter.HighQualityAntialiasing, True )
if self.node._failed:
#painter.setBrush(self.redBrush)
img_png = QtGui.QPixmap(":/icons/roadm_down.png")
elif option.state & QtWidgets.QStyle.State_Selected:
#painter.setBrush(self.grayBrush)
img_png = QtGui.QPixmap(":/icons/roadm_selected.png")
else:
#painter.setBrush(self.whiteBrush)
img_png = QtGui.QPixmap(":/icons/roadm.png")
painter.setPen(QtGui.QPen(QtCore.Qt.black, 1))
painter.setFont(QFont(self.font_family, self.font_size / 4))
painter.drawPixmap(QRect(*(self.node_position - self.node_radius), *(2 * self.node_radius)),img_png)
painter.drawText(
QRectF(*(self.node_position - self.node_radius + (-5,25) ), *(2 * self.node_radius + (10,0))),
Qt.AlignCenter,
self.node.label,
)
painter.restore()
def itemChange(self, change, value):
#change 9 == positionchange
if change == 9:
new_pos = self.boundingRect().center() + value
self.node.set_position(Vector(new_pos.x(),new_pos.y() ))
for item in self.scene().items():
if isinstance(item, Link):
if item.link.target == self.node or item.source_node == self.node :
item.updatePosition()
#update scene matrix
self.prepareGeometryChange();
self.update()
#return super(L1NodeItem, self).itemChange(change, value)
return value
def contextMenuEvent(self,event):
scene = self.scene()
cmenu = QMenu()
if not self.node._failed:
fail_node = cmenu.addAction("Node Down")
else:
unfail_node = cmenu.addAction("Node Up")
action = cmenu.exec_(event.screenPos())
if not self.node._failed and action == fail_node:
self.node._failed = True
if scene is not None:
scene.handleNodeActionDown(self, 'this is a message from Node Down GraphicsItem ')
elif self.node._failed and action == unfail_node:
self.node._failed = False
if scene is not None:
scene.handleNodeActionUp(self,'this is a message from Node Up GraphicsItem')
self.update()
super(L1NodeItem, self).contextMenuEvent(event)