Commit 1db06cb6f573242f8aebed8aa7c8e7a11c60d862
1 parent
c5c9a472
Exists in
master
and in
68 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 | 88 | ps.Publisher().subscribe(self.OnDuplicateMasks, 'Duplicate masks') |
89 | 89 | |
90 | 90 | def OnRemoveMasks(self, pubsub_evt): |
91 | - print "OnRemoveMasks" | |
92 | 91 | selected_items = pubsub_evt.data |
93 | - print "selected_items" | |
94 | 92 | proj = Project() |
95 | 93 | for item in selected_items: |
96 | 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 | 98 | self.SelectCurrentMask(0) |
101 | 99 | elif not proj.mask_dict: |
102 | 100 | self.blend_filter.SetOpacity(1, 0) |
... | ... | @@ -245,7 +243,7 @@ class Slice(object): |
245 | 243 | |
246 | 244 | colour_wx = [r*255, g*255, b*255] |
247 | 245 | ps.Publisher().sendMessage('Change mask colour in notebook', |
248 | - (self.current_mask.index, (r,g,b))) | |
246 | + (index, (r,g,b))) | |
249 | 247 | ps.Publisher().sendMessage('Set GUI items colour', colour_wx) |
250 | 248 | if update: |
251 | 249 | ps.Publisher().sendMessage('Update slice viewer') |
... | ... | @@ -368,22 +366,20 @@ class Slice(object): |
368 | 366 | self.current_mask = future_mask |
369 | 367 | |
370 | 368 | colour = future_mask.colour |
371 | - index = future_mask.index | |
369 | + #index = future_mask.index | |
372 | 370 | self.SetMaskColour(index, colour, update=False) |
373 | 371 | |
374 | 372 | imagedata = future_mask.imagedata |
375 | 373 | self.img_colours_mask.SetInput(imagedata) |
376 | 374 | |
377 | 375 | if self.current_mask.is_shown: |
378 | - print 1 | |
379 | 376 | self.blend_filter.SetOpacity(1, self.current_mask.opacity) |
380 | 377 | else: |
381 | - print 2 | |
382 | 378 | self.blend_filter.SetOpacity(1, 0) |
383 | 379 | self.blend_filter.Update() |
384 | 380 | |
385 | 381 | ps.Publisher().sendMessage('Set mask threshold in notebook', |
386 | - (self.current_mask.index, | |
382 | + (index, | |
387 | 383 | self.current_mask.threshold_range)) |
388 | 384 | ps.Publisher().sendMessage('Set threshold values in gradient', |
389 | 385 | self.current_mask.threshold_range) | ... | ... |
invesalius/gui/data_notebook.py
... | ... | @@ -148,11 +148,13 @@ class ButtonControlPanel(wx.Panel): |
148 | 148 | ps.Publisher().sendMessage('Create new mask', mask_name) |
149 | 149 | |
150 | 150 | def OnRemove(self): |
151 | + print "button -- OnRemove" | |
151 | 152 | selected_items = self.parent.listctrl.GetSelected() |
152 | 153 | if selected_items: |
154 | + print selected_items | |
155 | + ps.Publisher().sendMessage('Remove masks', selected_items) | |
153 | 156 | for item in selected_items: |
154 | 157 | self.parent.listctrl.RemoveMask(item) |
155 | - ps.Publisher().sendMessage('Remove masks', selected_items) | |
156 | 158 | else: |
157 | 159 | dlg.MaskSelectionRequiredForRemoval() |
158 | 160 | |
... | ... | @@ -175,6 +177,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
175 | 177 | wx.ListCtrl.__init__(self, parent, ID, pos, size, style=wx.LC_REPORT) |
176 | 178 | listmix.TextEditMixin.__init__(self) |
177 | 179 | self.mask_list_index = {} |
180 | + self.current_index = 0 | |
178 | 181 | self.__init_columns() |
179 | 182 | self.__init_image_list() |
180 | 183 | self.__bind_events_wx() |
... | ... | @@ -201,12 +204,14 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
201 | 204 | # Delete key |
202 | 205 | if (sys.platform == 'darwin') and (keycode == wx.WXK_BACK): |
203 | 206 | selected = self.GetSelected() |
204 | - self.__remove_items() | |
207 | + #self.__remove_items() | |
208 | + ps.Publisher().sendMessage('Remove masks', selected) | |
205 | 209 | for item in selected: |
206 | 210 | self.RemoveMask(item) |
207 | 211 | elif (keycode == wx.WXK_DELETE): |
208 | 212 | selected = self.GetSelected() |
209 | - self.__remove_items() | |
213 | + #self.__remove_items() | |
214 | + ps.Publisher().sendMessage('Remove masks', selected) | |
210 | 215 | for item in selected: |
211 | 216 | self.RemoveMask(item) |
212 | 217 | |
... | ... | @@ -220,6 +225,48 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
220 | 225 | self.RemoveMask(item) |
221 | 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 | 272 | def OnCloseProject(self, pubsub_evt): |
... | ... | @@ -229,7 +276,10 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
229 | 276 | def OnChangeCurrentMask(self, pubsub_evt): |
230 | 277 | mask_index = pubsub_evt.data |
231 | 278 | try: |
279 | + print "try" | |
232 | 280 | self.SetItemImage(mask_index, 1) |
281 | + self.current_index = mask_index | |
282 | + print "except" | |
233 | 283 | except wx._core.PyAssertionError: |
234 | 284 | #in SetItem(): invalid item index in SetItem |
235 | 285 | pass |
... | ... | @@ -279,6 +329,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
279 | 329 | if key != index: |
280 | 330 | self.SetItemImage(key, 0) |
281 | 331 | ps.Publisher().sendMessage('Change mask selected',index) |
332 | + self.current_index = index | |
282 | 333 | ps.Publisher().sendMessage('Show mask', (index, flag)) |
283 | 334 | |
284 | 335 | def CreateColourBitmap(self, colour): |
... | ... | @@ -309,6 +360,8 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
309 | 360 | for key in self.mask_list_index.keys(): |
310 | 361 | if key != index: |
311 | 362 | self.SetItemImage(key, 0) |
363 | + self.current_index = index | |
364 | + | |
312 | 365 | |
313 | 366 | def AddMask(self, pubsub_evt): |
314 | 367 | index, mask_name, threshold_range, colour = pubsub_evt.data |
... | ... | @@ -316,9 +369,10 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
316 | 369 | image_index = self.imagelist.Add(image) |
317 | 370 | self.mask_list_index[index] = image_index |
318 | 371 | self.InsertNewItem(index, mask_name, str(threshold_range)) |
319 | - | |
372 | + | |
320 | 373 | def EditMaskThreshold(self, pubsub_evt): |
321 | 374 | index, threshold_range = pubsub_evt.data |
375 | + print "EditMaskThreshold: ", index | |
322 | 376 | self.SetStringItem(index, 2, str(threshold_range)) |
323 | 377 | |
324 | 378 | def EditMaskColour(self, pubsub_evt): |
... | ... | @@ -342,33 +396,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
342 | 396 | selected.sort(reverse=True) |
343 | 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 | 402 | class SurfacePage(wx.Panel): |
... | ... | @@ -738,9 +766,11 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
738 | 766 | """ |
739 | 767 | Remove item given its index. |
740 | 768 | """ |
769 | + print "RemoveSurface" | |
741 | 770 | # it is necessary to update internal dictionary |
742 | 771 | # that maps bitmap given item index |
743 | 772 | old_dict = self.surface_list_index |
773 | + print old_dict | |
744 | 774 | new_dict = {} |
745 | 775 | for i in old_dict: |
746 | 776 | if i < index: |
... | ... | @@ -748,11 +778,9 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): |
748 | 778 | if i > index: |
749 | 779 | new_dict[i-1] = old_dict[i] |
750 | 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 | ... | ... |