Commit f6b001ebc009a7180961e2fcd80182d1c61e4ea9
Committed by
Thiago Franco de Moraes
1 parent
71982a56
Exists in
master
and in
6 other branches
Markers manipulation improvement (#81)
* working * Blink the selected marker in listctrl * Delete all selected items in the list ctrl * Trigger improvements * Fixed panel size
Showing
3 changed files
with
89 additions
and
26 deletions
Show diff stats
invesalius/data/trigger.py
| @@ -32,6 +32,8 @@ class Trigger(threading.Thread): | @@ -32,6 +32,8 @@ class Trigger(threading.Thread): | ||
| 32 | def __init__(self, nav_id): | 32 | def __init__(self, nav_id): |
| 33 | threading.Thread.__init__(self) | 33 | threading.Thread.__init__(self) |
| 34 | self.trigger_init = None | 34 | self.trigger_init = None |
| 35 | + self.stylusplh = False | ||
| 36 | + self.__bind_events() | ||
| 35 | try: | 37 | try: |
| 36 | import serial | 38 | import serial |
| 37 | 39 | ||
| @@ -46,6 +48,12 @@ class Trigger(threading.Thread): | @@ -46,6 +48,12 @@ class Trigger(threading.Thread): | ||
| 46 | except serial.serialutil.SerialException: | 48 | except serial.serialutil.SerialException: |
| 47 | print 'Connection with port COM1 failed.' | 49 | print 'Connection with port COM1 failed.' |
| 48 | 50 | ||
| 51 | + def __bind_events(self): | ||
| 52 | + Publisher.subscribe(self.OnStylusPLH, 'PLH Stylus Button On') | ||
| 53 | + | ||
| 54 | + def OnStylusPLH(self, pubsuv_evt): | ||
| 55 | + self.stylusplh = True | ||
| 56 | + | ||
| 49 | def stop(self): | 57 | def stop(self): |
| 50 | self._pause_ = True | 58 | self._pause_ = True |
| 51 | 59 | ||
| @@ -59,6 +67,13 @@ class Trigger(threading.Thread): | @@ -59,6 +67,13 @@ class Trigger(threading.Thread): | ||
| 59 | # lines = True | 67 | # lines = True |
| 60 | if lines: | 68 | if lines: |
| 61 | wx.CallAfter(Publisher.sendMessage, 'Create marker') | 69 | wx.CallAfter(Publisher.sendMessage, 'Create marker') |
| 70 | + sleep(0.5) | ||
| 71 | + | ||
| 72 | + if self.stylusplh: | ||
| 73 | + wx.CallAfter(Publisher.sendMessage, 'Create marker') | ||
| 74 | + sleep(0.5) | ||
| 75 | + self.stylusplh = False | ||
| 76 | + | ||
| 62 | sleep(0.175) | 77 | sleep(0.175) |
| 63 | if self._pause_: | 78 | if self._pause_: |
| 64 | if self.trigger_init: | 79 | if self.trigger_init: |
invesalius/data/viewer_volume.py
| @@ -123,6 +123,9 @@ class Viewer(wx.Panel): | @@ -123,6 +123,9 @@ class Viewer(wx.Panel): | ||
| 123 | self.sen1 = False | 123 | self.sen1 = False |
| 124 | self.sen2 = False | 124 | self.sen2 = False |
| 125 | 125 | ||
| 126 | + self.timer = False | ||
| 127 | + self.index = False | ||
| 128 | + | ||
| 126 | def __bind_events(self): | 129 | def __bind_events(self): |
| 127 | Publisher.subscribe(self.LoadActor, | 130 | Publisher.subscribe(self.LoadActor, |
| 128 | 'Load surface actor into viewer') | 131 | 'Load surface actor into viewer') |
| @@ -203,6 +206,8 @@ class Viewer(wx.Panel): | @@ -203,6 +206,8 @@ class Viewer(wx.Panel): | ||
| 203 | Publisher.subscribe(self.ShowAllMarkers, 'Show all markers') | 206 | Publisher.subscribe(self.ShowAllMarkers, 'Show all markers') |
| 204 | Publisher.subscribe(self.RemoveAllMarkers, 'Remove all markers') | 207 | Publisher.subscribe(self.RemoveAllMarkers, 'Remove all markers') |
| 205 | Publisher.subscribe(self.RemoveMarker, 'Remove marker') | 208 | Publisher.subscribe(self.RemoveMarker, 'Remove marker') |
| 209 | + Publisher.subscribe(self.BlinkMarker, 'Blink Marker') | ||
| 210 | + Publisher.subscribe(self.StopBlinkMarker, 'Stop Blink Marker') | ||
| 206 | 211 | ||
| 207 | def SetStereoMode(self, pubsub_evt): | 212 | def SetStereoMode(self, pubsub_evt): |
| 208 | mode = pubsub_evt.data | 213 | mode = pubsub_evt.data |
| @@ -478,11 +483,35 @@ class Viewer(wx.Panel): | @@ -478,11 +483,35 @@ class Viewer(wx.Panel): | ||
| 478 | 483 | ||
| 479 | def RemoveMarker(self, pubsub_evt): | 484 | def RemoveMarker(self, pubsub_evt): |
| 480 | index = pubsub_evt.data | 485 | index = pubsub_evt.data |
| 481 | - self.ren.RemoveActor(self.staticballs[index]) | ||
| 482 | - del self.staticballs[index] | ||
| 483 | - self.ball_id = self.ball_id - 1 | 486 | + for i in reversed(index): |
| 487 | + self.ren.RemoveActor(self.staticballs[i]) | ||
| 488 | + del self.staticballs[i] | ||
| 489 | + self.ball_id = self.ball_id - 1 | ||
| 484 | self.UpdateRender() | 490 | self.UpdateRender() |
| 485 | 491 | ||
| 492 | + def BlinkMarker(self, pubsub_evt): | ||
| 493 | + if self.timer: | ||
| 494 | + self.timer.Stop() | ||
| 495 | + self.staticballs[self.index].SetVisibility(1) | ||
| 496 | + self.index = pubsub_evt.data | ||
| 497 | + self.timer = wx.Timer(self) | ||
| 498 | + self.Bind(wx.EVT_TIMER, self.blink, self.timer) | ||
| 499 | + self.timer.Start(500) | ||
| 500 | + self.timer_count = 0 | ||
| 501 | + | ||
| 502 | + def blink(self, evt): | ||
| 503 | + self.staticballs[self.index].SetVisibility(int(self.timer_count % 2)) | ||
| 504 | + self.Refresh() | ||
| 505 | + self.timer_count += 1 | ||
| 506 | + | ||
| 507 | + def StopBlinkMarker(self, pubsub_evt): | ||
| 508 | + if self.timer: | ||
| 509 | + self.timer.Stop() | ||
| 510 | + if pubsub_evt.data == None: | ||
| 511 | + self.staticballs[self.index].SetVisibility(1) | ||
| 512 | + self.Refresh() | ||
| 513 | + self.index = False | ||
| 514 | + | ||
| 486 | def CreateBallReference(self): | 515 | def CreateBallReference(self): |
| 487 | """ | 516 | """ |
| 488 | Red sphere on volume visualization to reference center of | 517 | Red sphere on volume visualization to reference center of |
| @@ -1028,7 +1057,6 @@ class Viewer(wx.Panel): | @@ -1028,7 +1057,6 @@ class Viewer(wx.Panel): | ||
| 1028 | self.RemoveBallReference() | 1057 | self.RemoveBallReference() |
| 1029 | self.interactor.Render() | 1058 | self.interactor.Render() |
| 1030 | 1059 | ||
| 1031 | - | ||
| 1032 | class SlicePlane: | 1060 | class SlicePlane: |
| 1033 | def __init__(self): | 1061 | def __init__(self): |
| 1034 | project = prj.Project() | 1062 | project = prj.Project() |
invesalius/gui/task_navigator.py
| @@ -114,10 +114,13 @@ class InnerFoldPanel(wx.Panel): | @@ -114,10 +114,13 @@ class InnerFoldPanel(wx.Panel): | ||
| 114 | # is not working properly in this panel. It might be on some child or | 114 | # is not working properly in this panel. It might be on some child or |
| 115 | # parent panel. Perhaps we need to insert the item into the sizer also... | 115 | # parent panel. Perhaps we need to insert the item into the sizer also... |
| 116 | # Study this. | 116 | # Study this. |
| 117 | - | ||
| 118 | - fold_panel = fpb.FoldPanelBar(self, -1, wx.DefaultPosition, | ||
| 119 | - (10, 293), 0, fpb.FPB_SINGLE_FOLD) | ||
| 120 | - | 117 | + displaySize = wx.DisplaySize() |
| 118 | + if displaySize[1] > 768: | ||
| 119 | + fold_panel = fpb.FoldPanelBar(self, -1, wx.DefaultPosition, | ||
| 120 | + (10, 350), 0, fpb.FPB_SINGLE_FOLD) | ||
| 121 | + else: | ||
| 122 | + fold_panel = fpb.FoldPanelBar(self, -1, wx.DefaultPosition, | ||
| 123 | + (10, 293), 0, fpb.FPB_SINGLE_FOLD) | ||
| 121 | # Fold panel style | 124 | # Fold panel style |
| 122 | style = fpb.CaptionBarStyle() | 125 | style = fpb.CaptionBarStyle() |
| 123 | style.SetCaptionStyle(fpb.CAPTIONBAR_GRADIENT_V) | 126 | style.SetCaptionStyle(fpb.CAPTIONBAR_GRADIENT_V) |
| @@ -243,7 +246,7 @@ class NeuronavigationPanel(wx.Panel): | @@ -243,7 +246,7 @@ class NeuronavigationPanel(wx.Panel): | ||
| 243 | for k in btns_img: | 246 | for k in btns_img: |
| 244 | n = btns_img[k].keys()[0] | 247 | n = btns_img[k].keys()[0] |
| 245 | lab = btns_img[k].values()[0] | 248 | lab = btns_img[k].values()[0] |
| 246 | - self.btns_coord[n] = wx.ToggleButton(self, k, label=lab, size=wx.Size(30, 23)) | 249 | + self.btns_coord[n] = wx.ToggleButton(self, k, label=lab, size=wx.Size(45, 23)) |
| 247 | self.btns_coord[n].SetToolTip(tips_img[n]) | 250 | self.btns_coord[n].SetToolTip(tips_img[n]) |
| 248 | self.btns_coord[n].Bind(wx.EVT_TOGGLEBUTTON, self.OnImageFiducials) | 251 | self.btns_coord[n].Bind(wx.EVT_TOGGLEBUTTON, self.OnImageFiducials) |
| 249 | 252 | ||
| @@ -254,7 +257,7 @@ class NeuronavigationPanel(wx.Panel): | @@ -254,7 +257,7 @@ class NeuronavigationPanel(wx.Panel): | ||
| 254 | for k in btns_trk: | 257 | for k in btns_trk: |
| 255 | n = btns_trk[k].keys()[0] | 258 | n = btns_trk[k].keys()[0] |
| 256 | lab = btns_trk[k].values()[0] | 259 | lab = btns_trk[k].values()[0] |
| 257 | - self.btns_coord[n] = wx.Button(self, k, label=lab, size=wx.Size(30, 23)) | 260 | + self.btns_coord[n] = wx.Button(self, k, label=lab, size=wx.Size(45, 23)) |
| 258 | self.btns_coord[n].SetToolTip(tips_trk[n-3]) | 261 | self.btns_coord[n].SetToolTip(tips_trk[n-3]) |
| 259 | # Excepetion for event of button that set image coordinates | 262 | # Excepetion for event of button that set image coordinates |
| 260 | if n == 6: | 263 | if n == 6: |
| @@ -325,7 +328,6 @@ class NeuronavigationPanel(wx.Panel): | @@ -325,7 +328,6 @@ class NeuronavigationPanel(wx.Panel): | ||
| 325 | Publisher.subscribe(self.UpdateTriggerState, 'Update trigger state') | 328 | Publisher.subscribe(self.UpdateTriggerState, 'Update trigger state') |
| 326 | Publisher.subscribe(self.UpdateImageCoordinates, 'Set ball reference position') | 329 | Publisher.subscribe(self.UpdateImageCoordinates, 'Set ball reference position') |
| 327 | Publisher.subscribe(self.OnDisconnectTracker, 'Disconnect tracker') | 330 | Publisher.subscribe(self.OnDisconnectTracker, 'Disconnect tracker') |
| 328 | - Publisher.subscribe(self.OnStylusButton, 'PLH Stylus Button On') | ||
| 329 | 331 | ||
| 330 | def LoadImageFiducials(self, pubsub_evt): | 332 | def LoadImageFiducials(self, pubsub_evt): |
| 331 | marker_id = pubsub_evt.data[0] | 333 | marker_id = pubsub_evt.data[0] |
| @@ -359,10 +361,6 @@ class NeuronavigationPanel(wx.Panel): | @@ -359,10 +361,6 @@ class NeuronavigationPanel(wx.Panel): | ||
| 359 | if self.tracker_id: | 361 | if self.tracker_id: |
| 360 | dt.TrackerConnection(self.tracker_id, 'disconnect') | 362 | dt.TrackerConnection(self.tracker_id, 'disconnect') |
| 361 | 363 | ||
| 362 | - def OnStylusButton(self, pubsub_evt): | ||
| 363 | - if self.trigger_state: | ||
| 364 | - Publisher.sendMessage('Create marker') | ||
| 365 | - | ||
| 366 | def OnChoiceTracker(self, evt, ctrl): | 364 | def OnChoiceTracker(self, evt, ctrl): |
| 367 | Publisher.sendMessage('Update status text in GUI', _("Configuring tracker ...")) | 365 | Publisher.sendMessage('Update status text in GUI', _("Configuring tracker ...")) |
| 368 | if evt: | 366 | if evt: |
| @@ -592,7 +590,7 @@ class MarkersPanel(wx.Panel): | @@ -592,7 +590,7 @@ class MarkersPanel(wx.Panel): | ||
| 592 | btn_delete_single = wx.Button(self, -1, label=_('Remove'), size=wx.Size(65, 23)) | 590 | btn_delete_single = wx.Button(self, -1, label=_('Remove'), size=wx.Size(65, 23)) |
| 593 | btn_delete_single.Bind(wx.EVT_BUTTON, self.OnDeleteSingleMarker) | 591 | btn_delete_single.Bind(wx.EVT_BUTTON, self.OnDeleteSingleMarker) |
| 594 | 592 | ||
| 595 | - btn_delete_all = wx.Button(self, -1, label=_('Delete all markers'), size=wx.Size(135, 23)) | 593 | + btn_delete_all = wx.Button(self, -1, label=_('Delete all'), size=wx.Size(135, 23)) |
| 596 | btn_delete_all.Bind(wx.EVT_BUTTON, self.OnDeleteAllMarkers) | 594 | btn_delete_all.Bind(wx.EVT_BUTTON, self.OnDeleteAllMarkers) |
| 597 | 595 | ||
| 598 | sizer_delete = wx.FlexGridSizer(rows=1, cols=2, hgap=5, vgap=5) | 596 | sizer_delete = wx.FlexGridSizer(rows=1, cols=2, hgap=5, vgap=5) |
| @@ -612,6 +610,8 @@ class MarkersPanel(wx.Panel): | @@ -612,6 +610,8 @@ class MarkersPanel(wx.Panel): | ||
| 612 | self.lc.SetColumnWidth(3, 50) | 610 | self.lc.SetColumnWidth(3, 50) |
| 613 | self.lc.SetColumnWidth(4, 50) | 611 | self.lc.SetColumnWidth(4, 50) |
| 614 | self.lc.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnListEditMarkerId) | 612 | self.lc.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnListEditMarkerId) |
| 613 | + self.lc.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemBlink) | ||
| 614 | + self.lc.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnStopItemBlink) | ||
| 615 | 615 | ||
| 616 | # Add all lines into main sizer | 616 | # Add all lines into main sizer |
| 617 | group_sizer = wx.BoxSizer(wx.VERTICAL) | 617 | group_sizer = wx.BoxSizer(wx.VERTICAL) |
| @@ -639,6 +639,12 @@ class MarkersPanel(wx.Panel): | @@ -639,6 +639,12 @@ class MarkersPanel(wx.Panel): | ||
| 639 | self.PopupMenu(menu_id) | 639 | self.PopupMenu(menu_id) |
| 640 | menu_id.Destroy() | 640 | menu_id.Destroy() |
| 641 | 641 | ||
| 642 | + def OnItemBlink(self, evt): | ||
| 643 | + Publisher.sendMessage('Blink Marker', self.lc.GetFocusedItem()) | ||
| 644 | + | ||
| 645 | + def OnStopItemBlink(self, evt): | ||
| 646 | + Publisher.sendMessage('Stop Blink Marker') | ||
| 647 | + | ||
| 642 | def OnMenuEditMarkerId(self, evt): | 648 | def OnMenuEditMarkerId(self, evt): |
| 643 | id_label = dlg.EnterMarkerID(self.lc.GetItemText(self.lc.GetFocusedItem(), 4)) | 649 | id_label = dlg.EnterMarkerID(self.lc.GetItemText(self.lc.GetFocusedItem(), 4)) |
| 644 | list_index = self.lc.GetFocusedItem() | 650 | list_index = self.lc.GetFocusedItem() |
| @@ -653,6 +659,7 @@ class MarkersPanel(wx.Panel): | @@ -653,6 +659,7 @@ class MarkersPanel(wx.Panel): | ||
| 653 | self.marker_ind = 0 | 659 | self.marker_ind = 0 |
| 654 | Publisher.sendMessage('Remove all markers', self.lc.GetItemCount()) | 660 | Publisher.sendMessage('Remove all markers', self.lc.GetItemCount()) |
| 655 | self.lc.DeleteAllItems() | 661 | self.lc.DeleteAllItems() |
| 662 | + Publisher.sendMessage('Stop Blink Marker', 'DeleteAll') | ||
| 656 | 663 | ||
| 657 | def OnDeleteSingleMarker(self, evt): | 664 | def OnDeleteSingleMarker(self, evt): |
| 658 | # OnDeleteSingleMarker is used for both pubsub and button click events | 665 | # OnDeleteSingleMarker is used for both pubsub and button click events |
| @@ -667,22 +674,23 @@ class MarkersPanel(wx.Panel): | @@ -667,22 +674,23 @@ class MarkersPanel(wx.Panel): | ||
| 667 | for i in const.BTNS_IMG_MKS: | 674 | for i in const.BTNS_IMG_MKS: |
| 668 | if marker_id in const.BTNS_IMG_MKS[i].values()[0]: | 675 | if marker_id in const.BTNS_IMG_MKS[i].values()[0]: |
| 669 | self.lc.Focus(item.GetId()) | 676 | self.lc.Focus(item.GetId()) |
| 670 | - self.DeleteMarker() | 677 | + index = [self.lc.GetFocusedItem()] |
| 671 | else: | 678 | else: |
| 672 | if self.lc.GetFocusedItem() is not -1: | 679 | if self.lc.GetFocusedItem() is not -1: |
| 673 | - self.DeleteMarker() | 680 | + index = self.GetSelectedItems() |
| 674 | elif not self.lc.GetItemCount(): | 681 | elif not self.lc.GetItemCount(): |
| 675 | pass | 682 | pass |
| 676 | else: | 683 | else: |
| 677 | dlg.NoMarkerSelected() | 684 | dlg.NoMarkerSelected() |
| 678 | - | ||
| 679 | - def DeleteMarker(self): | ||
| 680 | - index = self.lc.GetFocusedItem() | ||
| 681 | - del self.list_coord[index] | ||
| 682 | - self.lc.DeleteItem(index) | ||
| 683 | - for n in range(0, self.lc.GetItemCount()): | ||
| 684 | - self.lc.SetStringItem(n, 0, str(n+1)) | ||
| 685 | - self.marker_ind -= 1 | 685 | + self.DeleteMarker(index) |
| 686 | + | ||
| 687 | + def DeleteMarker(self, index): | ||
| 688 | + for i in reversed(index): | ||
| 689 | + del self.list_coord[i] | ||
| 690 | + self.lc.DeleteItem(i) | ||
| 691 | + for n in range(0, self.lc.GetItemCount()): | ||
| 692 | + self.lc.SetStringItem(n, 0, str(n+1)) | ||
| 693 | + self.marker_ind -= 1 | ||
| 686 | Publisher.sendMessage('Remove marker', index) | 694 | Publisher.sendMessage('Remove marker', index) |
| 687 | 695 | ||
| 688 | def OnCreateMarker(self, evt): | 696 | def OnCreateMarker(self, evt): |
| @@ -777,3 +785,15 @@ class MarkersPanel(wx.Panel): | @@ -777,3 +785,15 @@ class MarkersPanel(wx.Panel): | ||
| 777 | self.lc.SetStringItem(num_items, 3, str(round(coord[2], 2))) | 785 | self.lc.SetStringItem(num_items, 3, str(round(coord[2], 2))) |
| 778 | self.lc.SetStringItem(num_items, 4, str(marker_id)) | 786 | self.lc.SetStringItem(num_items, 4, str(marker_id)) |
| 779 | self.lc.EnsureVisible(num_items) | 787 | self.lc.EnsureVisible(num_items) |
| 788 | + | ||
| 789 | + def GetSelectedItems(self): | ||
| 790 | + """ | ||
| 791 | + Returns a list of the selected items in the list control. | ||
| 792 | + """ | ||
| 793 | + selection = [] | ||
| 794 | + index = self.lc.GetFirstSelected() | ||
| 795 | + selection.append(index) | ||
| 796 | + while len(selection) != self.lc.GetSelectedItemCount(): | ||
| 797 | + index = self.lc.GetNextSelected(index) | ||
| 798 | + selection.append(index) | ||
| 799 | + return selection | ||
| 780 | \ No newline at end of file | 800 | \ No newline at end of file |