Skip to content

Commit

Permalink
checkpoint nodes!
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon Thomm committed Aug 1, 2020
1 parent 8a58db8 commit 273f525
Show file tree
Hide file tree
Showing 20 changed files with 885 additions and 9 deletions.
15 changes: 11 additions & 4 deletions Ryven/custom_src/NodeInstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,13 @@ def update_shape(self):
# very essential; repositions everything in case content has changed (inputs/outputs/widget)

if self.parent_node.design_style == 'minimalistic':
self.layout.setMinimumWidth(self.title_label.width + 15)
self.layout.activate()

# making it recompute its true minimumWidth here
self.widget.adjustSize()

if self.layout.minimumWidth() < self.title_label.width + 15:
self.layout.setMinimumWidth(self.title_label.width + 15)
self.layout.activate()

self.width = self.boundingRect().width()
self.height = self.boundingRect().height()
Expand Down Expand Up @@ -346,7 +351,8 @@ def add_input_to_layout(self, i):
def insert_input_into_layout(self, index, i):
self.inputs_layout.insertItem(index*2, i) # *2 because of the stretches
self.inputs_layout.setAlignment(i, Qt.AlignLeft)
self.inputs_layout.insertStretch(index*2+1) # *2+1 because of the stretches, too
if len(self.inputs) > 1:
self.inputs_layout.insertStretch(index*2+1) # *2+1 because of the stretches, too

def delete_input(self, i):
"""Disconnects and removes input. Handy for subclasses."""
Expand Down Expand Up @@ -404,7 +410,8 @@ def add_output_to_layout(self, o):
def insert_output_into_layout(self, index, o):
self.outputs_layout.insertItem(index*2, o) # *2 because of the stretches
self.outputs_layout.setAlignment(o, Qt.AlignRight)
self.outputs_layout.insertStretch(index*2+1) # *2+1 because of the stretches, too
if len(self.outputs) > 1:
self.outputs_layout.insertStretch(index*2+1) # *2+1 because of the stretches, too

