-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_editor_wnd.py
More file actions
111 lines (90 loc) · 3.61 KB
/
node_editor_wnd.py
File metadata and controls
111 lines (90 loc) · 3.61 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from node_graphics_scene import QDMGraphicsScene
from node_graphics_view import QDMGraphicsView
from node_scene import Scene
from node_node import Node
from node_edge import Edge
from node_console import ConsoleLog
from ui import UI
from random import randint
from Node_Types import *
import glob, os
DEBUG = False
class NodeEditorWnd(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.loadStylesheet("qss/nodestyle.qss")
self.initUI()
def initUI(self):
self.setGeometry(0, 0, 800, 600)
self.layout = QVBoxLayout()
self.layout.setContentsMargins(0,0,0,0)
self.setLayout(self.layout)
self.console = ConsoleLog()
# create Graphics Scene
self.scene = Scene(self.console)
self.addNodes()
# self.addUI()
# create Graphics View
self.view = QDMGraphicsView(self.console, self.scene.grScene, self)
self.layout.addWidget(self.view)
nodetypes = self._getNodeTypes()
self.uiwidget = UI(self.scene, nodetypes)
self.layout.addWidget(self.uiwidget.graphics)
self.setWindowTitle("Node Editor")
self.show()
def __str__(self):
return "NodeEditorWnd"
def _getNodeTypes(self):
os.chdir("./Node_Types")
nodeTypeList = []
for file in glob.glob("*.py"):
if file != '__init__.py':
file = file[:-3]
nodeTypeList.append(file)
return nodeTypeList
# Function for testing nodes
def addNodes(self):
scene = self.scene
node1 = Node(scene, "New Node 1")
node2 = Node(scene, "New Node 2")
node3 = Integer.NT_Integer(scene)
node4 = Printer.NT_Printer(scene)
node1.setPos(randint(-400, 400), randint(-400, 400))
node2.setPos(randint(-400, 400), randint(-400, 400))
node3.setPos(randint(-400, 400), randint(-400, 400))
node4.setPos(randint(-400, 400), randint(-400, 400))
def addDebugContent(self):
greenBrush = QBrush(Qt.green)
outlinePen = QPen(Qt.black)
outlinePen.setWidth(2)
graphicalScene = self.scene.grScene
rect = graphicalScene.addRect(-100,-100, 80, 80, outlinePen, greenBrush)
rect.setFlag(QGraphicsItem.ItemIsMovable)
rect.setFlag(QGraphicsItem.ItemIsSelectable)
text = graphicalScene.addText("TEXT HERE")
text.setFlag(QGraphicsItem.ItemIsSelectable)
text.setPos(-200, -300)
text.setFlag(QGraphicsItem.ItemIsMovable)
text.setDefaultTextColor(QColor.fromRgbF(1.0, 1.0, 1.0, 0.5))
widget1 = QPushButton("Hello World")
proxy1 = graphicalScene.addWidget(widget1)
proxy1.setPos(0, -30)
proxy1.setFlag(QGraphicsItem.ItemIsMovable)
proxy1.setFlag(QGraphicsItem.ItemIsSelectable)
widget2 = QTextEdit()
proxy2 = graphicalScene.addWidget(widget2)
proxy2.setFlag(QGraphicsItem.ItemIsMovable)
proxy2.setFlag(QGraphicsItem.ItemIsSelectable)
proxy2.setPos = (0, -60)
line = graphicalScene.addLine(-200,-100,400,200,outlinePen)
line.setFlag(QGraphicsItem.ItemIsMovable)
line.setFlag(QGraphicsItem.ItemIsSelectable)
def loadStylesheet(self, filename):
print("STYLE LOADING: " + filename)
file = QFile(filename)
file.open(QFile.ReadOnly | QFile.Text)
stylesheet = file.readAll()
QApplication.instance().setStyleSheet(str(stylesheet, encoding='utf-8'))