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

Using new props.suppress context manager. Also, Notifier.__new__ prints

a warning if the sub-class is also a HasProperties, because both classes
define a 'notify' method, which could be super confusing.
parent 20df5820
No related branches found
No related tags found
No related merge requests found
......@@ -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):
......
......@@ -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
......
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