def delete_output(self, o):
"""Disconnects and removes output. Handy for subclasses."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ def name_line_edit_editing_finished(self):
def del_variable(self, var, var_widget):
self.widgets.remove(var_widget)
var_widget.setParent(None)
del self.variables_handler.variables[self.variables.index(var)]
del self.variables_handler.variables[self.variables_handler.variables.index(var)]
self.recreate_ui()
72 changes: 72 additions & 0 deletions packages/random/nodes/random___RandInts0/random___RandInts0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from custom_src.NodeInstance import NodeInstance
from custom_src.Node import Node
from custom_src.retain import M


# API METHODS

# self.main_widget <- access to main widget
# self.update_shape() <- recomputes the whole shape and content positions

# Ports
# self.input(index) <- access to input data
# self.set_output_val(index, val) <- set output data port value
# self.exec_output(index) <- executes an execution output

# self.create_new_input(type_, label, widget_name=None, widget_pos='under', pos=-1)
# self.delete_input(index)
# self.create_new_output(type_, label, pos=-1)
# self.delete_output(index)


# Logging
# mylog = self.new_log('Example Log')
# mylog.log('I\'m alive!!')
# self.log_message('hello global!', target='global')
# self.log_message('that\'s not good', target='error')

# ------------------------------------------------------------------------------

import random


class RandInts_NodeInstance(NodeInstance):
def __init__(self, parent_node: Node, flow, configuration=None):
super(RandInts_NodeInstance, self).__init__(parent_node, flow, configuration)


self.special_actions['make executable'] = {'method': M(self.action_make_executable)}
self.active = False

self.initialized()

def action_make_executable(self):
del self.special_actions['make executable']
self.special_actions['make passve'] = {'method': M(self.action_make_passive)}
self.create_new_input('exec', '', pos=0)
self.create_new_output('exec', '', pos=0)
self.active = True

def action_make_passive(self):
del self.special_actions['make passve']
self.special_actions['make executable'] = {'method': M(self.action_make_executable)}
self.delete_input(0)
self.delete_output(0)
self.active = False

def update_event(self, input_called=-1):
if self.active and input_called==0:
self.set_output_val(1, [random.randint(self.input(2), self.input(3)) for i in range(self.input(1))])
self.exec_output(0)
else:
self.set_output_val(0, [random.randint(self.input(1), self.input(2)) for i in range(self.input(0))])

def get_data(self):
data = {'active': self.active}
return data

def set_data(self, data):
self.active = data['active']

def removing(self):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from custom_src.NodeInstance import NodeInstance
from custom_src.Node import Node
from custom_src.retain import M


# API METHODS

# self.main_widget <- access to main widget
# self.update_shape() <- recomputes the whole shape and content positions

# Ports
# self.input(index) <- access to input data
# self.set_output_val(index, val) <- set output data port value
# self.exec_output(index) <- executes an execution output

# self.create_new_input(type_, label, widget_name=None, widget_pos='under', pos=-1)
# self.delete_input(index)
# self.create_new_output(type_, label, pos=-1)
# self.delete_output(index)


# Logging
# mylog = self.new_log('Example Log')
# mylog.log('I\'m alive!!')
# self.log_message('hello global!', target='global')
# self.log_message('that\'s not good', target='error')

# ------------------------------------------------------------------------------

import random


class %NODE_TITLE%_NodeInstance(NodeInstance):
def __init__(self, parent_node: Node, flow, configuration=None):
super(%NODE_TITLE%_NodeInstance, self).__init__(parent_node, flow, configuration)


self.special_actions['make executable'] = {'method': M(self.action_make_executable)}
self.active = False

self.initialized()

def action_make_executable(self):
del self.special_actions['make executable']
self.special_actions['make passve'] = {'method': M(self.action_make_passive)}
self.create_new_input('exec', '', pos=0)
self.create_new_output('exec', '', pos=0)
self.active = True

def action_make_passive(self):
del self.special_actions['make passve']
self.special_actions['make executable'] = {'method': M(self.action_make_executable)}
self.delete_input(0)
self.delete_output(0)
self.active = False

def update_event(self, input_called=-1):
if self.active and input_called==0:
self.set_output_val(1, [random.randint(self.input(2), self.input(3)) for i in range(self.input(1))])
self.exec_output(0)
else:
self.set_output_val(0, [random.randint(self.input(1), self.input(2)) for i in range(self.input(0))])

def get_data(self):
data = {'active': self.active}
return data

def set_data(self, data):
self.active = data['active']

def removing(self):
pass
2 changes: 1 addition & 1 deletion packages/random/random.rpc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type": "vyScriptFP nodes package", "nodes": [{"title": "Rand Seed", "description": "Initializes the random number generator.", "type": "", "module name": "random___RandSeed0", "class name": "RandSeed", "design style": "extended", "color": "#a2de98", "has main widget": false, "custom input widgets": [], "inputs": [{"type": "exec", "label": ""}, {"type": "data", "label": "seed", "has widget": true, "widget name": "std line edit m", "widget position": "besides"}], "outputs": [{"type": "exec", "label": ""}]}, {"title": "rand int", "description": "Generates a random integer N in a given range a <= N <= b.", "type": "", "module name": "random___RandInt0", "class name": "RandInt", "design style": "extended", "color": "#a2de98", "has main widget": false, "custom input widgets": [], "inputs": [{"type": "data", "label": "a", "has widget": true, "widget name": "std line edit m r nb", "widget position": "besides"}, {"type": "data", "label": "b", "has widget": true, "widget name": "std line edit m r nb", "widget position": "besides"}], "outputs": [{"type": "data", "label": ""}]}, {"title": "random", "description": "Generates a random float between 0.0 and 1.0.", "type": "", "module name": "random___Random0", "class name": "Random", "design style": "extended", "color": "#a2de98", "has main widget": false, "custom input widgets": [], "inputs": [], "outputs": [{"type": "data", "label": ""}]}]}
{"type": "vyScriptFP nodes package", "nodes": [{"title": "Rand Seed", "description": "Initializes the random number generator.", "type": "", "module name": "random___RandSeed0", "class name": "RandSeed", "design style": "extended", "color": "#a2de98", "has main widget": false, "custom input widgets": [], "inputs": [{"type": "exec", "label": ""}, {"type": "data", "label": "seed", "has widget": true, "widget name": "std line edit m", "widget position": "besides"}], "outputs": [{"type": "exec", "label": ""}]}, {"title": "rand int", "description": "Generates a random integer N in a given range a <= N <= b.", "type": "", "module name": "random___RandInt0", "class name": "RandInt", "design style": "extended", "color": "#a2de98", "has main widget": false, "custom input widgets": [], "inputs": [{"type": "data", "label": "a", "has widget": true, "widget name": "std line edit m r nb", "widget position": "besides"}, {"type": "data", "label": "b", "has widget": true, "widget name": "std line edit m r nb", "widget position": "besides"}], "outputs": [{"type": "data", "label": ""}]}, {"title": "random", "description": "Generates a random float between 0.0 and 1.0.", "type": "", "module name": "random___Random0", "class name": "Random", "design style": "extended", "color": "#a2de98", "has main widget": false, "custom input widgets": [], "inputs": [], "outputs": [{"type": "data", "label": ""}]}, {"title": "rand ints", "description": "Generates a number of random integers N in a range a <= N <= b.", "type": "", "module name": "random___RandInts0", "class name": "RandInts", "design style": "extended", "color": "#a2de98", "has main widget": false, "custom input widgets": [], "inputs": [{"type": "data", "label": "cnt", "has widget": true, "widget name": "std line edit m r nb", "widget position": "besides"}, {"type": "data", "label": "a", "has widget": true, "widget name": "std line edit m r nb", "widget position": "besides"}, {"type": "data", "label": "b", "has widget": true, "widget name": "std line edit m r nb", "widget position": "besides"}], "outputs": [{"type": "data", "label": ""}]}]}
97 changes: 97 additions & 0 deletions packages/std/nodes/std___Checkpoint0/std___Checkpoint0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from custom_src.NodeInstance import NodeInstance
from custom_src.Node import Node
from custom_src.retain import M


# API METHODS

# self.main_widget <- access to main widget
# self.update_shape() <- recomputes the whole shape and content positions

# Ports
# self.input(index) <- access to input data
# self.set_output_val(index, val) <- set output data port value
# self.exec_output(index) <- executes an execution output

# self.create_new_input(type_, label, widget_name=None, widget_pos='under', pos=-1)
# self.delete_input(index)
# self.create_new_output(type_, label, pos=-1)
# self.delete_output(index)


# Logging
# mylog = self.new_log('Example Log')
# mylog.log('I\'m alive!!')
# self.log_message('hello global!', target='global')
# self.log_message('that\'s not good', target='error')

# ------------------------------------------------------------------------------


class Checkpoint_NodeInstance(NodeInstance):
def __init__(self, parent_node: Node, flow, configuration=None):
super(Checkpoint_NodeInstance, self).__init__(parent_node, flow, configuration)

self.special_actions['make exec'] = {'method': M(self.action_make_exec)}
self.passive = True
self.num_exec_outputs = 0

self.initialized()

def action_make_exec(self):
self.passive = False
self.delete_input(0)
self.delete_output(0)
self.create_new_input('exec', '')
del self.special_actions['make exec']
self.special_actions['make data'] = {'method': M(self.action_make_data)}
self.special_actions['add sequence output'] = {'method': M(self.action_add_sequence_output)}
self.action_add_sequence_output()

def action_add_sequence_output(self):
self.create_new_output('exec', '')
self.num_exec_outputs += 1
self.special_actions['remove output '+str(self.num_exec_outputs)] = {'method': M(self.action_remove_sequence_output),
'data': self.num_exec_outputs-1} # -1 because index
def action_remove_sequence_output(self, index):
self.delete_output(index)

# rebuilding special actions
for i in range(self.num_exec_outputs):
del self.special_actions['remove output '+str(i+1)]
self.num_exec_outputs -= 1
for i in range(self.num_exec_outputs):
self.special_actions['remove output '+str(i+1)] = {'method': M(self.action_remove_sequence_output),
'data': i}

def action_make_data(self):
self.delete_input(0)
for i in range(self.num_exec_outputs):
self.delete_output(0)
del self.special_actions['remove output '+str(i+1)]
self.num_exec_outputs = 0
self.create_new_input('data', '')
self.create_new_output('data', '')
del self.special_actions['make data']
del self.special_actions['add sequence output']
self.special_actions['make exec'] = {'method': M(self.action_make_exec)}

def update_event(self, input_called=-1):
if self.passive:
self.set_output_val(0, self.input(0))
else:
if input_called==0:
for i in range(self.num_exec_outputs):
self.exec_output(i)

def get_data(self):
data = {'passive': self.passive,
'num exec outputs': self.num_exec_outputs}
return data

def set_data(self, data):
self.passive = data['passive']
self.num_exec_outputs = data['num exec outputs']

def removing(self):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from custom_src.NodeInstance import NodeInstance
from custom_src.Node import Node
from custom_src.retain import M


# API METHODS

# self.main_widget <- access to main widget
# self.update_shape() <- recomputes the whole shape and content positions

# Ports
# self.input(index) <- access to input data
# self.set_output_val(index, val) <- set output data port value
# self.exec_output(index) <- executes an execution output

# self.create_new_input(type_, label, widget_name=None, widget_pos='under', pos=-1)
# self.delete_input(index)
# self.create_new_output(type_, label, pos=-1)
# self.delete_output(index)


# Logging
# mylog = self.new_log('Example Log')
# mylog.log('I\'m alive!!')
# self.log_message('hello global!', target='global')
# self.log_message('that\'s not good', target='error')

# ------------------------------------------------------------------------------


class %NODE_TITLE%_NodeInstance(NodeInstance):
def __init__(self, parent_node: Node, flow, configuration=None):
super(%NODE_TITLE%_NodeInstance, self).__init__(parent_node, flow, configuration)

self.special_actions['make exec'] = {'method': M(self.action_make_exec)}
self.passive = True
self.num_exec_outputs = 0

self.initialized()

def action_make_exec(self):
self.passive = False
self.delete_input(0)
self.delete_output(0)
self.create_new_input('exec', '')
del self.special_actions['make exec']
self.special_actions['make data'] = {'method': M(self.action_make_data)}
self.special_actions['add sequence output'] = {'method': M(self.action_add_sequence_output)}
self.action_add_sequence_output()

def action_add_sequence_output(self):
self.create_new_output('exec', '')
self.num_exec_outputs += 1
self.special_actions['remove output '+str(self.num_exec_outputs)] = {'method': M(self.action_remove_sequence_output),
'data': self.num_exec_outputs-1} # -1 because index
def action_remove_sequence_output(self, index):
self.delete_output(index)

# rebuilding special actions
for i in range(self.num_exec_outputs):
del self.special_actions['remove output '+str(i+1)]
self.num_exec_outputs -= 1
for i in range(self.num_exec_outputs):
self.special_actions['remove output '+str(i+1)] = {'method': M(self.action_remove_sequence_output),
'data': i}

def action_make_data(self):
self.delete_input(0)
for i in range(self.num_exec_outputs):
self.delete_output(0)
del self.special_actions['remove output '+str(i+1)]
self.num_exec_outputs = 0
self.create_new_input('data', '')
self.create_new_output('data', '')
del self.special_actions['make data']
del self.special_actions['add sequence output']
self.special_actions['make exec'] = {'method': M(self.action_make_exec)}

def update_event(self, input_called=-1):
if self.passive:
self.set_output_val(0, self.input(0))
else:
if input_called==0:
for i in range(self.num_exec_outputs):
self.exec_output(i)

def get_data(self):
data = {'passive': self.passive,
'num exec outputs': self.num_exec_outputs}
return data

def set_data(self, data):
self.passive = data['passive']
self.num_exec_outputs = data['num exec outputs']

def removing(self):
pass
Loading

0 comments on commit 273f525

Please sign in to comment.