def disconnect_from(self, port=None, push_undo=True): """ Disconnect from the specified port and emits the :attr:`NodeGraph.port_disconnected` signal from the parent node graph. Args: port (NodeGraphQt.Port): port object. push_undo (bool): register the command to the undo stack. (default: True) """ if not port: return if self.locked() or port.locked(): name = [p.name() for p in [self, port] if p.locked()][0] raise PortError( 'Can\'t disconnect port because "{}" is locked.'.format(name)) graph = self.node().graph if push_undo: graph.undo_stack().beginMacro('disconnect port') graph.undo_stack().push(PortDisconnectedCmd(self, port)) graph.undo_stack().push(NodeInputDisconnectedCmd(self, port)) graph.undo_stack().endMacro() else: PortDisconnectedCmd(self, port).redo() NodeInputDisconnectedCmd(self, port).redo() # emit "port_disconnected" signal from the parent graph. ports = {p.type_(): p for p in [self, port]} graph.port_disconnected.emit(ports[PortTypeEnum.IN.value], ports[PortTypeEnum.OUT.value])
def connect_to(self, port=None): """ Create connection to the specified port and emits the "port_connected" signal from the parent node graph. Args: port (NodeGraphQt.Port): port object. """ if not port: return graph = self.node().graph viewer = graph.viewer() undo_stack = graph.undo_stack() undo_stack.beginMacro('connect port') pre_conn_port = None src_conn_ports = self.connected_ports() if not self.multi_connection() and src_conn_ports: pre_conn_port = src_conn_ports[0] if not port: if pre_conn_port: undo_stack.push(NodeInputDisconnectedCmd(self, port)) undo_stack.push(PortDisconnectedCmd(self, port)) return if graph.acyclic() and viewer.acyclic_check(self.view, port.view): if pre_conn_port: undo_stack.push(NodeInputDisconnectedCmd(self, pre_conn_port)) undo_stack.push(PortDisconnectedCmd(self, pre_conn_port)) return trg_conn_ports = port.connected_ports() if not port.multi_connection() and trg_conn_ports: dettached_port = trg_conn_ports[0] undo_stack.push(NodeInputDisconnectedCmd(port, dettached_port)) undo_stack.push(PortDisconnectedCmd(port, dettached_port)) if pre_conn_port: undo_stack.push(NodeInputDisconnectedCmd(self, pre_conn_port)) undo_stack.push(PortDisconnectedCmd(self, pre_conn_port)) undo_stack.push(NodeInputConnectedCmd(self, port)) undo_stack.push(PortConnectedCmd(self, port)) undo_stack.endMacro() # emit "port_connected" signal from the parent graph. ports = {p.type_(): p for p in [self, port]} graph.port_connected.emit(ports[IN_PORT], ports[OUT_PORT])
def disconnect_from(self, port=None): """ Disconnect from the specified port. Args: port (NodeGraphQt.Port): port object. """ if not port: return graph = self.node().graph graph.undo_stack().push(PortDisconnectedCmd(self, port))
def connect_to(self, port=None): """ Create connection to the specified port. Args: port (NodeGraphQt.Port): port object. """ if not port: return graph = self.node().graph viewer = graph.viewer() undo_stack = graph.undo_stack() undo_stack.beginMacro('connected port') pre_conn_port = None src_conn_ports = self.connected_ports() if not self.multi_connection() and src_conn_ports: pre_conn_port = src_conn_ports[0] if not port: if pre_conn_port: undo_stack.push(PortDisconnectedCmd(self, port)) return if graph.acyclic() and viewer.acyclic_check(self.view, port.view): if pre_conn_port: undo_stack.push(PortDisconnectedCmd(self, pre_conn_port)) return trg_conn_ports = port.connected_ports() if not port.multi_connection() and trg_conn_ports: dettached_port = trg_conn_ports[0] undo_stack.push(PortDisconnectedCmd(port, dettached_port)) if pre_conn_port: undo_stack.push(PortDisconnectedCmd(self, pre_conn_port)) undo_stack.push(PortConnectedCmd(self, port)) undo_stack.endMacro()
def disconnect_from(self, port=None): """ Disconnect from the specified port and emits the "port_disconnected" signal from the parent node graph. Args: port (NodeGraphQt.Port): port object. """ if not port: return graph = self.node().graph graph.undo_stack().push(PortDisconnectedCmd(self, port)) # emit "port_disconnected" signal from the parent graph. graph.port_disconnected.emit(self, port)
def set_visible(self, visible=True): """ Sets weather the port should be visible or not. Args: visible (bool): true if visible. """ self.model.visible = visible label = 'show' if visible else 'hide' undo_stack = self.node().graph.undo_stack() undo_stack.beginMacro('{} port {}'.format(label, self.name())) for port in self.connected_ports(): undo_stack.push(PortDisconnectedCmd(self, port)) undo_stack.push(PortVisibleCmd(self)) undo_stack.endMacro()
def disconnect_from(self, port=None): """ Disconnect from the specified port and emits the "port_disconnected" signal from the parent node graph. Args: port (NodeGraphQt.Port): port object. """ if not port: return graph = self.node().graph graph.undo_stack().beginMacro('disconnect port') graph.undo_stack().push(NodeInputDisconnectedCmd(self, port)) graph.undo_stack().push(PortDisconnectedCmd(self, port)) graph.undo_stack().endMacro() # emit "port_disconnected" signal from the parent graph. ports = {p.type_(): p for p in [self, port]} graph.port_disconnected.emit(ports[IN_PORT], ports[OUT_PORT])
def connect_to(self, port=None, push_undo=True): """ Create connection to the specified port and emits the :attr:`NodeGraph.port_connected` signal from the parent node graph. Args: port (NodeGraphQt.Port): port object. push_undo (bool): register the command to the undo stack. (default: True) """ if not port: return if self in port.connected_ports(): return if self.locked() or port.locked(): name = [p.name() for p in [self, port] if p.locked()][0] raise PortError( 'Can\'t connect port because "{}" is locked.'.format(name)) graph = self.node().graph viewer = graph.viewer() if push_undo: undo_stack = graph.undo_stack() undo_stack.beginMacro('connect port') pre_conn_port = None src_conn_ports = self.connected_ports() if not self.multi_connection() and src_conn_ports: pre_conn_port = src_conn_ports[0] if not port: if pre_conn_port: if push_undo: undo_stack.push(PortDisconnectedCmd(self, port)) undo_stack.push(NodeInputDisconnectedCmd(self, port)) undo_stack.endMacro() else: PortDisconnectedCmd(self, port).redo() NodeInputDisconnectedCmd(self, port).redo() return if graph.acyclic() and viewer.acyclic_check(self.view, port.view): if pre_conn_port: if push_undo: undo_stack.push(PortDisconnectedCmd(self, pre_conn_port)) undo_stack.push( NodeInputDisconnectedCmd(self, pre_conn_port)) undo_stack.endMacro() else: PortDisconnectedCmd(self, pre_conn_port).redo() NodeInputDisconnectedCmd(self, pre_conn_port).redo() return trg_conn_ports = port.connected_ports() if not port.multi_connection() and trg_conn_ports: dettached_port = trg_conn_ports[0] if push_undo: undo_stack.push(PortDisconnectedCmd(port, dettached_port)) undo_stack.push(NodeInputDisconnectedCmd(port, dettached_port)) else: PortDisconnectedCmd(port, dettached_port).redo() NodeInputDisconnectedCmd(port, dettached_port).redo() if pre_conn_port: if push_undo: undo_stack.push(PortDisconnectedCmd(self, pre_conn_port)) undo_stack.push(NodeInputDisconnectedCmd(self, pre_conn_port)) else: PortDisconnectedCmd(self, pre_conn_port).redo() NodeInputDisconnectedCmd(self, pre_conn_port).redo() if push_undo: undo_stack.push(PortConnectedCmd(self, port)) undo_stack.push(NodeInputConnectedCmd(self, port)) undo_stack.endMacro() else: PortConnectedCmd(self, port).redo() NodeInputConnectedCmd(self, port).redo() # emit "port_connected" signal from the parent graph. ports = {p.type_(): p for p in [self, port]} graph.port_connected.emit(ports[PortTypeEnum.IN.value], ports[PortTypeEnum.OUT.value])