88from .PortItemInputWidgets import Data_IW_S , Data_IW_M , Data_IW_L , Float_IW , Integer_IW , \
99 Choice_IW , Boolean_IW , String_IW_S , String_IW_M , String_IW_L
1010from ryvencore import serialize , Data
11- from ryvencore .NodePort import NodeOutput , NodeInput
11+ from ryvencore .NodePort import NodeOutput , NodeInput , NodePort
1212from ryvencore .utils import deserialize
1313from ...utils import get_longest_line , shorten
1414
1515from ..FlowViewProxyWidget import FlowViewProxyWidget
1616
17- # Utility methods ------------------------------------------------------------------------------------------------------
18- # These could be moved to another module for clarity
17+ #
18+ # Utils
19+ #
1920
2021def is_connected (port ):
2122 if isinstance (port , NodeOutput ):
@@ -43,7 +44,10 @@ def connections(port):
4344 return [(port .node .flow .connected_output (port ), port )]
4445 else :
4546 return []
46- # ==========
47+
48+ #
49+ # Classes
50+ #
4751
4852class PortItem (GUIBase , QGraphicsWidget ):
4953 """The GUI representative for ports of nodes, also handling mouse events for connections."""
@@ -56,7 +60,7 @@ def __init__(self, node_gui, node_item, port, flow_view):
5660
5761 self .node_gui = node_gui
5862 self .node_item = node_item
59- self .port = port
63+ self .port : NodePort = port
6064 self .flow_view = flow_view
6165
6266 # self.port.has_been_connected.connect(self.port_connected)
@@ -106,23 +110,9 @@ def __init__(self, node_gui, node_item, port, input_widget: Tuple[type, str] = N
106110 if self .port .node .flow .connected_output (self .port ) is not None :
107111 self .port_connected ()
108112
109- # TODO: add DType support when Addon will be enabled
110- # if self.port.add_data:
111- #
112- # if self.port.dtype:
113- # c_d = self.port.add_data['widget data']
114- # self.widget.set_state(deserialize(c_d))
115- #
116- # elif 'widget data' in self.port.add_data:
117- # try:
118- # c_d = self.port.add_data['widget data']
119- # if type(c_d) == dict: # backwards compatibility
120- # self.widget.set_state(c_d)
121- # else:
122- # self.widget.set_state(deserialize(c_d))
123- # except Exception as e:
124- # print('Exception while setting data in', self.node.title,
125- # '\'s input widget:', e, ' (was this intended?)')
113+ if self .port .load_data is not None and self .port .load_data ['has widget' ]:
114+ c_d = self .port .load_data ['widget data' ]
115+ self .widget .set_state (deserialize (c_d ))
126116
127117 self .setup_ui ()
128118
@@ -150,47 +140,11 @@ def create_widget(self, widget_class, widget_pos):
150140 return
151141
152142 if self .port .type_ != 'data' :
153- # TODO: input widgets from exec inputs?
143+ # TODO: how about input widgets for exec inputs?
154144 return
155145
156146 params = (self .port , self , self .node_gui .node , self .node_gui , widget_pos )
157147
158- # TODO: add DType support when Addon will be enabled
159- # self.port.dtype = DTypes.Data()
160- #
161- # if self.port.dtype:
162- #
163- # dtype = self.port.dtype
164- #
165- # if isinstance(dtype, DTypes.Data):
166- # if dtype.size == 's':
167- # return Data_IW_S(params)
168- # elif dtype.size == 'm':
169- # return Data_IW_M(params)
170- # elif dtype.size == 'l':
171- # return Data_IW_L(params)
172- #
173- # elif isinstance(dtype, DTypes.String):
174- # if dtype.size == 's':
175- # return String_IW_S(params)
176- # elif dtype.size == 'm':
177- # return String_IW_M(params)
178- # elif dtype.size == 'l':
179- # return String_IW_L(params)
180- #
181- # elif isinstance(dtype, DTypes.Integer):
182- # return Integer_IW(params)
183- #
184- # elif isinstance(dtype, DTypes.Float):
185- # return Float_IW(params)
186- #
187- # elif isinstance(dtype, DTypes.Boolean):
188- # return Boolean_IW(params)
189- #
190- # elif isinstance(dtype, DTypes.Choice):
191- # return Choice_IW(params)
192- #
193-
194148 # custom input widget
195149 self .widget = widget_class (params )
196150 self .proxy = FlowViewProxyWidget (self .flow_view , parent = self .node_item )
0 commit comments