66 NodeInputDisconnectedCmd )
77from .model import PortModel
88from ..constants import IN_PORT , OUT_PORT
9+ from ..errors import PortError
910
1011
1112class Port (object ):
@@ -102,15 +103,6 @@ def visible(self):
102103 """
103104 return self .model .visible
104105
105- def locked (self ):
106- """
107- Port locked state.
108-
109- Returns:
110- bool: true if visible.
111- """
112- return self .model .locked
113-
114106 def set_visible (self , visible = True ):
115107 """
116108 Sets weather the port should be visible or not.
@@ -129,14 +121,42 @@ def set_visible(self, visible=True):
129121 undo_stack .push (PortVisibleCmd (self ))
130122 undo_stack .endMacro ()
131123
132- def set_locked (self , locked = False ):
124+ def locked (self ):
125+ """
126+ Returns the locked state.
127+
128+ If ports are locked then new pipe connections can't be connected
129+ and current connected pipes can't be disconnected.
130+
131+ Returns:
132+ bool: true if locked.
133133 """
134- Sets the port locked state when locked new pipe connections can't be
135- connected or disconnected from the node graph gui.
134+ return self .model .locked
135+
136+ def lock (self ):
137+ """
138+ Lock the port so new pipe connections can't be connected and
139+ current connected pipes can't be disconnected.
140+
141+ This is the same as calling :meth:`Port.set_locked` with the arg
142+ set to ``True``
143+ """
144+ self .set_locked (True )
145+
146+ def unlock (self ):
147+ """
148+ Unlock the port so new pipe connections can be connected and
149+ existing connected pipes can be disconnected.
136150
137- Note:
138- pipes can still be connected/disconnected to locked ports through
139- the api.
151+ This is the same as calling :meth:`Port.set_locked` with the arg
152+ set to ``False``
153+ """
154+ self .set_locked (False )
155+
156+ def set_locked (self , locked = False ):
157+ """
158+ Sets the port locked state. When locked pipe connections can't be
159+ connected or disconnected from this port.
140160
141161 Args:
142162 locked (Bool): true if locked.
@@ -176,6 +196,11 @@ def connect_to(self, port=None):
176196 if self in port .connected_ports ():
177197 return
178198
199+ if self .locked () or port .locked ():
200+ name = [p .name () for p in [self , port ] if p .locked ()][0 ]
201+ raise PortError (
202+ 'Can\' t connect port because "{}" is locked.' .format (name ))
203+
179204 graph = self .node ().graph
180205 viewer = graph .viewer ()
181206
@@ -227,6 +252,12 @@ def disconnect_from(self, port=None):
227252 """
228253 if not port :
229254 return
255+
256+ if self .locked () or port .locked ():
257+ name = [p .name () for p in [self , port ] if p .locked ()][0 ]
258+ raise PortError (
259+ 'Can\' t disconnect port because "{}" is locked.' .format (name ))
260+
230261 graph = self .node ().graph
231262 graph .undo_stack ().beginMacro ('disconnect port' )
232263 graph .undo_stack ().push (PortDisconnectedCmd (self , port ))
0 commit comments