diff --git a/fsl/data/melodiclabels.py b/fsl/data/melodiclabels.py index 49e9192d911db05a85bf53ee098fa3df346d2d8e..9ca546cae65e9501d74e9df9d6cb0e28c14162f8 100644 --- a/fsl/data/melodiclabels.py +++ b/fsl/data/melodiclabels.py @@ -88,14 +88,10 @@ class MelodicClassification(props.HasProperties): def clear(self): """Removes all labels from all components. """ - notifState = self.getNotificationState('labels') - self.disableNotification('labels') - - self.__components = {} - self.labels = [[] for i in range(self.__ncomps)] - - self.setNotificationState('labels', notifState) - self.notify('labels') + with props.suppress(self, 'labels', notify=True): + + self.__components = {} + self.labels = [[] for i in range(self.__ncomps)] def load(self, filename): @@ -130,15 +126,11 @@ class MelodicClassification(props.HasProperties): allLabels.append(['Unknown']) # Add the labels to this melclass object - notifState = self.getNotificationState('labels') - self.disableNotification('labels') + with props.suppress(self, 'labels', notify=True): - for i, labels in enumerate(allLabels): - for label in labels: - self.addLabel(i, label) - - self.setNotificationState('labels', notifState) - self.notify('labels') + for i, labels in enumerate(allLabels): + for label in labels: + self.addLabel(i, label) def save(self, filename): @@ -223,13 +215,9 @@ class MelodicClassification(props.HasProperties): labels = self.getLabels(component) - self.disableNotification('labels') - - for l in labels: - self.removeLabel(component, l) - - self.enableNotification('labels') - self.notify('labels') + with props.suppress(self, 'labels', notify=True): + for l in labels: + self.removeLabel(component, l) log.debug('Labels cleared from component: {}'.format(component)) @@ -262,13 +250,9 @@ class MelodicClassification(props.HasProperties): components = self.getComponents(label) - self.disableNotification('labels') - - for c in components: - self.removeComponent(label, c) - - self.enableNotification('labels') - self.notify('labels') + with props.suppress(self, 'labels', notify=True): + for c in components: + self.removeComponent(label, c) def loadLabelFile(filename, includeLabel=None, excludeLabel=None): diff --git a/fsl/utils/notifier.py b/fsl/utils/notifier.py index 5aef630dfa7bf802e1c9a0b70c78dc4d9def236b..b05aebc3de676b13a741ed4ed61f64cd6dc8d505 100644 --- a/fsl/utils/notifier.py +++ b/fsl/utils/notifier.py @@ -46,6 +46,10 @@ class Notifier(object): new = object.__new__(cls) new.__listeners = collections.defaultdict(collections.OrderedDict) + if isinstance(new, props.HasProperties): + log.warning('Warning: {} is a sub-class of both ' + 'Notifier and props.HasProperties!') + return new