Commit 81a37add57380ca9d13ec258014d434ff3a11c06
1 parent
088d7b8b
Exists in
master
and in
68 other branches
ENH: Restructuring state of the tools
Showing
2 changed files
with
44 additions
and
65 deletions
Show diff stats
invesalius/data/viewer_slice.py
| @@ -149,97 +149,77 @@ class Viewer(wx.Panel): | @@ -149,97 +149,77 @@ class Viewer(wx.Panel): | ||
| 149 | if "ZOOM" in self.modes or "ZOOMSELECT" in self.modes: | 149 | if "ZOOM" in self.modes or "ZOOMSELECT" in self.modes: |
| 150 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) | 150 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) |
| 151 | 151 | ||
| 152 | - #TODO: Temporary | ||
| 153 | - self.modes = [] | ||
| 154 | - | ||
| 155 | - # Retrieve currently set modes | ||
| 156 | - self.modes.append(mode) | ||
| 157 | - | ||
| 158 | - # All modes and bindings | ||
| 159 | - action = {'CROSS': { | 152 | + action = {const.SLICE_STATE_CROSS: { |
| 160 | "MouseMoveEvent": self.OnCrossMove, | 153 | "MouseMoveEvent": self.OnCrossMove, |
| 161 | "LeftButtonPressEvent": self.OnCrossMouseClick, | 154 | "LeftButtonPressEvent": self.OnCrossMouseClick, |
| 162 | "LeftButtonReleaseEvent": self.OnCrossMouseRelease | 155 | "LeftButtonReleaseEvent": self.OnCrossMouseRelease |
| 163 | }, | 156 | }, |
| 164 | - 'EDITOR': { | 157 | + const.SLICE_STATE_EDITOR: { |
| 165 | "MouseMoveEvent": self.OnBrushMove, | 158 | "MouseMoveEvent": self.OnBrushMove, |
| 166 | "LeftButtonPressEvent": self.OnBrushClick, | 159 | "LeftButtonPressEvent": self.OnBrushClick, |
| 167 | "LeftButtonReleaseEvent": self.OnMouseRelease, | 160 | "LeftButtonReleaseEvent": self.OnMouseRelease, |
| 168 | "EnterEvent": self.OnEnterInteractor, | 161 | "EnterEvent": self.OnEnterInteractor, |
| 169 | "LeaveEvent": self.OnLeaveInteractor | 162 | "LeaveEvent": self.OnLeaveInteractor |
| 170 | }, | 163 | }, |
| 171 | - 'PAN':{ | 164 | + const.STATE_PAN:{ |
| 172 | "MouseMoveEvent": self.OnPanMove, | 165 | "MouseMoveEvent": self.OnPanMove, |
| 173 | "LeftButtonPressEvent": self.OnPanClick, | 166 | "LeftButtonPressEvent": self.OnPanClick, |
| 174 | "LeftButtonReleaseEvent": self.OnReleaseModes | 167 | "LeftButtonReleaseEvent": self.OnReleaseModes |
| 175 | }, | 168 | }, |
| 176 | - 'SPIN':{ | 169 | + const.STATE_SPIN:{ |
| 177 | "MouseMoveEvent": self.OnSpinMove, | 170 | "MouseMoveEvent": self.OnSpinMove, |
| 178 | "LeftButtonPressEvent": self.OnSpinClick, | 171 | "LeftButtonPressEvent": self.OnSpinClick, |
| 179 | "LeftButtonReleaseEvent": self.OnReleaseModes | 172 | "LeftButtonReleaseEvent": self.OnReleaseModes |
| 180 | }, | 173 | }, |
| 181 | - 'ZOOM':{ | 174 | + const.STATE_ZOOM:{ |
| 182 | "MouseMoveEvent": self.OnZoomMove, | 175 | "MouseMoveEvent": self.OnZoomMove, |
| 183 | "LeftButtonPressEvent": self.OnZoomClick, | 176 | "LeftButtonPressEvent": self.OnZoomClick, |
| 184 | "LeftButtonReleaseEvent": self.OnReleaseModes, | 177 | "LeftButtonReleaseEvent": self.OnReleaseModes, |
| 185 | }, | 178 | }, |
| 186 | - 'CHANGESLICE':{ | 179 | + const.SLICE_STATE_SCROLL:{ |
| 187 | "MouseMoveEvent": self.OnChangeSliceMove, | 180 | "MouseMoveEvent": self.OnChangeSliceMove, |
| 188 | "LeftButtonPressEvent": self.OnChangeSliceClick, | 181 | "LeftButtonPressEvent": self.OnChangeSliceClick, |
| 189 | "LeftButtonReleaseEvent": self.OnReleaseModes | 182 | "LeftButtonReleaseEvent": self.OnReleaseModes |
| 190 | }, | 183 | }, |
| 191 | - 'WINDOWLEVEL':{ | 184 | + const.STATE_WL:{ |
| 192 | "MouseMoveEvent": self.OnWindowLevelMove, | 185 | "MouseMoveEvent": self.OnWindowLevelMove, |
| 193 | "LeftButtonPressEvent": self.OnWindowLevelClick, | 186 | "LeftButtonPressEvent": self.OnWindowLevelClick, |
| 194 | "LeftButtonReleaseEvent": self.OnReleaseModes | 187 | "LeftButtonReleaseEvent": self.OnReleaseModes |
| 195 | } | 188 | } |
| 196 | } | 189 | } |
| 197 | - | 190 | + |
| 198 | # Bind method according to current mode | 191 | # Bind method according to current mode |
| 199 | - if(mode == 'ZOOMSELECT'): | 192 | + if(mode == const.STATE_ZOOM_SL): |
| 200 | style = vtk.vtkInteractorStyleRubberBandZoom() | 193 | style = vtk.vtkInteractorStyleRubberBandZoom() |
| 201 | else: | 194 | else: |
| 202 | style = vtk.vtkInteractorStyleImage() | 195 | style = vtk.vtkInteractorStyleImage() |
| 203 | 196 | ||
| 204 | - # Check all modes set by user | ||
| 205 | - for mode in self.modes: | ||
| 206 | - # Check each event available for each mode | ||
| 207 | - for event in action[mode]: | ||
| 208 | - # Bind event | ||
| 209 | - style.AddObserver(event, | ||
| 210 | - action[mode][event]) | ||
| 211 | - | ||
| 212 | - if ((mode == "ZOOM") or (mode == "ZOOMSELECT")): | 197 | + # Check each event available for each mode |
| 198 | + for event in action[mode]: | ||
| 199 | + # Bind event | ||
| 200 | + style.AddObserver(event, | ||
| 201 | + action[mode][event]) | ||
| 202 | + | ||
| 203 | + if ((mode == const.STATE_ZOOM) or (mode == const.STATE_ZOOM_SL)): | ||
| 213 | self.interactor.Bind(wx.EVT_LEFT_DCLICK, self.OnUnZoom) | 204 | self.interactor.Bind(wx.EVT_LEFT_DCLICK, self.OnUnZoom) |
| 214 | else: | 205 | else: |
| 215 | self.interactor.Bind(wx.EVT_LEFT_DCLICK, None) | 206 | self.interactor.Bind(wx.EVT_LEFT_DCLICK, None) |
| 216 | - | ||
| 217 | - #try: | ||
| 218 | - # if mode == "CROSS": | ||
| 219 | - # self.cross_actor.VisibilityOn() | ||
| 220 | - # else: | ||
| 221 | - # self.cross_actor.VisibilityOff() | ||
| 222 | - #except AttributeError: | ||
| 223 | - # pass | ||
| 224 | 207 | ||
| 225 | self.style = style | 208 | self.style = style |
| 226 | self.interactor.SetInteractorStyle(style) | 209 | self.interactor.SetInteractorStyle(style) |
| 210 | + | ||
| 211 | + | ||
| 227 | 212 | ||
| 228 | def __set_mode_editor(self, pubsub_evt): | 213 | def __set_mode_editor(self, pubsub_evt): |
| 229 | - self.append_mode('EDITOR') | 214 | + self.append_mode(const.SLICE_STATE_EDITOR) |
| 230 | self.mouse_pressed = 0 | 215 | self.mouse_pressed = 0 |
| 231 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK)) | 216 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK)) |
| 232 | - #------------------------------------------ | ||
| 233 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_EDITOR) | ||
| 234 | 217 | ||
| 235 | def __set_mode_spin(self, pubsub_evt): | 218 | def __set_mode_spin(self, pubsub_evt): |
| 236 | self.append_mode('SPIN') | 219 | self.append_mode('SPIN') |
| 237 | self.mouse_pressed = 0 | 220 | self.mouse_pressed = 0 |
| 238 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) | 221 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) |
| 239 | - #------------------------------------------ | ||
| 240 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_SPIN) | ||
| 241 | - | ||
| 242 | - | 222 | + |
| 243 | def __set_mode_zoom(self, pubsub_evt): | 223 | def __set_mode_zoom(self, pubsub_evt): |
| 244 | #print "Zoom" | 224 | #print "Zoom" |
| 245 | self.append_mode('ZOOM') | 225 | self.append_mode('ZOOM') |
| @@ -247,46 +227,34 @@ class Viewer(wx.Panel): | @@ -247,46 +227,34 @@ class Viewer(wx.Panel): | ||
| 247 | ICON_IMAGE = wx.Image(os.path.join(const.ICON_DIR, | 227 | ICON_IMAGE = wx.Image(os.path.join(const.ICON_DIR, |
| 248 | "tool_zoom.png"),wx.BITMAP_TYPE_PNG) | 228 | "tool_zoom.png"),wx.BITMAP_TYPE_PNG) |
| 249 | self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) | 229 | self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) |
| 250 | - #------------------------------------------ | ||
| 251 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_ZOOM) | ||
| 252 | 230 | ||
| 253 | def __set_mode_pan(self, pubsub_evt): | 231 | def __set_mode_pan(self, pubsub_evt): |
| 254 | self.append_mode('PAN') | 232 | self.append_mode('PAN') |
| 255 | self.mouse_pressed = 0 | 233 | self.mouse_pressed = 0 |
| 256 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) | 234 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) |
| 257 | - #------------------------------------------ | ||
| 258 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_PAN) | ||
| 259 | 235 | ||
| 260 | def __set_mode_zoom_select(self, pubsub_evt): | 236 | def __set_mode_zoom_select(self, pubsub_evt): |
| 261 | self.append_mode('ZOOMSELECT') | 237 | self.append_mode('ZOOMSELECT') |
| 262 | ICON_IMAGE = wx.Image(os.path.join(const.ICON_DIR, | 238 | ICON_IMAGE = wx.Image(os.path.join(const.ICON_DIR, |
| 263 | "tool_zoom.png"),wx.BITMAP_TYPE_PNG) | 239 | "tool_zoom.png"),wx.BITMAP_TYPE_PNG) |
| 264 | self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) | 240 | self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) |
| 265 | - #------------------------------------------ | ||
| 266 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_SL) | ||
| 267 | 241 | ||
| 268 | def __set_mode_window_level(self, pubsub_evt): | 242 | def __set_mode_window_level(self, pubsub_evt): |
| 269 | self.append_mode('WINDOWLEVEL') | 243 | self.append_mode('WINDOWLEVEL') |
| 270 | self.mouse_pressed = 0 | 244 | self.mouse_pressed = 0 |
| 271 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) | 245 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) |
| 272 | self.interactor.Render() | 246 | self.interactor.Render() |
| 273 | - #------------------------------------------ | ||
| 274 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_WL) | ||
| 275 | 247 | ||
| 276 | 248 | ||
| 277 | def __set_mode_slice_scroll(self, pubsub_evt): | 249 | def __set_mode_slice_scroll(self, pubsub_evt): |
| 278 | self.append_mode('CHANGESLICE') | 250 | self.append_mode('CHANGESLICE') |
| 279 | self.mouse_pressed = 0 | 251 | self.mouse_pressed = 0 |
| 280 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) | 252 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) |
| 281 | - #------------------------------------------ | ||
| 282 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_SCROLL) | ||
| 283 | 253 | ||
| 284 | def __set_mode_cross(self, pubsub_evt): | 254 | def __set_mode_cross(self, pubsub_evt): |
| 285 | self.append_mode('CROSS') | 255 | self.append_mode('CROSS') |
| 286 | self.mouse_pressed = 0 | 256 | self.mouse_pressed = 0 |
| 287 | self.cross_actor.VisibilityOn() | 257 | self.cross_actor.VisibilityOn() |
| 288 | - #------------------------------------------ | ||
| 289 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_CROSS) | ||
| 290 | 258 | ||
| 291 | def OnWindowLevelMove(self, evt, obj): | 259 | def OnWindowLevelMove(self, evt, obj): |
| 292 | if self.mouse_pressed: | 260 | if self.mouse_pressed: |
| @@ -785,6 +753,7 @@ class Viewer(wx.Panel): | @@ -785,6 +753,7 @@ class Viewer(wx.Panel): | ||
| 785 | 'Set edition operation') | 753 | 'Set edition operation') |
| 786 | 754 | ||
| 787 | ### | 755 | ### |
| 756 | + """ | ||
| 788 | ps.Publisher().subscribe(self.__set_mode_pan, | 757 | ps.Publisher().subscribe(self.__set_mode_pan, |
| 789 | ('Set interaction mode', | 758 | ('Set interaction mode', |
| 790 | const.MODE_MOVE)) | 759 | const.MODE_MOVE)) |
| @@ -809,17 +778,26 @@ class Viewer(wx.Panel): | @@ -809,17 +778,26 @@ class Viewer(wx.Panel): | ||
| 809 | ps.Publisher().subscribe(self.__set_mode_cross, | 778 | ps.Publisher().subscribe(self.__set_mode_cross, |
| 810 | ('Set interaction mode', | 779 | ('Set interaction mode', |
| 811 | const.MODE_SLICE_CROSS)) | 780 | const.MODE_SLICE_CROSS)) |
| 812 | - | 781 | + """ |
| 782 | + | ||
| 813 | ps.Publisher().subscribe(self.UpdateWindowLevelValue,\ | 783 | ps.Publisher().subscribe(self.UpdateWindowLevelValue,\ |
| 814 | 'Update window level value') | 784 | 'Update window level value') |
| 815 | 785 | ||
| 816 | ps.Publisher().subscribe(self.__set_cross_visibility,\ | 786 | ps.Publisher().subscribe(self.__set_cross_visibility,\ |
| 817 | 'Set cross visibility') | 787 | 'Set cross visibility') |
| 818 | - | ||
| 819 | ### | 788 | ### |
| 820 | ps.Publisher().subscribe(self.__set_layout, | 789 | ps.Publisher().subscribe(self.__set_layout, |
| 821 | 'Set slice viewer layout') | 790 | 'Set slice viewer layout') |
| 822 | 791 | ||
| 792 | + ps.Publisher().subscribe(self.OnSetMode, | ||
| 793 | + 'Set slice mode') | ||
| 794 | + | ||
| 795 | + def OnSetMode(self, pubsub_evt): | ||
| 796 | + mode = pubsub_evt.data | ||
| 797 | + self.mouse_pressed = 0 | ||
| 798 | + self.append_mode(mode) | ||
| 799 | + | ||
| 800 | + | ||
| 823 | def ChangeBrushOperation(self, pubsub_evt): | 801 | def ChangeBrushOperation(self, pubsub_evt): |
| 824 | #print pubsub_evt.data | 802 | #print pubsub_evt.data |
| 825 | self._brush_cursor_op = pubsub_evt.data | 803 | self._brush_cursor_op = pubsub_evt.data |
| @@ -925,7 +903,7 @@ class Viewer(wx.Panel): | @@ -925,7 +903,7 @@ class Viewer(wx.Panel): | ||
| 925 | 903 | ||
| 926 | self.EnableText() | 904 | self.EnableText() |
| 927 | # Insert cursor | 905 | # Insert cursor |
| 928 | - self.append_mode('EDITOR') | 906 | + self.append_mode(const.SLICE_STATE_EDITOR) |
| 929 | 907 | ||
| 930 | self.__build_cross_lines() | 908 | self.__build_cross_lines() |
| 931 | 909 |
invesalius/gui/frame.py
| @@ -36,11 +36,11 @@ import session as ses | @@ -36,11 +36,11 @@ import session as ses | ||
| 36 | # Object toolbar | 36 | # Object toolbar |
| 37 | OBJ_TOOLS = [ID_ZOOM, ID_ZOOM_SELECT, ID_ROTATE, ID_MOVE, | 37 | OBJ_TOOLS = [ID_ZOOM, ID_ZOOM_SELECT, ID_ROTATE, ID_MOVE, |
| 38 | ID_CONTRAST] = [wx.NewId() for number in range(5)] | 38 | ID_CONTRAST] = [wx.NewId() for number in range(5)] |
| 39 | -MODE_BY_ID = {ID_ZOOM: const.MODE_ZOOM, | ||
| 40 | - ID_ZOOM_SELECT: const.MODE_ZOOM_SELECTION, | ||
| 41 | - ID_ROTATE: const.MODE_ROTATE, | ||
| 42 | - ID_MOVE: const.MODE_MOVE, | ||
| 43 | - ID_CONTRAST: const.MODE_WW_WL} | 39 | +MODE_BY_ID = {ID_ZOOM: const.STATE_ZOOM, |
| 40 | + ID_ZOOM_SELECT: const.STATE_ZOOM_SL, | ||
| 41 | + ID_ROTATE: const.STATE_SPIN, | ||
| 42 | + ID_MOVE: const.STATE_PAN, | ||
| 43 | + ID_CONTRAST: const.STATE_WL} | ||
| 44 | 44 | ||
| 45 | # Slice toolbar | 45 | # Slice toolbar |
| 46 | SLICE_TOOLS = [ID_SLICE_SCROLL, ID_CROSS] = [wx.NewId() for number in range(2)] | 46 | SLICE_TOOLS = [ID_SLICE_SCROLL, ID_CROSS] = [wx.NewId() for number in range(2)] |
| @@ -672,12 +672,13 @@ class ObjectToolBar(wx.ToolBar): | @@ -672,12 +672,13 @@ class ObjectToolBar(wx.ToolBar): | ||
| 672 | state = self.GetToolState(id) | 672 | state = self.GetToolState(id) |
| 673 | 673 | ||
| 674 | if state: | 674 | if state: |
| 675 | - ps.Publisher().sendMessage(('Set interaction mode', | ||
| 676 | - MODE_BY_ID[id])) | ||
| 677 | - ps.Publisher().sendMessage('Untoggle slice toolbar items') | 675 | + ps.Publisher().sendMessage('Set slice mode', |
| 676 | + MODE_BY_ID[id]) | ||
| 677 | + | ||
| 678 | + #ps.Publisher().sendMessage('Untoggle slice toolbar items') | ||
| 678 | else: | 679 | else: |
| 679 | - ps.Publisher().sendMessage(('Set interaction mode', | ||
| 680 | - const.MODE_SLICE_EDITOR)) | 680 | + ps.Publisher().sendMessage('Set interaction mode', |
| 681 | + const.MODE_SLICE_EDITOR) | ||
| 681 | 682 | ||
| 682 | 683 | ||
| 683 | 684 |