From b5ed056f4a7965d6a86199233dae6fea5200080c Mon Sep 17 00:00:00 2001 From: ofgulban Date: Tue, 26 Sep 2017 19:10:21 +0200 Subject: [PATCH] Cosmetics - try except removed (it was giving pep8 error anyway) - highlights mechanism generalized to include large circle. --- segmentator/gui_utils.py | 41 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/segmentator/gui_utils.py b/segmentator/gui_utils.py index 69082a13..faba1bf9 100755 --- a/segmentator/gui_utils.py +++ b/segmentator/gui_utils.py @@ -44,7 +44,7 @@ def __init__(self, **kwargs): self.imaSlc = self.orig[:, :, self.sliceNr] # selected slice self.cycleCount = 0 self.cycRotHistory = [[0, 0], [0, 0], [0, 0]] - self.highlights = [] # to hold image to histogram circles + self.highlights = [[], []] # to hold image to histogram circles def remapMsks(self, remap_slice=True): """Update volume histogram to image mapping. @@ -163,13 +163,14 @@ def findVoxInHist(self, event): xpix = (pixelLin / self.nrBins) ypix = (pixelLin % self.nrBins) # Switch x and y for circle centre since back to Cartesian. - self.circle1 = plt.Circle((ypix, xpix), radius=5, edgecolor=None, - color=np.array([33, 113, 181, 255])/255) - self.highlights.append( - plt.Circle((ypix, xpix), radius=1, edgecolor=None, - color=np.array([8, 48, 107, 255])/255)) - self.axes.add_artist(self.circle1) - self.axes.add_artist(self.highlights[-1]) + circle_colors = [np.array([8, 48, 107, 255])/255, + np.array([33, 113, 181, 255])/255] + self.highlights[0].append(plt.Circle((ypix, xpix), radius=1, + edgecolor=None, color=circle_colors[0])) + self.highlights[1].append(plt.Circle((ypix, xpix), radius=5, + edgecolor=None, color=circle_colors[1])) + self.axes.add_artist(self.highlights[0][-1]) # small circle + self.axes.add_artist(self.highlights[1][-1]) # large circle self.figure.canvas.draw() def on_press(self, event): @@ -297,10 +298,9 @@ def on_motion(self, event): def on_release(self, event): """Determine what happens if mouse button is released.""" self.press = None - try: # remove highlight circle - self.circle1.remove() - except: - return + # Remove highlight circle + if self.highlights[1]: + self.highlights[1][-1].set_visible(False) self.figure.canvas.draw() def disconnect(self): @@ -402,9 +402,10 @@ def exportNifti(self, event): def clearOverlays(self): """Clear overlaid items such as circle highlights.""" - if self.highlights: - {h.remove() for h in self.highlights} - self.highlights = [] + if self.highlights[0]: + {h.remove() for h in self.highlights[0]} + {h.remove() for h in self.highlights[1]} + self.highlights[0] = [] def resetGlobal(self, event): """Reset stuff.""" @@ -514,11 +515,11 @@ def imaSlcMskTransSwitch(self): def volHistHighlightTransSwitch(self): """Update transparency of highlights to toggle transparency.""" self.volHistHighlightSwitch = (self.volHistHighlightSwitch+1) % 2 - if self.volHistHighlightSwitch == 1 and self.highlights: - if self.highlights: - {h.set_visible(False) for h in self.highlights} - elif self.volHistHighlightSwitch == 0 and self.highlights: - {h.set_visible(True) for h in self.highlights} + if self.volHistHighlightSwitch == 1 and self.highlights[0]: + if self.highlights[0]: + {h.set_visible(False) for h in self.highlights[0]} + elif self.volHistHighlightSwitch == 0 and self.highlights[0]: + {h.set_visible(True) for h in self.highlights[0]} self.figure.canvas.draw() def updateLabelsRadio(self, val):