Commit 40abd5b9a75b17b8d356a00087bb3b591de21a4f

Authored by Thiago Franco de Moraes
1 parent 335ce5cf

Better surface combobox manage

Showing 1 changed file with 34 additions and 25 deletions   Show diff stats
invesalius/gui/task_surface.py
... ... @@ -400,13 +400,12 @@ class SurfaceProperties(wx.Panel):
400 400 default_colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUBAR)
401 401 self.SetBackgroundColour(default_colour)
402 402  
403   - self.surface_dict = utl.TwoWaysDictionary()
  403 + self.surface_list = []
404 404  
405 405 ## LINE 1
406 406  
407 407 # Combo related to mask naem
408   - combo_surface_name = wx.ComboBox(self, -1, "", choices=
409   - self.surface_dict.keys() or ["", ],
  408 + combo_surface_name = wx.ComboBox(self, -1, "",
410 409 style=wx.CB_DROPDOWN|wx.CB_READONLY)
411 410 combo_surface_name.SetSelection(0)
412 411 if sys.platform != 'win32':
... ... @@ -476,20 +475,20 @@ class SurfaceProperties(wx.Panel):
476 475 def OnRemoveSurfaces(self, pubsub_evt):
477 476 list_index = pubsub_evt.data
478 477  
479   - old_dict = self.surface_dict
480   - new_dict = utl.TwoWaysDictionary()
481   - for index in list_index:
482   - self.combo_surface_name.Delete(index)
483   -
484   - for name in old_dict:
485   - if old_dict[name] < index:
486   - new_dict[name] = old_dict[name]
487   - if old_dict[name] > index:
488   - new_dict[name] = old_dict[name] -1
489   - old_dict = new_dict
490   - self.surface_dict = new_dict
  478 + old_dict = self.surface_list
  479 + new_dict = []
  480 + for n, (name, index) in enumerate(old_dict):
  481 + if n not in list_index:
  482 + new_dict.append([name, index])
  483 + self.surface_list = new_dict
491 484  
  485 + s = self.combo_surface_name.GetSelection()
  486 + self.combo_surface_name.SetItems([n[0] for n in self.surface_list])
492 487  
  488 + if s in list_index:
  489 + self.combo_surface_name.SetSelection(0)
  490 + else:
  491 + self.combo_surface_name.SetSelection(s)
493 492  
494 493 def OnCloseProject(self, pubsub_evt):
495 494 self.CloseProject()
... ... @@ -501,28 +500,38 @@ class SurfaceProperties(wx.Panel):
501 500  
502 501 def ChangeSurfaceName(self, pubsub_evt):
503 502 index, name = pubsub_evt.data
504   - old_name = self.surface_dict.get_key(index)
505   - self.surface_dict.remove(old_name)
506   - self.surface_dict[name] = index
  503 + self.surface_list[index][0] = name
507 504 self.combo_surface_name.SetString(index, name)
508   - self.combo_surface_name.Refresh()
  505 +
  506 + print ">>>> SURFACE DICT", self.surface_list
509 507  
510 508 def InsertNewSurface(self, pubsub_evt):
511 509 #not_update = len(pubsub_evt.data) == 5
512 510 index = pubsub_evt.data[0]
513 511 name = pubsub_evt.data[1]
514 512 colour = [value*255 for value in pubsub_evt.data[2]]
515   - overwrite = name in self.surface_dict.keys()
516   - #if index not in self.surface_dict.values():
517   - if not overwrite or not self.surface_dict:
518   - self.surface_dict[name] = index
519   - index = self.combo_surface_name.Append(name)
  513 + i = 0
  514 + try:
  515 + i = self.surface_list.index([name, index])
  516 + overwrite = True
  517 + except ValueError:
  518 + overwrite = False
  519 +
  520 + if overwrite:
  521 + self.surface_list[i] = [name, index]
  522 + else:
  523 + self.surface_list.append([name, index])
  524 + i = len(self.surface_list) - 1
  525 +
  526 + self.combo_surface_name.SetItems([n[0] for n in self.surface_list])
  527 + self.combo_surface_name.SetSelection(i)
520 528 transparency = 100*pubsub_evt.data[4]
521 529 self.button_colour.SetColour(colour)
522 530 self.slider_transparency.SetValue(transparency)
523   - self.combo_surface_name.SetSelection(index)
524 531 Publisher.sendMessage('Update surface data', (index))
525 532  
  533 +
  534 +
526 535 def OnComboName(self, evt):
527 536 surface_name = evt.GetString()
528 537 surface_index = evt.GetSelection()
... ...