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 | 32 | def __init__(self, nav_id): |
| 33 | 33 | threading.Thread.__init__(self) |
| 34 | 34 | self.trigger_init = None |
| 35 | + self.stylusplh = False | |
| 36 | + self.__bind_events() | |
| 35 | 37 | try: |
| 36 | 38 | import serial |
| 37 | 39 | |
| ... | ... | @@ -46,6 +48,12 @@ class Trigger(threading.Thread): |
| 46 | 48 | except serial.serialutil.SerialException: |
| 47 | 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 | 57 | def stop(self): |
| 50 | 58 | self._pause_ = True |
| 51 | 59 | |
| ... | ... | @@ -59,6 +67,13 @@ class Trigger(threading.Thread): |
| 59 | 67 | # lines = True |
| 60 | 68 | if lines: |
| 61 | 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 | 77 | sleep(0.175) |
| 63 | 78 | if self._pause_: |
| 64 | 79 | if self.trigger_init: | ... | ... |
invesalius/data/viewer_volume.py
| ... | ... | @@ -123,6 +123,9 @@ class Viewer(wx.Panel): |
| 123 | 123 | self.sen1 = False |
| 124 | 124 | self.sen2 = False |
| 125 | 125 | |
| 126 | + self.timer = False | |
| 127 | + self.index = False | |
| 128 | + | |
| 126 | 129 | def __bind_events(self): |
| 127 | 130 | Publisher.subscribe(self.LoadActor, |
| 128 | 131 | 'Load surface actor into viewer') |
| ... | ... | @@ -203,6 +206,8 @@ class Viewer(wx.Panel): |
| 203 | 206 | Publisher.subscribe(self.ShowAllMarkers, 'Show all markers') |
| 204 | 207 | Publisher.subscribe(self.RemoveAllMarkers, 'Remove all markers') |
| 205 | 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 | 212 | def SetStereoMode(self, pubsub_evt): |
| 208 | 213 | mode = pubsub_evt.data |
| ... | ... | @@ -478,11 +483,35 @@ class Viewer(wx.Panel): |
| 478 | 483 | |
| 479 | 484 | def RemoveMarker(self, pubsub_evt): |
| 480 | 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 | 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 | 515 | def CreateBallReference(self): |
| 487 | 516 | """ |
| 488 | 517 | Red sphere on volume visualization to reference center of |
| ... | ... | @@ -1028,7 +1057,6 @@ class Viewer(wx.Panel): |
| 1028 | 1057 | self.RemoveBallReference() |
| 1029 | 1058 | self.interactor.Render() |
| 1030 | 1059 | |
| 1031 | - | |
| 1032 | 1060 | class SlicePlane: |
| 1033 | 1061 | def __init__(self): |
| 1034 | 1062 | project = prj.Project() | ... | ... |
invesalius/gui/task_navigator.py
| ... | ... | @@ -114,10 +114,13 @@ class InnerFoldPanel(wx.Panel): |
| 114 | 114 | # is not working properly in this panel. It might be on some child or |
| 115 | 115 | # parent panel. Perhaps we need to insert the item into the sizer also... |
| 116 | 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 | 124 | # Fold panel style |
| 122 | 125 | style = fpb.CaptionBarStyle() |
| 123 | 126 | style.SetCaptionStyle(fpb.CAPTIONBAR_GRADIENT_V) |
| ... | ... | @@ -243,7 +246,7 @@ class NeuronavigationPanel(wx.Panel): |
| 243 | 246 | for k in btns_img: |
| 244 | 247 | n = btns_img[k].keys()[0] |
| 245 | 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 | 250 | self.btns_coord[n].SetToolTip(tips_img[n]) |
| 248 | 251 | self.btns_coord[n].Bind(wx.EVT_TOGGLEBUTTON, self.OnImageFiducials) |
| 249 | 252 | |
| ... | ... | @@ -254,7 +257,7 @@ class NeuronavigationPanel(wx.Panel): |
| 254 | 257 | for k in btns_trk: |
| 255 | 258 | n = btns_trk[k].keys()[0] |
| 256 | 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 | 261 | self.btns_coord[n].SetToolTip(tips_trk[n-3]) |
| 259 | 262 | # Excepetion for event of button that set image coordinates |
| 260 | 263 | if n == 6: |
| ... | ... | @@ -325,7 +328,6 @@ class NeuronavigationPanel(wx.Panel): |
| 325 | 328 | Publisher.subscribe(self.UpdateTriggerState, 'Update trigger state') |
| 326 | 329 | Publisher.subscribe(self.UpdateImageCoordinates, 'Set ball reference position') |
| 327 | 330 | Publisher.subscribe(self.OnDisconnectTracker, 'Disconnect tracker') |
| 328 | - Publisher.subscribe(self.OnStylusButton, 'PLH Stylus Button On') | |
| 329 | 331 | |
| 330 | 332 | def LoadImageFiducials(self, pubsub_evt): |
| 331 | 333 | marker_id = pubsub_evt.data[0] |
| ... | ... | @@ -359,10 +361,6 @@ class NeuronavigationPanel(wx.Panel): |
| 359 | 361 | if self.tracker_id: |
| 360 | 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 | 364 | def OnChoiceTracker(self, evt, ctrl): |
| 367 | 365 | Publisher.sendMessage('Update status text in GUI', _("Configuring tracker ...")) |
| 368 | 366 | if evt: |
| ... | ... | @@ -592,7 +590,7 @@ class MarkersPanel(wx.Panel): |
| 592 | 590 | btn_delete_single = wx.Button(self, -1, label=_('Remove'), size=wx.Size(65, 23)) |
| 593 | 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 | 594 | btn_delete_all.Bind(wx.EVT_BUTTON, self.OnDeleteAllMarkers) |
| 597 | 595 | |
| 598 | 596 | sizer_delete = wx.FlexGridSizer(rows=1, cols=2, hgap=5, vgap=5) |
| ... | ... | @@ -612,6 +610,8 @@ class MarkersPanel(wx.Panel): |
| 612 | 610 | self.lc.SetColumnWidth(3, 50) |
| 613 | 611 | self.lc.SetColumnWidth(4, 50) |
| 614 | 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 | 616 | # Add all lines into main sizer |
| 617 | 617 | group_sizer = wx.BoxSizer(wx.VERTICAL) |
| ... | ... | @@ -639,6 +639,12 @@ class MarkersPanel(wx.Panel): |
| 639 | 639 | self.PopupMenu(menu_id) |
| 640 | 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 | 648 | def OnMenuEditMarkerId(self, evt): |
| 643 | 649 | id_label = dlg.EnterMarkerID(self.lc.GetItemText(self.lc.GetFocusedItem(), 4)) |
| 644 | 650 | list_index = self.lc.GetFocusedItem() |
| ... | ... | @@ -653,6 +659,7 @@ class MarkersPanel(wx.Panel): |
| 653 | 659 | self.marker_ind = 0 |
| 654 | 660 | Publisher.sendMessage('Remove all markers', self.lc.GetItemCount()) |
| 655 | 661 | self.lc.DeleteAllItems() |
| 662 | + Publisher.sendMessage('Stop Blink Marker', 'DeleteAll') | |
| 656 | 663 | |
| 657 | 664 | def OnDeleteSingleMarker(self, evt): |
| 658 | 665 | # OnDeleteSingleMarker is used for both pubsub and button click events |
| ... | ... | @@ -667,22 +674,23 @@ class MarkersPanel(wx.Panel): |
| 667 | 674 | for i in const.BTNS_IMG_MKS: |
| 668 | 675 | if marker_id in const.BTNS_IMG_MKS[i].values()[0]: |
| 669 | 676 | self.lc.Focus(item.GetId()) |
| 670 | - self.DeleteMarker() | |
| 677 | + index = [self.lc.GetFocusedItem()] | |
| 671 | 678 | else: |
| 672 | 679 | if self.lc.GetFocusedItem() is not -1: |
| 673 | - self.DeleteMarker() | |
| 680 | + index = self.GetSelectedItems() | |
| 674 | 681 | elif not self.lc.GetItemCount(): |
| 675 | 682 | pass |
| 676 | 683 | else: |
| 677 | 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 | 694 | Publisher.sendMessage('Remove marker', index) |
| 687 | 695 | |
| 688 | 696 | def OnCreateMarker(self, evt): |
| ... | ... | @@ -777,3 +785,15 @@ class MarkersPanel(wx.Panel): |
| 777 | 785 | self.lc.SetStringItem(num_items, 3, str(round(coord[2], 2))) |
| 778 | 786 | self.lc.SetStringItem(num_items, 4, str(marker_id)) |
| 779 | 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 | 800 | \ No newline at end of file | ... | ... |