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

MelodicComponentGrid refactorings.

parent 013e9de8
No related branches found
No related tags found
No related merge requests found
...@@ -240,7 +240,7 @@ class MelodicClassification(props.HasProperties): ...@@ -240,7 +240,7 @@ class MelodicClassification(props.HasProperties):
def addLabel(self, component, label): def addLabel(self, component, label):
labels = list(self.labels[component]) labels = list(self.labels[component])
comps = self.__components.get(label, []) comps = list(self.__components.get(label, []))
if label in labels: if label in labels:
return return
...@@ -258,7 +258,7 @@ class MelodicClassification(props.HasProperties): ...@@ -258,7 +258,7 @@ class MelodicClassification(props.HasProperties):
def removeLabel(self, component, label): def removeLabel(self, component, label):
labels = list(self.labels[component]) labels = list(self.labels[component])
comps = self.__components.get(label, []) comps = list(self.__components.get(label, []))
if label not in labels: if label not in labels:
return return
...@@ -270,7 +270,7 @@ class MelodicClassification(props.HasProperties): ...@@ -270,7 +270,7 @@ class MelodicClassification(props.HasProperties):
self.__components[label] = comps self.__components[label] = comps
log.debug('Label removed from component: {} <-> {}'.format(component, log.debug('Label removed from component: {} <-> {}'.format(component,
label)) label))
def clearLabels(self, component): def clearLabels(self, component):
......
...@@ -101,7 +101,6 @@ class ComponentGrid(fslpanel.FSLEyesPanel): ...@@ -101,7 +101,6 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
if not isinstance(overlay, fslmelimage.MelodicImage): if not isinstance(overlay, fslmelimage.MelodicImage):
return return
self.__overlay = overlay self.__overlay = overlay
display = self._displayCtx.getDisplay(overlay) display = self._displayCtx.getDisplay(overlay)
opts = display.getDisplayOpts() opts = display.getDisplayOpts()
...@@ -128,29 +127,8 @@ class ComponentGrid(fslpanel.FSLEyesPanel): ...@@ -128,29 +127,8 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
""" """
overlay = self.__overlay overlay = self.__overlay
lut = self.__lut
melclass = overlay.getICClassification()
numComps = overlay.numComponents() numComps = overlay.numComponents()
labels = [l.name() for l in lut.labels]
colours = [l.colour() for l in lut.labels]
# Compile lists of all the existing
# labels, and the colours for each one
for i in range(numComps):
for label in melclass.getLabels(i):
if label in labels:
continue
colour = self.__addNewLutLabel(label).colour()
labels .append(label)
colours.append(colour)
for i in range(len(colours)):
colours[i] = [int(round(c * 255)) for c in colours[i]]
for i in range(numComps): for i in range(numComps):
tags = texttag.TextTagPanel(self.__grid, tags = texttag.TextTagPanel(self.__grid,
...@@ -159,8 +137,6 @@ class ComponentGrid(fslpanel.FSLEyesPanel): ...@@ -159,8 +137,6 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
texttag.TTP_NO_DUPLICATES | texttag.TTP_NO_DUPLICATES |
texttag.TTP_KEYBOARD_NAV)) texttag.TTP_KEYBOARD_NAV))
tags.SetOptions(labels, colours)
# Store the component number on the tag # Store the component number on the tag
# panel, so we know which component we # panel, so we know which component we
# are dealing with in the __onTagAdded # are dealing with in the __onTagAdded
...@@ -170,19 +146,54 @@ class ComponentGrid(fslpanel.FSLEyesPanel): ...@@ -170,19 +146,54 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
self.__grid.SetText( i, 0, str(i)) self.__grid.SetText( i, 0, str(i))
self.__grid.SetWidget(i, 1, tags) self.__grid.SetWidget(i, 1, tags)
for label in melclass.getLabels(i):
tags.AddTag(label)
tags.Bind(texttag.EVT_TTP_TAG_ADDED_EVENT, self.__onTagAdded) tags.Bind(texttag.EVT_TTP_TAG_ADDED_EVENT, self.__onTagAdded)
tags.Bind(texttag.EVT_TTP_TAG_REMOVED_EVENT, self.__onTagRemoved) tags.Bind(texttag.EVT_TTP_TAG_REMOVED_EVENT, self.__onTagRemoved)
self.__refreshTags()
self.Layout() self.Layout()
def __refreshTags(self):
overlay = self.__overlay
melclass = overlay.getICClassification()
numComps = overlay.numComponents()
lut = self.__lut
labels = [l.name() for l in lut.labels]
colours = [l.colour() for l in lut.labels]
# Compile lists of all the existing
# labels, and the colours for each one
for i in range(numComps):
for label in melclass.getLabels(i):
if label in labels:
continue
colour = self.__addNewLutLabel(label).colour()
labels .append(label)
colours.append(colour)
for i in range(len(colours)):
colours[i] = [int(round(c * 255)) for c in colours[i]]
for row in range(numComps):
tags = self.__grid.GetWidget(row, 1)
tags.ClearTags()
tags.SetOptions(labels, colours)
for label in melclass.getLabels(row):
tags.AddTag(label)
def __addNewLutLabel(self, label, colour=None): def __addNewLutLabel(self, label, colour=None):
""" """
""" """
lut = self.__lut lut = self.__lut
value = lut.max() + 1 value = lut.max() + 1
...@@ -193,8 +204,10 @@ class ComponentGrid(fslpanel.FSLEyesPanel): ...@@ -193,8 +204,10 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
lut.set(value, name=label, colour=colour) lut.set(value, name=label, colour=colour)
lut.enableListener('labels', self._name) lut.enableListener('labels', self._name)
return lut.get(value) self.__refreshTags()
return lut.get(value)
def __onTagAdded(self, ev): def __onTagAdded(self, ev):
""" """
...@@ -207,15 +220,25 @@ class ComponentGrid(fslpanel.FSLEyesPanel): ...@@ -207,15 +220,25 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
lut = self.__lut lut = self.__lut
melclass = overlay.getICClassification() melclass = overlay.getICClassification()
# Add the new label to the melodic component
melclass.disableListener('labels', self._name)
melclass.addLabel(component, label)
# If the tag panel previously just contained
# the 'Unknown' tag, remove that tag
if tags.TagCount() == 2 and tags.HasTag('Unknown'):
melclass.removeLabel(component, 'Unknown')
tags.RemoveTag('Unknown')
melclass.enableListener('labels', self._name)
# If the newly added tag is not in
# the lookup table, add it in
if lut.getByName(label) is None: if lut.getByName(label) is None:
colour = tags.GetTagColour(label) colour = tags.GetTagColour(label)
colour = [c / 255.0 for c in colour] colour = [c / 255.0 for c in colour]
self.__addNewLutLabel(label, colour) self.__addNewLutLabel(label, colour)
melclass.disableListener('labels', self._name)
melclass.addLabel(component, label)
melclass.enableListener('labels', self._name)
self.__grid.FitInside() self.__grid.FitInside()
...@@ -229,9 +252,16 @@ class ComponentGrid(fslpanel.FSLEyesPanel): ...@@ -229,9 +252,16 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
overlay = self.__overlay overlay = self.__overlay
melclass = overlay.getICClassification() melclass = overlay.getICClassification()
# Remove the label from
# the melodic component
melclass.disableListener('labels', self._name) melclass.disableListener('labels', self._name)
melclass.removeLabel(component, label) melclass.removeLabel(component, label)
melclass.enableListener('labels', self._name) melclass.enableListener('labels', self._name)
# If the tag panel now has no tags,
# add the 'Unknown' tag back in.
if tags.TagCount() == 0:
tags.AddTag('Unknown')
self.__grid.FitInside() self.__grid.FitInside()
...@@ -260,11 +290,11 @@ class ComponentGrid(fslpanel.FSLEyesPanel): ...@@ -260,11 +290,11 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
def __labelsChanged(self, *a): def __labelsChanged(self, *a):
self.__recreateTags() self.__refreshTags()
def __lutChanged(self, *a): def __lutChanged(self, *a):
self.__recreateTags() self.__refreshTags()
......
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