Skip to main content

A QT signal/slot concept for Python with Weakrefs.

Project description

QSignal – A QT Signal/slot for python

https://travis-ci.org/complynx/qsignal.svg?branch=master

This project provides easy to use Signal class for implementing Signal/Slot mechanism in Python. It does not implement it strictly but rather creates the easy and simple alternative.

Classes

Signal

qsignal.Signal is the main class.

To create a signal, just make a sig = qsignal.Signal and set up an emitter of it. Or create it with sig = qsignal.Signal(emitter=foo).

To emit it, just call your sig(). Or emit it in asynchronous mode with the method async.

Example:

>>> from qsignal import Signal
>>> # Creating signal
>>> sig = Signal()
>>> # Or
>>> myobject.signal = Signal(emitter=myobject)
>>> # Connecting to signals
>>> sig.connect(callback)
>>> myobject.signal.connect(sig)
>>> myobject.signal.connect(otherobject.callback_method)
>>> # Emitting
>>> sig()
>>> myobject.signal('argument(s)', optional=True)
>>> # Emitting in asynchronous mode
>>> sig.async()

To connect slots to it, pass callbacks into connect. The connections are maintained through weakref, thus you don’t need to search for them and disconnect whenever you’re up to destroy some object.

Signaller

The base class for objects to maintain their Signals.

The only purpose of this class is to automate Signal names and emitter references.

>>> from qsignal import Signal, Signaller
>>> # For example, this is a class...
>>> class MyClass(Signaller):
>>>     my_signal = Signal()
>>> # This is a slot...
>>> def my_slot():
>>>     sig = Signal.emitted()
>>>     assert sig.name == my_signal
>>>     assert sig.emitter.__class__ == MyClass
>>> # And the connections...
>>> o = MyClass()
>>> o.my_signal.connect(my_slot)
>>> #...
>>> o.my_signal()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qsignal-1.0.2b1.tar.gz (7.5 kB view hashes)

Uploaded Source

Built Distribution

qsignal-1.0.2b1-py2.py3-none-any.whl (6.7 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page