- if listener_type == GraphListenerType.PORT_ADDED:
- fn = native_bt.py3_graph_add_port_added_listener
- listener_from_native = functools.partial(_graph_port_added_listener_from_native,
- listener)
- elif listener_type == GraphListenerType.PORT_REMOVED:
- fn = native_bt.py3_graph_add_port_removed_listener
- listener_from_native = functools.partial(_graph_port_removed_listener_from_native,
- listener)
- elif listener_type == GraphListenerType.PORTS_CONNECTED:
- fn = native_bt.py3_graph_add_ports_connected_listener
- listener_from_native = functools.partial(_graph_ports_connected_listener_from_native,
- listener)
- elif listener_type == GraphListenerType.PORTS_DISCONNECTED:
- fn = native_bt.py3_graph_add_ports_disconnected_listener
- listener_from_native = functools.partial(_graph_ports_disconnected_listener_from_native,
- listener)
- else:
- raise TypeError
+ fn = native_bt.py3_graph_add_port_added_listener
+ listener_from_native = functools.partial(_graph_port_added_listener_from_native,
+ listener)
+
+ listener_ids = fn(self._ptr, listener_from_native)
+ if listener_ids is None:
+ utils._raise_bt2_error('cannot add listener to graph object')
+ return bt2._ListenerHandle(listener_ids, self)