def test_signal_connection(qapp): # Create a signal and attach our listener sig = Signal(name='my_signal', value=1) register_signal(sig) widget = WritableWidget() listener = widget.channels()[0] sig_conn = SignalConnection(listener, 'my_signal') sig_conn.add_listener(listener) # Check that our widget receives the initial value qapp.processEvents() assert widget._write_access assert widget._connected assert widget.value == 1 # Check that we can push values back to the signal which in turn causes the # internal value at the widget to update widget.send_value_signal[int].emit(2) qapp.processEvents() qapp.processEvents() # Must be called twice. Multiple rounds of signals assert sig.get() == 2 assert widget.value == 2 # Try changing types qapp.processEvents() qapp.processEvents() # Must be called twice. Multiple rounds of signals sig_conn.remove_listener(listener) # Check that our signal is disconnected completely and maintains the same # value as the signal updates in the background sig.put(3) qapp.processEvents() assert widget.value == 2 widget.send_value_signal.emit(1) qapp.processEvents() assert sig.get() == 3
def test_signal_connection(qapp, qtbot): # Create a signal and attach our listener sig = Signal(name='my_signal', value=1) register_signal(sig) widget = PyDMLineEdit() qtbot.addWidget(widget) widget.channel = 'sig://my_signal' listener = widget.channels()[0] # If PyDMChannel can not connect, we need to connect it ourselves # In PyDM > 1.5.0 this will not be neccesary as the widget will be # connected after we set the channel name if not hasattr(listener, 'connect'): pydm.utilities.establish_widget_connections(widget) # Check that our widget receives the initial value qapp.processEvents() assert widget._write_access assert widget._connected assert widget.value == 1 # Check that we can push values back to the signal which in turn causes the # internal value at the widget to update widget.send_value_signal[int].emit(2) qapp.processEvents() qapp.processEvents() # Must be called twice. Multiple rounds of signals assert sig.get() == 2 assert widget.value == 2 # Try changing types qapp.processEvents() qapp.processEvents() # Must be called twice. Multiple rounds of signals # In PyDM > 1.5.0 we will not need the application to disconnect the # widget, but until then we have to check for the attribute if hasattr(listener, 'disconnect'): listener.disconnect() else: qapp.close_widget_connections(widget) # Check that our signal is disconnected completely and maintains the same # value as the signal updates in the background sig.put(3) qapp.processEvents() assert widget.value == 2 widget.send_value_signal.emit(1) qapp.processEvents() assert sig.get() == 3
def sim_signal(): sim_sig = Signal(name='tst_this_2') sim_sig.put(3.14) register_signal(sim_sig) return sim_sig