Commit 1db06cb6f573242f8aebed8aa7c8e7a11c60d862
1 parent
c5c9a472
Exists in
master
and in
6 other branches
FIX: Problems related to remove mask and eye on data notebook
Showing
2 changed files
with
68 additions
and
44 deletions
Show diff stats
invesalius/data/slice_.py
@@ -88,15 +88,13 @@ class Slice(object): | @@ -88,15 +88,13 @@ class Slice(object): | ||
88 | ps.Publisher().subscribe(self.OnDuplicateMasks, 'Duplicate masks') | 88 | ps.Publisher().subscribe(self.OnDuplicateMasks, 'Duplicate masks') |
89 | 89 | ||
90 | def OnRemoveMasks(self, pubsub_evt): | 90 | def OnRemoveMasks(self, pubsub_evt): |
91 | - print "OnRemoveMasks" | ||
92 | selected_items = pubsub_evt.data | 91 | selected_items = pubsub_evt.data |
93 | - print "selected_items" | ||
94 | proj = Project() | 92 | proj = Project() |
95 | for item in selected_items: | 93 | for item in selected_items: |
96 | proj.RemoveMask(item) | 94 | proj.RemoveMask(item) |
97 | - | ||
98 | - index = self.current_mask.index | ||
99 | - if (proj.mask_dict) and (index in selected_items): | 95 | + #index = self.current_mask.index |
96 | + if (proj.mask_dict) and (self.current_mask.index in selected_items): | ||
97 | + self.current_mask = proj.mask_dict[0] | ||
100 | self.SelectCurrentMask(0) | 98 | self.SelectCurrentMask(0) |
101 | elif not proj.mask_dict: | 99 | elif not proj.mask_dict: |
102 | self.blend_filter.SetOpacity(1, 0) | 100 | self.blend_filter.SetOpacity(1, 0) |
@@ -245,7 +243,7 @@ class Slice(object): | @@ -245,7 +243,7 @@ class Slice(object): | ||
245 | 243 | ||
246 | colour_wx = [r*255, g*255, b*255] | 244 | colour_wx = [r*255, g*255, b*255] |
247 | ps.Publisher().sendMessage('Change mask colour in notebook', | 245 | ps.Publisher().sendMessage('Change mask colour in notebook', |
248 | - (self.current_mask.index, (r,g,b))) | 246 | + (index, (r,g,b))) |
249 | ps.Publisher().sendMessage('Set GUI items colour', colour_wx) | 247 | ps.Publisher().sendMessage('Set GUI items colour', colour_wx) |
250 | if update: | 248 | if update: |
251 | ps.Publisher().sendMessage('Update slice viewer') | 249 | ps.Publisher().sendMessage('Update slice viewer') |
@@ -368,22 +366,20 @@ class Slice(object): | @@ -368,22 +366,20 @@ class Slice(object): | ||
368 | self.current_mask = future_mask | 366 | self.current_mask = future_mask |
369 | 367 | ||
370 | colour = future_mask.colour | 368 | colour = future_mask.colour |
371 | - index = future_mask.index | 369 | + #index = future_mask.index |
372 | self.SetMaskColour(index, colour, update=False) | 370 | self.SetMaskColour(index, colour, update=False) |
373 | 371 | ||
374 | imagedata = future_mask.imagedata | 372 | imagedata = future_mask.imagedata |
375 | self.img_colours_mask.SetInput(imagedata) | 373 | self.img_colours_mask.SetInput(imagedata) |
376 | 374 | ||
377 | if self.current_mask.is_shown: | 375 | if self.current_mask.is_shown: |
378 | - print 1 | ||
379 | self.blend_filter.SetOpacity(1, self.current_mask.opacity) | 376 | self.blend_filter.SetOpacity(1, self.current_mask.opacity) |
380 | else: | 377 | else: |
381 | - print 2 | ||
382 | self.blend_filter.SetOpacity(1, 0) | 378 | self.blend_filter.SetOpacity(1, 0) |
383 | self.blend_filter.Update() | 379 | self.blend_filter.Update() |
384 | 380 | ||
385 | ps.Publisher().sendMessage('Set mask threshold in notebook', | 381 | ps.Publisher().sendMessage('Set mask threshold in notebook', |
386 | - (self.current_mask.index, | 382 | + (index, |
387 | self.current_mask.threshold_range)) | 383 | self.current_mask.threshold_range)) |
388 | ps.Publisher().sendMessage('Set threshold values in gradient', | 384 | ps.Publisher().sendMessage('Set threshold values in gradient', |
389 | self.current_mask.threshold_range) | 385 | self.current_mask.threshold_range) |
invesalius/gui/data_notebook.py
@@ -148,11 +148,13 @@ class ButtonControlPanel(wx.Panel): | @@ -148,11 +148,13 @@ class ButtonControlPanel(wx.Panel): | ||
148 | ps.Publisher().sendMessage('Create new mask', mask_name) | 148 | ps.Publisher().sendMessage('Create new mask', mask_name) |
149 | 149 | ||
150 | def OnRemove(self): | 150 | def OnRemove(self): |
151 | + print "button -- OnRemove" | ||
151 | selected_items = self.parent.listctrl.GetSelected() | 152 | selected_items = self.parent.listctrl.GetSelected() |
152 | if selected_items: | 153 | if selected_items: |
154 | + print selected_items | ||
155 | + ps.Publisher().sendMessage('Remove masks', selected_items) | ||
153 | for item in selected_items: | 156 | for item in selected_items: |
154 | self.parent.listctrl.RemoveMask(item) | 157 | self.parent.listctrl.RemoveMask(item) |
155 | - ps.Publisher().sendMessage('Remove masks', selected_items) | ||
156 | else: | 158 | else: |
157 | dlg.MaskSelectionRequiredForRemoval() | 159 | dlg.MaskSelectionRequiredForRemoval() |
158 | 160 | ||
@@ -175,6 +177,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -175,6 +177,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
175 | wx.ListCtrl.__init__(self, parent, ID, pos, size, style=wx.LC_REPORT) | 177 | wx.ListCtrl.__init__(self, parent, ID, pos, size, style=wx.LC_REPORT) |
176 | listmix.TextEditMixin.__init__(self) | 178 | listmix.TextEditMixin.__init__(self) |
177 | self.mask_list_index = {} | 179 | self.mask_list_index = {} |
180 | + self.current_index = 0 | ||
178 | self.__init_columns() | 181 | self.__init_columns() |
179 | self.__init_image_list() | 182 | self.__init_image_list() |
180 | self.__bind_events_wx() | 183 | self.__bind_events_wx() |
@@ -201,12 +204,14 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -201,12 +204,14 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
201 | # Delete key | 204 | # Delete key |
202 | if (sys.platform == 'darwin') and (keycode == wx.WXK_BACK): | 205 | if (sys.platform == 'darwin') and (keycode == wx.WXK_BACK): |
203 | selected = self.GetSelected() | 206 | selected = self.GetSelected() |
204 | - self.__remove_items() | 207 | + #self.__remove_items() |
208 | + ps.Publisher().sendMessage('Remove masks', selected) | ||
205 | for item in selected: | 209 | for item in selected: |
206 | self.RemoveMask(item) | 210 | self.RemoveMask(item) |
207 | elif (keycode == wx.WXK_DELETE): | 211 | elif (keycode == wx.WXK_DELETE): |
208 | selected = self.GetSelected() | 212 | selected = self.GetSelected() |
209 | - self.__remove_items() | 213 | + #self.__remove_items() |
214 | + ps.Publisher().sendMessage('Remove masks', selected) | ||
210 | for item in selected: | 215 | for item in selected: |
211 | self.RemoveMask(item) | 216 | self.RemoveMask(item) |
212 | 217 | ||
@@ -220,6 +225,48 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -220,6 +225,48 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
220 | self.RemoveMask(item) | 225 | self.RemoveMask(item) |
221 | ps.Publisher().sendMessage('Remove masks', selected_items) | 226 | ps.Publisher().sendMessage('Remove masks', selected_items) |
222 | 227 | ||
228 | + def RemoveMask(self, index): | ||
229 | + """ | ||
230 | + Remove item given its index. | ||
231 | + """ | ||
232 | + print "Remove item" | ||
233 | + # it is necessary to update internal dictionary | ||
234 | + # that maps bitmap given item index | ||
235 | + old_dict = self.mask_list_index | ||
236 | + print "current_index", self.current_index | ||
237 | + print "old_dict", old_dict | ||
238 | + new_dict = {} | ||
239 | + for i in old_dict: | ||
240 | + if i < index: | ||
241 | + new_dict[i] = old_dict[i] | ||
242 | + if i > index: | ||
243 | + new_dict[i-1] = old_dict[i] | ||
244 | + self.mask_list_index = new_dict | ||
245 | + print "new_dict", new_dict | ||
246 | + | ||
247 | + if new_dict and not index: | ||
248 | + print "gotta case" | ||
249 | + for key in new_dict: | ||
250 | + if key == 0: | ||
251 | + print ":)", key | ||
252 | + self.SetItemImage(key, 1) | ||
253 | + ps.Publisher().sendMessage('Show mask', (key, 1)) | ||
254 | + else: | ||
255 | + print ":(" | ||
256 | + self.SetItemImage(key, 0) | ||
257 | + | ||
258 | + self.DeleteItem(index) | ||
259 | + | ||
260 | + if new_dict: | ||
261 | + if self.current_index > index: | ||
262 | + self.current_index -= 1 | ||
263 | + elif self.current_index == index: | ||
264 | + print "XXXXXXXXXXXXX" | ||
265 | + self.current_index = 0 | ||
266 | + self.SetItemImage(0, 1) | ||
267 | + ps.Publisher().sendMessage('Show mask', (0, 1)) | ||
268 | + | ||
269 | + | ||
223 | 270 | ||
224 | 271 | ||
225 | def OnCloseProject(self, pubsub_evt): | 272 | def OnCloseProject(self, pubsub_evt): |
@@ -229,7 +276,10 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -229,7 +276,10 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
229 | def OnChangeCurrentMask(self, pubsub_evt): | 276 | def OnChangeCurrentMask(self, pubsub_evt): |
230 | mask_index = pubsub_evt.data | 277 | mask_index = pubsub_evt.data |
231 | try: | 278 | try: |
279 | + print "try" | ||
232 | self.SetItemImage(mask_index, 1) | 280 | self.SetItemImage(mask_index, 1) |
281 | + self.current_index = mask_index | ||
282 | + print "except" | ||
233 | except wx._core.PyAssertionError: | 283 | except wx._core.PyAssertionError: |
234 | #in SetItem(): invalid item index in SetItem | 284 | #in SetItem(): invalid item index in SetItem |
235 | pass | 285 | pass |
@@ -279,6 +329,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -279,6 +329,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
279 | if key != index: | 329 | if key != index: |
280 | self.SetItemImage(key, 0) | 330 | self.SetItemImage(key, 0) |
281 | ps.Publisher().sendMessage('Change mask selected',index) | 331 | ps.Publisher().sendMessage('Change mask selected',index) |
332 | + self.current_index = index | ||
282 | ps.Publisher().sendMessage('Show mask', (index, flag)) | 333 | ps.Publisher().sendMessage('Show mask', (index, flag)) |
283 | 334 | ||
284 | def CreateColourBitmap(self, colour): | 335 | def CreateColourBitmap(self, colour): |
@@ -309,6 +360,8 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -309,6 +360,8 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
309 | for key in self.mask_list_index.keys(): | 360 | for key in self.mask_list_index.keys(): |
310 | if key != index: | 361 | if key != index: |
311 | self.SetItemImage(key, 0) | 362 | self.SetItemImage(key, 0) |
363 | + self.current_index = index | ||
364 | + | ||
312 | 365 | ||
313 | def AddMask(self, pubsub_evt): | 366 | def AddMask(self, pubsub_evt): |
314 | index, mask_name, threshold_range, colour = pubsub_evt.data | 367 | index, mask_name, threshold_range, colour = pubsub_evt.data |
@@ -316,9 +369,10 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -316,9 +369,10 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
316 | image_index = self.imagelist.Add(image) | 369 | image_index = self.imagelist.Add(image) |
317 | self.mask_list_index[index] = image_index | 370 | self.mask_list_index[index] = image_index |
318 | self.InsertNewItem(index, mask_name, str(threshold_range)) | 371 | self.InsertNewItem(index, mask_name, str(threshold_range)) |
319 | - | 372 | + |
320 | def EditMaskThreshold(self, pubsub_evt): | 373 | def EditMaskThreshold(self, pubsub_evt): |
321 | index, threshold_range = pubsub_evt.data | 374 | index, threshold_range = pubsub_evt.data |
375 | + print "EditMaskThreshold: ", index | ||
322 | self.SetStringItem(index, 2, str(threshold_range)) | 376 | self.SetStringItem(index, 2, str(threshold_range)) |
323 | 377 | ||
324 | def EditMaskColour(self, pubsub_evt): | 378 | def EditMaskColour(self, pubsub_evt): |
@@ -342,33 +396,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -342,33 +396,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
342 | selected.sort(reverse=True) | 396 | selected.sort(reverse=True) |
343 | return selected | 397 | return selected |
344 | 398 | ||
345 | - def RemoveMask(self, index): | ||
346 | - """ | ||
347 | - Remove item given its index. | ||
348 | - """ | ||
349 | - # it is necessary to update internal dictionary | ||
350 | - # that maps bitmap given item index | ||
351 | - old_dict = self.mask_list_index | ||
352 | - new_dict = {} | ||
353 | - for i in old_dict: | ||
354 | - if i < index: | ||
355 | - new_dict[i] = old_dict[i] | ||
356 | - if i > index: | ||
357 | - new_dict[i-1] = old_dict[i] | ||
358 | - self.mask_list_index = new_dict | ||
359 | 399 | ||
360 | - if new_dict: | ||
361 | - for key in new_dict: | ||
362 | - if key == 0: | ||
363 | - self.SetItemImage(key, 1) | ||
364 | - ps.Publisher().sendMessage('Show mask', (key, 1)) | ||
365 | - | ||
366 | - # TODO: Understand why this is occuring and enhace code, so | ||
367 | - # this excpet is not necessary | ||
368 | - try: | ||
369 | - self.DeleteItem(index) | ||
370 | - except wx._core.PyAssertionError: | ||
371 | - ul.debug("tried to remove inexistent index") | ||
372 | 400 | ||
373 | #------------------------------------------------- | 401 | #------------------------------------------------- |
374 | class SurfacePage(wx.Panel): | 402 | class SurfacePage(wx.Panel): |
@@ -738,9 +766,11 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -738,9 +766,11 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
738 | """ | 766 | """ |
739 | Remove item given its index. | 767 | Remove item given its index. |
740 | """ | 768 | """ |
769 | + print "RemoveSurface" | ||
741 | # it is necessary to update internal dictionary | 770 | # it is necessary to update internal dictionary |
742 | # that maps bitmap given item index | 771 | # that maps bitmap given item index |
743 | old_dict = self.surface_list_index | 772 | old_dict = self.surface_list_index |
773 | + print old_dict | ||
744 | new_dict = {} | 774 | new_dict = {} |
745 | for i in old_dict: | 775 | for i in old_dict: |
746 | if i < index: | 776 | if i < index: |
@@ -748,11 +778,9 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -748,11 +778,9 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
748 | if i > index: | 778 | if i > index: |
749 | new_dict[i-1] = old_dict[i] | 779 | new_dict[i-1] = old_dict[i] |
750 | self.surface_list_index = new_dict | 780 | self.surface_list_index = new_dict |
781 | + print new_dict | ||
751 | 782 | ||
752 | - try: | ||
753 | - self.DeleteItem(index) | ||
754 | - except wx._core.PyAssertionError: | ||
755 | - ul.debug("tried to remove inexistent index") | 783 | + self.DeleteItem(index) |
756 | 784 | ||
757 | #------------------------------------------------- | 785 | #------------------------------------------------- |
758 | 786 |