Commit 102faa25184697409ffd6980f1d53090b18ef2fe
1 parent
0da93f69
Exists in
master
and in
68 other branches
ADD: Restructuring of the ways to bring the tools
Showing
3 changed files
with
51 additions
and
32 deletions
Show diff stats
invesalius/constants.py
| @@ -328,10 +328,14 @@ SLICE_STATE_WL = 2 | @@ -328,10 +328,14 @@ SLICE_STATE_WL = 2 | ||
| 328 | SLICE_STATE_SPIN = 3 | 328 | SLICE_STATE_SPIN = 3 |
| 329 | SLICE_STATE_ZOOM = 4 | 329 | SLICE_STATE_ZOOM = 4 |
| 330 | SLICE_STATE_ZOOM_SL = 5 | 330 | SLICE_STATE_ZOOM_SL = 5 |
| 331 | +SLICE_STATE_CROSS = 6 | ||
| 332 | +SLICE_STATE_SCROLL = 7 | ||
| 331 | 333 | ||
| 332 | LEVEL = {SLICE_STATE_DEFAULT: 0, | 334 | LEVEL = {SLICE_STATE_DEFAULT: 0, |
| 333 | SLICE_STATE_EDITOR: 1, | 335 | SLICE_STATE_EDITOR: 1, |
| 334 | SLICE_STATE_WL: 2, | 336 | SLICE_STATE_WL: 2, |
| 335 | SLICE_STATE_SPIN: 2, | 337 | SLICE_STATE_SPIN: 2, |
| 336 | SLICE_STATE_ZOOM: 2, | 338 | SLICE_STATE_ZOOM: 2, |
| 337 | - SLICE_STATE_ZOOM_SL: 2} | 339 | + SLICE_STATE_ZOOM_SL: 2, |
| 340 | + SLICE_STATE_CROSS: 2, | ||
| 341 | + SLICE_STATE_SCROLL: 2} |
invesalius/data/viewer_slice.py
| @@ -33,6 +33,7 @@ import constants as const | @@ -33,6 +33,7 @@ import constants as const | ||
| 33 | import cursor_actors as ca | 33 | import cursor_actors as ca |
| 34 | import data.slice_ as sl | 34 | import data.slice_ as sl |
| 35 | import data.vtk_utils as vtku | 35 | import data.vtk_utils as vtku |
| 36 | +import mode as md | ||
| 36 | import project | 37 | import project |
| 37 | from slice_data import SliceData | 38 | from slice_data import SliceData |
| 38 | 39 | ||
| @@ -74,7 +75,8 @@ class Viewer(wx.Panel): | @@ -74,7 +75,8 @@ class Viewer(wx.Panel): | ||
| 74 | 75 | ||
| 75 | self.__bind_events() | 76 | self.__bind_events() |
| 76 | self.__bind_events_wx() | 77 | self.__bind_events_wx() |
| 77 | - | 78 | + |
| 79 | + md.SliceMode() | ||
| 78 | 80 | ||
| 79 | def __init_gui(self): | 81 | def __init_gui(self): |
| 80 | 82 | ||
| @@ -227,12 +229,17 @@ class Viewer(wx.Panel): | @@ -227,12 +229,17 @@ class Viewer(wx.Panel): | ||
| 227 | self.append_mode('EDITOR') | 229 | self.append_mode('EDITOR') |
| 228 | self.mouse_pressed = 0 | 230 | self.mouse_pressed = 0 |
| 229 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK)) | 231 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK)) |
| 230 | - | 232 | + #------------------------------------------ |
| 233 | + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_EDITOR) | ||
| 234 | + | ||
| 231 | def __set_mode_spin(self, pubsub_evt): | 235 | def __set_mode_spin(self, pubsub_evt): |
| 232 | self.append_mode('SPIN') | 236 | self.append_mode('SPIN') |
| 233 | self.mouse_pressed = 0 | 237 | self.mouse_pressed = 0 |
| 234 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) | 238 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) |
| 235 | - | 239 | + #------------------------------------------ |
| 240 | + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_SPIN) | ||
| 241 | + | ||
| 242 | + | ||
| 236 | def __set_mode_zoom(self, pubsub_evt): | 243 | def __set_mode_zoom(self, pubsub_evt): |
| 237 | #print "Zoom" | 244 | #print "Zoom" |
| 238 | self.append_mode('ZOOM') | 245 | self.append_mode('ZOOM') |
| @@ -240,33 +247,46 @@ class Viewer(wx.Panel): | @@ -240,33 +247,46 @@ class Viewer(wx.Panel): | ||
| 240 | ICON_IMAGE = wx.Image(os.path.join(const.ICON_DIR, | 247 | ICON_IMAGE = wx.Image(os.path.join(const.ICON_DIR, |
| 241 | "tool_zoom.png"),wx.BITMAP_TYPE_PNG) | 248 | "tool_zoom.png"),wx.BITMAP_TYPE_PNG) |
| 242 | self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) | 249 | self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) |
| 243 | - | 250 | + #------------------------------------------ |
| 251 | + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_ZOOM) | ||
| 252 | + | ||
| 244 | def __set_mode_pan(self, pubsub_evt): | 253 | def __set_mode_pan(self, pubsub_evt): |
| 245 | self.append_mode('PAN') | 254 | self.append_mode('PAN') |
| 246 | self.mouse_pressed = 0 | 255 | self.mouse_pressed = 0 |
| 247 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) | 256 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) |
| 248 | - | 257 | + #------------------------------------------ |
| 258 | + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_PAN) | ||
| 259 | + | ||
| 249 | def __set_mode_zoom_select(self, pubsub_evt): | 260 | def __set_mode_zoom_select(self, pubsub_evt): |
| 250 | self.append_mode('ZOOMSELECT') | 261 | self.append_mode('ZOOMSELECT') |
| 251 | ICON_IMAGE = wx.Image(os.path.join(const.ICON_DIR, | 262 | ICON_IMAGE = wx.Image(os.path.join(const.ICON_DIR, |
| 252 | "tool_zoom.png"),wx.BITMAP_TYPE_PNG) | 263 | "tool_zoom.png"),wx.BITMAP_TYPE_PNG) |
| 253 | self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) | 264 | self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) |
| 254 | - | 265 | + #------------------------------------------ |
| 266 | + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_SL) | ||
| 267 | + | ||
| 255 | def __set_mode_window_level(self, pubsub_evt): | 268 | def __set_mode_window_level(self, pubsub_evt): |
| 256 | self.append_mode('WINDOWLEVEL') | 269 | self.append_mode('WINDOWLEVEL') |
| 257 | self.mouse_pressed = 0 | 270 | self.mouse_pressed = 0 |
| 258 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) | 271 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) |
| 259 | self.interactor.Render() | 272 | self.interactor.Render() |
| 273 | + #------------------------------------------ | ||
| 274 | + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_WL) | ||
| 275 | + | ||
| 260 | 276 | ||
| 261 | def __set_mode_slice_scroll(self, pubsub_evt): | 277 | def __set_mode_slice_scroll(self, pubsub_evt): |
| 262 | self.append_mode('CHANGESLICE') | 278 | self.append_mode('CHANGESLICE') |
| 263 | self.mouse_pressed = 0 | 279 | self.mouse_pressed = 0 |
| 264 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) | 280 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) |
| 281 | + #------------------------------------------ | ||
| 282 | + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_SCROLL) | ||
| 265 | 283 | ||
| 266 | def __set_mode_cross(self, pubsub_evt): | 284 | def __set_mode_cross(self, pubsub_evt): |
| 267 | self.append_mode('CROSS') | 285 | self.append_mode('CROSS') |
| 268 | self.mouse_pressed = 0 | 286 | self.mouse_pressed = 0 |
| 269 | self.cross_actor.VisibilityOn() | 287 | self.cross_actor.VisibilityOn() |
| 288 | + #------------------------------------------ | ||
| 289 | + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_CROSS) | ||
| 270 | 290 | ||
| 271 | def OnWindowLevelMove(self, evt, obj): | 291 | def OnWindowLevelMove(self, evt, obj): |
| 272 | if self.mouse_pressed: | 292 | if self.mouse_pressed: |
invesalius/mode.py
| @@ -17,19 +17,14 @@ | @@ -17,19 +17,14 @@ | ||
| 17 | # detalhes. | 17 | # detalhes. |
| 18 | #-------------------------------------------------------------------------- | 18 | #-------------------------------------------------------------------------- |
| 19 | 19 | ||
| 20 | +import wx.lib.pubsub as ps | ||
| 21 | + | ||
| 22 | + | ||
| 20 | # mode.py | 23 | # mode.py |
| 21 | # to be instanced inside Controller (control.py) | 24 | # to be instanced inside Controller (control.py) |
| 22 | 25 | ||
| 23 | 26 | ||
| 24 | -# TODO: Add to constants.py: | ||
| 25 | -#-------------------- | ||
| 26 | -# SLICE MODE | ||
| 27 | -SLICE_STATE_DEFAULT = 0 | ||
| 28 | -SLICE_STATE_EDITOR = 1 | ||
| 29 | -SLICE_STATE_WL = 2 | ||
| 30 | -SLICE_STATE_SPIN = 3 | ||
| 31 | -SLICE_STATE_ZOOM = 4 | ||
| 32 | -SLICE_STATE_ZOOM_SL = 5 | 27 | + |
| 33 | # IMPORTANT: When adding a new state, remember o insert it into LEVEL | 28 | # IMPORTANT: When adding a new state, remember o insert it into LEVEL |
| 34 | # dictionary | 29 | # dictionary |
| 35 | 30 | ||
| @@ -38,19 +33,19 @@ SLICE_STATE_ZOOM_SL = 5 | @@ -38,19 +33,19 @@ SLICE_STATE_ZOOM_SL = 5 | ||
| 38 | # default is the only level 0 | 33 | # default is the only level 0 |
| 39 | # states controlled somehow by taskmenu are level 1 | 34 | # states controlled somehow by taskmenu are level 1 |
| 40 | # states controlled by toolbar are level 2 | 35 | # states controlled by toolbar are level 2 |
| 41 | -LEVEL = {SLICE_STATE_DEFAULT: 0, | ||
| 42 | - SLICE_STATE_EDITOR: 1, | ||
| 43 | - SLICE_STATE_WL: 2, | ||
| 44 | - SLICE_STATE_SPIN: 2, | ||
| 45 | - SLICE_STATE_ZOOM: 2, | ||
| 46 | - SLICE_STATE_ZOOM_SL: 2} | 36 | +#LEVEL = {SLICE_STATE_DEFAULT: 0, |
| 37 | +# SLICE_STATE_EDITOR: 1, | ||
| 38 | +# SLICE_STATE_WL: 2, | ||
| 39 | +# SLICE_STATE_SPIN: 2, | ||
| 40 | +# SLICE_STATE_ZOOM: 2, | ||
| 41 | +# SLICE_STATE_ZOOM_SL: 2} | ||
| 47 | #---------------------- | 42 | #---------------------- |
| 48 | # TODO: Add to viewer_slice.py: | 43 | # TODO: Add to viewer_slice.py: |
| 49 | 44 | ||
| 50 | - ps.Publisher().subscribe(self.OnSetMode, 'Set slice mode') | 45 | +#ps.Publisher().subscribe(self.OnSetMode, 'Set slice mode') |
| 51 | 46 | ||
| 52 | -def OnSetMode(self, pubsub_evt): | ||
| 53 | - mode = pubsub_evt.data | 47 | +#def OnSetMode(self, pubsub_evt): |
| 48 | +# mode = pubsub_evt.data | ||
| 54 | # according to mode, set cursor, interaction, etc | 49 | # according to mode, set cursor, interaction, etc |
| 55 | #---------------------- | 50 | #---------------------- |
| 56 | # TODO: Add GUI classes (frame, tasks related to slice, toolbar): | 51 | # TODO: Add GUI classes (frame, tasks related to slice, toolbar): |
| @@ -59,11 +54,11 @@ def OnSetMode(self, pubsub_evt): | @@ -59,11 +54,11 @@ def OnSetMode(self, pubsub_evt): | ||
| 59 | # viewer_slice directly | 54 | # viewer_slice directly |
| 60 | 55 | ||
| 61 | # example - pseudo code | 56 | # example - pseudo code |
| 62 | -def OnToggleButtonSpin(self, evt) | ||
| 63 | - if evt.toggle: # doesn't exist, just to illustrate | ||
| 64 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_ZOOM) | ||
| 65 | - else: | ||
| 66 | - ps.Publisher().subscribe('Disable mode', const.SLICE_STATE_ZOOM) | 57 | +#def OnToggleButtonSpin(self, evt) |
| 58 | +# if evt.toggle: # doesn't exist, just to illustrate | ||
| 59 | +# ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_ZOOM) | ||
| 60 | +# else: | ||
| 61 | +# ps.Publisher().subscribe('Disable mode', const.SLICE_STATE_ZOOM) | ||
| 67 | 62 | ||
| 68 | 63 | ||
| 69 | #---------------------- | 64 | #---------------------- |
| @@ -83,9 +78,9 @@ class SliceMode(object): | @@ -83,9 +78,9 @@ class SliceMode(object): | ||
| 83 | const.SLICE_STATE_DEFAULT | 78 | const.SLICE_STATE_DEFAULT |
| 84 | 79 | ||
| 85 | # bind pubsub evt | 80 | # bind pubsub evt |
| 86 | - self.bind_events() | 81 | + self.__bind_events() |
| 87 | 82 | ||
| 88 | - def _bind_events(self): | 83 | + def __bind_events(self): |
| 89 | ps.Publisher().subscribe(self.OnEnableState, 'Enable mode') | 84 | ps.Publisher().subscribe(self.OnEnableState, 'Enable mode') |
| 90 | ps.Publisher().subscribe(self.OnDisableState, 'Disable mode') | 85 | ps.Publisher().subscribe(self.OnDisableState, 'Disable mode') |
| 91 | 86 |