Skip to content
Snippets Groups Projects
Commit b729afa0 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Adjusted required notifier callback signature - a value can now be

passed through to listener functions.
parent 947acd3a
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -598,7 +598,7 @@ class Image(Nifti, notifier.Notifier):
:class:`.Notifier` interface) on the ``'dataRange'`` topic.
"""
if not self.__suppressDataRange:
self.notify(notifier_topic='dataRange')
self.notify(topic='dataRange')
def calcRange(self, sizethres=None):
......@@ -693,7 +693,7 @@ class Image(Nifti, notifier.Notifier):
self.__dataSource = filename
self.__saveState = True
self.notify(notifier_topic='saveState')
self.notify(topic='saveState')
def __getitem__(self, sliceobj):
......@@ -739,14 +739,14 @@ class Image(Nifti, notifier.Notifier):
if values.size > 0:
self.notify(notifier_topic='data')
self.notify(topic='data')
if self.__saveState:
self.__saveState = False
self.notify(notifier_topic='saveState')
self.notify(topic='saveState')
if not np.all(np.isclose(oldRange, newRange)):
self.notify(notifier_topic='dataRange')
self.notify(topic='dataRange')
ALLOWED_EXTENSIONS = ['.nii.gz', '.nii', '.img', '.hdr', '.img.gz', '.hdr.gz']
......
......@@ -106,7 +106,7 @@ class MelodicImage(fslimage.Image):
self.__tr = val
if oldval != val:
self.notify(notifier_topic='tr')
self.notify(topic='tr')
def getComponentTimeSeries(self, component):
......
......@@ -39,6 +39,7 @@ class Notifier(object):
class, provided by the :mod:`props` package.
"""
def __new__(cls, *args, **kwargs):
"""Initialises a dictionary of listeners on a new ``Notifier``
instance.
......@@ -57,13 +58,21 @@ class Notifier(object):
"""Register a listener with this ``Notifier``.
:arg name: A unique name for the listener.
:arg callback: The function to call - must accept this ``Notifier``
instance as its sole argument.
:arg callback: The function to call - must accept two positional
arguments:
- this ``Notifier`` instance.
- A value, which may be ``None`` - see
:meth:`notify`.
:arg topic: Optional topic on which to listen for notifications.
:arg runOnIdle: If ``True``, this listener will be called on the main
thread, via the :func:`.async.idle` function.
Otherwise this function will be called directly by the
:meth:`notify` method.
:meth:`notify` method. Defaults to ``False``.
"""
if topic is None:
......@@ -132,9 +141,13 @@ class Notifier(object):
The documented arguments must be passed as keyword arguments.
:args notifier_topic: The topic on which to notify. Default
listeners are always notified, regardless
of the specified topic.
:arg topic: The topic on which to notify. Default
listeners are always notified, regardless
of the specified topic.
:arg value: A value passed through to the registered listener
functions. If not provided, listeners will be passed
a value of ``None``.
All other arguments passed to this method are ignored.
......@@ -143,7 +156,8 @@ class Notifier(object):
See :meth:`register`.
"""
topic = kwargs.get('notifier_topic', DEFAULT_TOPIC)
topic = kwargs.get('topic', DEFAULT_TOPIC)
value = kwargs.get('value', None)
listeners = [self.__listeners[topic]]
if topic != DEFAULT_TOPIC:
......@@ -179,5 +193,5 @@ class Notifier(object):
'removing from list'.format(name))
ldict.pop(name)
elif runOnIdle: async.idle(callback, self)
else: callback(self)
elif runOnIdle: async.idle(callback, self, value)
else: callback( self, value)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment