Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions NodeGraphQt/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
# === ITEM CACHE MODE ===

# QGraphicsItem.NoCache
# QGraphicsItem.ItemCoordinateCache
# QGraphicsItem.DeviceCoordinateCache
# QGraphicsItem.ItemCoordinateCache

ITEM_CACHE_MODE = QtWidgets.QGraphicsItem.ItemCoordinateCache
ITEM_CACHE_MODE = QtWidgets.QGraphicsItem.DeviceCoordinateCache
2 changes: 1 addition & 1 deletion NodeGraphQt/widgets/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def _set_viewer_zoom(self, value, sensitivity=None, pos=None):
self.scale(scale, scale, pos)

def _set_viewer_pan(self, pos_x, pos_y):
speed = self._scene_range.width() * 0.001
speed = self._scene_range.width() * 0.002
x = -pos_x * speed
y = -pos_y * speed
self._scene_range.adjust(x, y, x, y)
Expand Down
8 changes: 5 additions & 3 deletions example_auto_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ def GetNodesFromFolder(FolderPath):
return nodes


def cook_node(graph,node):
def cook_node(graph, node):
node.cook()


def print_functions(graph,node):
def print_functions(graph, node):
for func in node.module_functions:
print(func)

def toggle_auto_cook(graph,node):

def toggle_auto_cook(graph, node):
node.autoCook = not node.autoCook


if __name__ == '__main__':
app = QtWidgets.QApplication([])

Expand Down
8 changes: 5 additions & 3 deletions example_auto_nodes/basic_nodes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from .node_base.auto_node import AutoNode


class FooNode(AutoNode):
"""
A node class with 2 inputs and 2 outputs.
"""

# unique node identifier.
__identifier__ = 'com.chantasticvfx'
__identifier__ = 'examples'

# initial default node name.
NODE_NAME = 'foo node'
Expand All @@ -21,7 +22,8 @@ def __init__(self):
# create node outputs.
self.add_output('out A')
self.add_output('out B')
self.set_icon("example_auto_nodes/pear.png")
self.set_icon("example_auto_nodes/icons/pear.png")


class BarNode(AutoNode):
"""
Expand All @@ -30,7 +32,7 @@ class BarNode(AutoNode):
"""

# unique node identifier.
__identifier__ = 'com.chantasticvfx'
__identifier__ = 'examples'

# initial default node name.
NODE_NAME = 'bar'
Expand Down
44 changes: 27 additions & 17 deletions example_auto_nodes/data_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@ class VectorSplit(AutoNode):

def __init__(self):
super(VectorSplit, self).__init__()
self.defaultValue = [0.0, 0.0, 0.0]

self.add_output('x')
self.create_property("x", self.defaultValue[0])
self.create_property("x", 0.0)
self.add_output('y')
self.create_property("y", self.defaultValue[1])
self.create_property("y", 0.0)
self.add_output('z')
self.create_property("z", self.defaultValue[2])
self.create_property("z", 0.0)
self.add_output('w')
self.create_property("w", 0.0)

self.add_input("in vector",list)
self.add_input("in vector", list)
self.map = {0: "x", 1: "y", 2: "z", 3: "w"}

def run(self):
value = self.getInputData(0)
self.set_property("x", value[0])
self.set_property("y", value[1])
self.set_property("z", value[2])
if type(value) is not list:
self.error("Input data not list")
for index, data in enumerate(value):
if index > 3:
return
self.set_property(self.map[index], data)


class VectorMaker(AutoNode):
Expand All @@ -42,17 +47,22 @@ class VectorMaker(AutoNode):
def __init__(self):
super(VectorMaker, self).__init__()

self.add_output('out')
self.create_property("out", [0, 0, 0])

self.add_input("x",float)
self.add_input("y",float)
self.add_input("z",float)
self.add_output('out', list)
self.create_property("out",None)

self.defaultValue = 0.0
self.add_input("x", float)
self.add_input("y", float)
self.add_input("z", float)
self.add_input("w", float)

def run(self):
self.set_property("out", [self.getInputData(0), self.getInputData(1), self.getInputData(2)])
result = []
for i in range(4):
data = self.getInputData(i)
if data is not None:
result.append(data)

self.set_property("out", result)


class DataConvect(AutoNode):
Expand All @@ -67,7 +77,7 @@ def __init__(self):
super(DataConvect, self).__init__()

self.add_output('out')
self.create_property("out",None)
self.create_property("out", None)
self.add_input("in data")

items = ["all to int"]
Expand Down
Binary file added example_auto_nodes/icons/numpy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
32 changes: 24 additions & 8 deletions example_auto_nodes/input_nodes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from NodeGraphQt import QtCore
from NodeGraphQt.constants import (NODE_PROP_VECTOR2,
NODE_PROP_VECTOR3,
NODE_PROP_VECTOR4,
NODE_PROP_SLIDER)
NODE_PROP_VECTOR4)

