-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlnetd_group.py
181 lines (166 loc) · 5.28 KB
/
lnetd_group.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import json
import math
from random import randrange
from PyQt5 import QtCore, QtGui, QtWidgets,sip
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,
QGraphicsItemGroup,
QGraphicsItem
)
from lnetd_node import Rectangle
from utilities import Vector
class LnetdGroup(QGraphicsItemGroup):
def __init__(self,node,scene,label,keepPosition):
super(LnetdGroup, self).__init__()
self.label = label
self.keepPosition = keepPosition
self.setFlag(QGraphicsItemGroup.ItemIsMovable)
#self.setFlag(QGraphicsItemGroup.ItemIsSelectable)
self.setFlag(QtWidgets.QGraphicsItem.ItemSendsGeometryChanges)
#self.setFlag(QtWidgets.QGraphicsItem.ItemSendsScenePositionChanges)
#self.setZValue(0)
self.scene = scene
self.hide = False
self.node_list = {}
#self.setHandlesChildEvents(false)
#self.setFlag(QGraphicsItemGroup.ItemClipsChildrenToShape)
def boundingRect(self):
#return self.childrenBoundingRect()
return self.childrenBoundingRect().adjusted(-25, -25, 25, 25)
def shape1(self):
"""this is the selection area and colision detection"""
path = QtGui.QPainterPath()
path.addRect(
10,10,10,10
)
return path
def paint(self,
painter: QtGui.QPainter,
option: QtWidgets.QStyleOptionGraphicsItem,
widget: QtWidgets.QWidget = None):
img_png = QtGui.QPixmap(":/icons/roadm_selected.png")
painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
painter.setBrush(QtGui.QBrush(QtCore.Qt.gray))
r = self.boundingRect();
#print(r)
#painter.drawRect(QRect(10,10,10,10))
#painter.drawRect(QRect(r.x(), r.y(), r.width(), r.height()))
painter.setPen(QtGui.QPen(QtCore.Qt.black, 1))
if self.hide:
painter.setOpacity(1)
painter.drawPixmap(
QRect(r.x(), r.y(), r.width(), r.height()),
img_png,
)
painter.drawText(
QRect(r.x(), r.y()+r.height() / 3, r.width(), r.height()),
Qt.AlignCenter,
self.label,
)
else:
painter.setOpacity(0.5)
painter.drawPixmap(
QRect(r.x(), r.y(), r.width(), r.height()),
img_png,
)
painter.drawText(
QRect(r.x(), r.y() + r.height() / 3 , r.width(), r.height()),
Qt.AlignCenter,
self.label,
)
def itemChange(self, change, value):
#print('group_change',change)
# change 9 == positionchange
if change == 9:
for item in self.childItems():
pos_br = item.sceneBoundingRect().center()
item.node.set_position(Vector(pos_br.x(), pos_br.y()))
item.prepareGeometryChange()
item.update()
self.scene.update()
# update scene matrix
self.prepareGeometryChange()
#self.scene.update()
#return super(LnetdGroup, self).itemChange(change, value)
return value
def contextMenuEvent(self, event):
self.cmenu = QMenu()
un_group = self.cmenu.addAction("Un-Group")
#topology = self.cmenu.addAction("Show Topology")
if self.hide:
un_hide = self.cmenu.addAction("Un-Hide")
un_hide.setText('Un-hide Nodes')
else:
hide = self.cmenu.addAction("Hide")
hide.setText('Hide Nodes')
action = self.cmenu.exec_(event.screenPos())
if action.text() == 'Un-hide Nodes':
for item in self.childItems():
item.show()
self.hide = False
elif action.text() == 'Hide Nodes':
for item in self.childItems():
item.hide()
self.hide = True
elif action.text() == 'Un-Group':
for item in self.childItems():
self.removeFromGroup(item)
self.scene.removeItem(item)
self.scene.addItem(item)
previousNode = self.node_list.get(item.node.label)
if previousNode and self.keepPosition:
item.setPos(previousNode['posX'],previousNode['posY'])
item.show()
item.prepareGeometryChange()
self.scene.destroyItemGroup(self)
'''
#disabled for now , see comment in main program.
elif action.text() == 'Show Topology':
self.scene.handleGroupActionTopology(
self, "message from group topology")
'''
self.scene.update()
# dont propagate event
super(LnetdGroup, self).contextMenuEvent(event)