forked from Kazuhito00/Image-Processing-Node-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_node_float_value.py
More file actions
109 lines (86 loc) · 3.16 KB
/
Copy path_node_float_value.py
File metadata and controls
109 lines (86 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import dearpygui.dearpygui as dpg
from node_editor.util import dpg_get_value, dpg_set_value
from node.basenode import Node as BaseNode
class FactoryNode:
node_label = 'FloatValue'
node_tag = 'FloatValue'
def __init__(self):
pass
def add_node(
self,
parent,
node_id,
pos=[0, 0],
opencv_setting_dict=None,
callback=None,
):
"""Adds a Float Value node that outputs a float value."""
# Generate node instance
node = Node()
node.tag_node_name = str(node_id) + ':' + node.node_tag
# Output tags
node.tag_node_output01_name = node.tag_node_name + ':' + node.TYPE_FLOAT + ':Output01'
node.tag_node_output01_value_name = node.tag_node_name + ':' + node.TYPE_FLOAT + ':Output01Value'
node._opencv_setting_dict = opencv_setting_dict
# Create node in the GUI
with dpg.node(
tag=node.tag_node_name,
parent=parent,
label=node.node_label,
pos=pos,
):
# Float value slider as output
with dpg.node_attribute(
tag=node.tag_node_output01_name,
attribute_type=dpg.mvNode_Attr_Output,
):
dpg.add_slider_float(
tag=node.tag_node_output01_value_name,
label="",
width=150,
default_value=0.0,
min_value=-10.0,
max_value=10.0,
callback=None,
)
return node
class Node(BaseNode):
_ver = '1.0.0'
node_label = 'FloatValue'
node_tag = 'FloatValue'
_opencv_setting_dict = None
def __init__(self):
pass
def update(
self,
node_id,
connection_list,
node_image_dict,
node_result_dict,
node_audio_dict,
):
"""Float Value node just passes through the value set by the slider."""
# No processing needed - the slider value is directly accessible
# through the output tag when other nodes connect to it
return {"image": None, "json": None, "audio": None}
def close(self, node_id):
pass
def get_setting_dict(self, node_id):
"""Save the current float value."""
tag_node_name = str(node_id) + ':' + self.node_tag
output_value_tag = tag_node_name + ':' + self.TYPE_FLOAT + ':Output01Value'
output_value = float(dpg_get_value(output_value_tag))
pos = dpg.get_item_pos(tag_node_name)
setting_dict = {}
setting_dict['ver'] = self._ver
setting_dict['pos'] = pos
setting_dict[output_value_tag] = output_value
return setting_dict
def set_setting_dict(self, node_id, setting_dict):
"""Restore the float value."""
tag_node_name = str(node_id) + ':' + self.node_tag
output_value_tag = tag_node_name + ':' + self.TYPE_FLOAT + ':Output01Value'
output_value = float(setting_dict[output_value_tag])
dpg_set_value(output_value_tag, output_value)