from .node_base.auto_node import AutoNode
import os
Expand All @@ -19,7 +18,7 @@ class FloatInputNode(AutoNode):
def __init__(self):
super(FloatInputNode, self).__init__()
self.output = self.add_output('out', float)
self.add_float_input('out', 'Float Value', value=0.0,range=(-10,10))
self.add_float_input('out', 'Float Value', value=0.0, range=(-10, 10))


class IntInputNode(AutoNode):
Expand All @@ -44,7 +43,7 @@ def __init__(self):
super(Vector2InputNode, self).__init__()
self.output = self.add_output('out', list)
self.create_property(
"out", [0, 0], widget_type=NODE_PROP_VECTOR2)
"out", [0.0, 0.0], widget_type=NODE_PROP_VECTOR2)


class Vector3InputNode(AutoNode):
Expand All @@ -55,7 +54,7 @@ def __init__(self):
super(Vector3InputNode, self).__init__()
self.output = self.add_output('out', list)
self.create_property(
"out", [0, 0, 0], widget_type=NODE_PROP_VECTOR3)
"out", [0.0, 0.0, 0.0], widget_type=NODE_PROP_VECTOR3)


class Vector4InputNode(AutoNode):
Expand All @@ -66,7 +65,7 @@ def __init__(self):
super(Vector4InputNode, self).__init__()
self.output = self.add_output('out', list)
self.create_property(
"out", [0, 0, 0, 0], widget_type=NODE_PROP_VECTOR4)
"out", [0.0, 0.0, 0.0, 0.0], widget_type=NODE_PROP_VECTOR4)


class TickTimeNode(AutoNode):
Expand Down Expand Up @@ -106,7 +105,6 @@ def __init__(self):
self.add_output('file content', str)
self.create_property('file content', "")
self.add_output('file path', str)

self.add_file_input('file path', 'File Path')

def run(self):
Expand All @@ -119,7 +117,7 @@ def run(self):
except Exception as e:
self.error(e)
else:
self.error('No existe %s' % path)
self.error('No exist %s' % path)
self.set_property('file content', '')


Expand All @@ -142,3 +140,21 @@ def __init__(self):

# create QLineEdit text input widget.
self.add_text_input('out', 'Text Input')


class BoolInputNode(AutoNode):
"""
Input Bool data.
"""

__identifier__ = 'Inputs'
NODE_NAME = 'Bool'

def __init__(self):
super(BoolInputNode, self).__init__()
self.add_output('out', bool)
self.create_property('out', True)
self.add_combo_menu('combo', 'Bool value', items=['True', 'False'])

def run(self):
self.set_property('out', eval(self.get_property('combo')))
77 changes: 77 additions & 0 deletions example_auto_nodes/logic_nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from .basic_nodes import AutoNode


class IfNode(AutoNode):
"""
if node.
"""

__identifier__ = 'Logics'
NODE_NAME = 'If'

def __init__(self):
super(IfNode, self).__init__()
self.condition = self.add_input('condition')
self._then = self.add_input('then')
self._else = self.add_input('else')
self.add_output('out')
self.create_property('out', None)

def run(self):
if self.getInputData(self.condition):
result = self.getInputData(self._then)
else:
result = self.getInputData(self._else)

self.set_property('out', result)


class BooleanNode(AutoNode):
"""
Boolean Logic funtions node.
"""

__identifier__ = 'Logics'

NODE_NAME = 'Boolean'

logics = {'and': 'a and b',
'or': 'a or b',
'xor': '(not a and b) or (a and not b)',
'not': 'not a'}

def __init__(self):
super(BooleanNode, self).__init__()
self.a = self.add_input('a', bool)
self.b = self.add_input('b', bool)
self.add_output('out', bool)
self.create_property('out', None)
self.add_combo_menu('funcs',
'Functions',
items=list(self.logics.keys()),
tab='widgets')

self.func = self.logics['and']
# switch math function type
self.view.widgets['funcs'].value_changed.connect(self.addFunction)

def addFunction(self, prop, func):
"""
Create inputs based on math functions arguments.
"""
self.func = self.logics[func]
if self.b.visible() and not 'b' in self.func:
self.b.set_visible(False)
elif not self.b.visible():
self.b.set_visible(True)
self.cook()

def run(self):
a = self.getInputData(self.a)
b = self.getInputData(self.b)

if a is None or (b is None and 'b' in self.func):
self.error("No inputs!")
return

self.set_property('out', eval(self.func))
Loading