-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_editor_window.py
More file actions
92 lines (63 loc) · 3.16 KB
/
node_editor_window.py
File metadata and controls
92 lines (63 loc) · 3.16 KB
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
from PyQt5.QtWidgets import QWidget, QPushButton, QTextEdit, QGraphicsView, QGraphicsScene, QGraphicsItem
from PyQt5.QtWidgets import QVBoxLayout, QHBoxLayout, QApplication
from PyQt5.QtGui import QColor, QPainter, QPen, QBrush, QFont
from PyQt5.QtCore import Qt, QFile
from node_scene import Scene
from node_graphics_view import customgraphics_view
from node_node import Node
from node_edge import Edge
class NodeEditor_window(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.styleSheet_filename = "qss/nodestyle.qss"
self.loadStylesheet(self.styleSheet_filename)
self.initUI()
def initUI(self):
self.setGeometry(200,200,800,600) # x_offset, y_offset, width, height
self.main_layout = QVBoxLayout()
self.main_layout.setContentsMargins(0,0,0,0) # removes border for the scene in the view-port
self.setLayout(self.main_layout)
# Create graphics scene
self.scene = Scene()
# self.graphicScene = self.screen.graphicScene
self.addNodes()
# Create graphic view
self.view = customgraphics_view(self.scene.graphicScene, self) # Creates a view-port | order of args is 'self' comes last |
# self.view.setScene(self.graphicScene) # add a scence inside in the view-port
self.main_layout.addWidget(self.view)
self.setWindowTitle("PyBlocks")
self.show()
# self.addDebugContent()
def addNodes(self):
node1 = Node(self.scene, "Node 1", inputs = [1, 2, 3], outputs=[1])
node2 = Node(self.scene, "Node 2", inputs = [1, 2, 3], outputs=[1])
node3 = Node(self.scene, "Node 3", inputs = [1, 2, 3], outputs=[1])
node1.setPos(-350, -250)
node2.setPos(-75, 0)
node3.setPos(200, -150)
edge1 = Edge(self.scene, node1.outputs[0], node2.inputs[1])
edge2 = Edge(self.scene, node2.outputs[0], node3.inputs[1], type=2)
def addDebugContent(self):
greenBrush = QBrush(Qt.green)
outlinePen = QPen(Qt.black)
outlinePen.setWidth(2) # 2 px
rect = self.graphicScene.addRect(-100, -100, 80, 100, outlinePen, greenBrush) # addRect takes location
rect.setFlag(QGraphicsItem.ItemIsMovable) # makes rect moveable by mouse
text = self.graphicScene.addText("This is test text", QFont("Arial"))
text.setFlag(QGraphicsItem.ItemIsSelectable)
text.setFlag(QGraphicsItem.ItemIsMovable)
text.setDefaultTextColor(QColor.fromRgbF(1.0, 1.0,1.0))
widget1 = QPushButton("Widget1")
proxy1 = self.graphicScene.addWidget(widget1)
proxy1.setFlag(QGraphicsItem.ItemIsMovable)
proxy1.setPos(0,30)
widget2 = QTextEdit("Widget1")
proxy2 = self.graphicScene.addWidget(widget2)
proxy2.setFlag(QGraphicsItem.ItemIsSelectable)
proxy2.setPos(0,60)
def loadStylesheet(self, file_name):
print("Style loading:", file_name)
file = QFile(file_name)
file.open(QFile.ReadOnly | QFile.Text)
stylesheet = file.readAll()
QApplication.instance().setStyleSheet(str(stylesheet, encoding="utf-8"))