Commit 102faa25184697409ffd6980f1d53090b18ef2fe

Authored by Paulo Henrique Junqueira Amorim
1 parent 0da93f69

ADD: Restructuring of the ways to bring the tools

invesalius/constants.py
... ... @@ -328,10 +328,14 @@ SLICE_STATE_WL = 2
328 328 SLICE_STATE_SPIN = 3
329 329 SLICE_STATE_ZOOM = 4
330 330 SLICE_STATE_ZOOM_SL = 5
  331 +SLICE_STATE_CROSS = 6
  332 +SLICE_STATE_SCROLL = 7
331 333  
332 334 LEVEL = {SLICE_STATE_DEFAULT: 0,
333 335 SLICE_STATE_EDITOR: 1,
334 336 SLICE_STATE_WL: 2,
335 337 SLICE_STATE_SPIN: 2,
336 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 33 import cursor_actors as ca
34 34 import data.slice_ as sl
35 35 import data.vtk_utils as vtku
  36 +import mode as md
36 37 import project
37 38 from slice_data import SliceData
38 39  
... ... @@ -74,7 +75,8 @@ class Viewer(wx.Panel):
74 75  
75 76 self.__bind_events()
76 77 self.__bind_events_wx()
77   -
  78 +
  79 + md.SliceMode()
78 80  
79 81 def __init_gui(self):
80 82  
... ... @@ -227,12 +229,17 @@ class Viewer(wx.Panel):
227 229 self.append_mode('EDITOR')
228 230 self.mouse_pressed = 0
229 231 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK))
230   -
  232 + #------------------------------------------
  233 + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_EDITOR)
  234 +
231 235 def __set_mode_spin(self, pubsub_evt):
232 236 self.append_mode('SPIN')
233 237 self.mouse_pressed = 0
234 238 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
235   -
  239 + #------------------------------------------
  240 + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_SPIN)
  241 +
  242 +
236 243 def __set_mode_zoom(self, pubsub_evt):
237 244 #print "Zoom"
238 245 self.append_mode('ZOOM')
... ... @@ -240,33 +247,46 @@ class Viewer(wx.Panel):
240 247 ICON_IMAGE = wx.Image(os.path.join(const.ICON_DIR,
241 248 "tool_zoom.png"),wx.BITMAP_TYPE_PNG)
242 249 self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE))
243   -
  250 + #------------------------------------------
  251 + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_ZOOM)
  252 +
244 253 def __set_mode_pan(self, pubsub_evt):
245 254 self.append_mode('PAN')
246 255 self.mouse_pressed = 0
247 256 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
248   -
  257 + #------------------------------------------
  258 + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_PAN)
  259 +
249 260 def __set_mode_zoom_select(self, pubsub_evt):
250 261 self.append_mode('ZOOMSELECT')
251 262 ICON_IMAGE = wx.Image(os.path.join(const.ICON_DIR,
252 263 "tool_zoom.png"),wx.BITMAP_TYPE_PNG)
253 264 self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE))
254   -
  265 + #------------------------------------------
  266 + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_SL)
  267 +
255 268 def __set_mode_window_level(self, pubsub_evt):
256 269 self.append_mode('WINDOWLEVEL')
257 270 self.mouse_pressed = 0
258 271 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
259 272 self.interactor.Render()
  273 + #------------------------------------------
  274 + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_WL)
  275 +
260 276  
261 277 def __set_mode_slice_scroll(self, pubsub_evt):
262 278 self.append_mode('CHANGESLICE')
263 279 self.mouse_pressed = 0
264 280 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS))
  281 + #------------------------------------------
  282 + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_SCROLL)
265 283  
266 284 def __set_mode_cross(self, pubsub_evt):
267 285 self.append_mode('CROSS')
268 286 self.mouse_pressed = 0
269 287 self.cross_actor.VisibilityOn()
  288 + #------------------------------------------
  289 + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_CROSS)
270 290  
271 291 def OnWindowLevelMove(self, evt, obj):
272 292 if self.mouse_pressed:
... ...
invesalius/mode.py
... ... @@ -17,19 +17,14 @@
17 17 # detalhes.
18 18 #--------------------------------------------------------------------------
19 19  
  20 +import wx.lib.pubsub as ps
  21 +
  22 +
20 23 # mode.py
21 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 28 # IMPORTANT: When adding a new state, remember o insert it into LEVEL
34 29 # dictionary
35 30  
... ... @@ -38,19 +33,19 @@ SLICE_STATE_ZOOM_SL = 5
38 33 # default is the only level 0
39 34 # states controlled somehow by taskmenu are level 1
40 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 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 49 # according to mode, set cursor, interaction, etc
55 50 #----------------------
56 51 # TODO: Add GUI classes (frame, tasks related to slice, toolbar):
... ... @@ -59,11 +54,11 @@ def OnSetMode(self, pubsub_evt):
59 54 # viewer_slice directly
60 55  
61 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 78 const.SLICE_STATE_DEFAULT
84 79  
85 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 84 ps.Publisher().subscribe(self.OnEnableState, 'Enable mode')
90 85 ps.Publisher().subscribe(self.OnDisableState, 'Disable mode')
91 86  
... ...