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 | 149 | if "ZOOM" in self.modes or "ZOOMSELECT" in self.modes: |
150 | 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 | 153 | "MouseMoveEvent": self.OnCrossMove, |
161 | 154 | "LeftButtonPressEvent": self.OnCrossMouseClick, |
162 | 155 | "LeftButtonReleaseEvent": self.OnCrossMouseRelease |
163 | 156 | }, |
164 | - 'EDITOR': { | |
157 | + const.SLICE_STATE_EDITOR: { | |
165 | 158 | "MouseMoveEvent": self.OnBrushMove, |
166 | 159 | "LeftButtonPressEvent": self.OnBrushClick, |
167 | 160 | "LeftButtonReleaseEvent": self.OnMouseRelease, |
168 | 161 | "EnterEvent": self.OnEnterInteractor, |
169 | 162 | "LeaveEvent": self.OnLeaveInteractor |
170 | 163 | }, |
171 | - 'PAN':{ | |
164 | + const.STATE_PAN:{ | |
172 | 165 | "MouseMoveEvent": self.OnPanMove, |
173 | 166 | "LeftButtonPressEvent": self.OnPanClick, |
174 | 167 | "LeftButtonReleaseEvent": self.OnReleaseModes |
175 | 168 | }, |
176 | - 'SPIN':{ | |
169 | + const.STATE_SPIN:{ | |
177 | 170 | "MouseMoveEvent": self.OnSpinMove, |
178 | 171 | "LeftButtonPressEvent": self.OnSpinClick, |
179 | 172 | "LeftButtonReleaseEvent": self.OnReleaseModes |
180 | 173 | }, |
181 | - 'ZOOM':{ | |
174 | + const.STATE_ZOOM:{ | |
182 | 175 | "MouseMoveEvent": self.OnZoomMove, |
183 | 176 | "LeftButtonPressEvent": self.OnZoomClick, |
184 | 177 | "LeftButtonReleaseEvent": self.OnReleaseModes, |
185 | 178 | }, |
186 | - 'CHANGESLICE':{ | |
179 | + const.SLICE_STATE_SCROLL:{ | |
187 | 180 | "MouseMoveEvent": self.OnChangeSliceMove, |
188 | 181 | "LeftButtonPressEvent": self.OnChangeSliceClick, |
189 | 182 | "LeftButtonReleaseEvent": self.OnReleaseModes |
190 | 183 | }, |
191 | - 'WINDOWLEVEL':{ | |
184 | + const.STATE_WL:{ | |
192 | 185 | "MouseMoveEvent": self.OnWindowLevelMove, |
193 | 186 | "LeftButtonPressEvent": self.OnWindowLevelClick, |
194 | 187 | "LeftButtonReleaseEvent": self.OnReleaseModes |
195 | 188 | } |
196 | 189 | } |
197 | - | |
190 | + | |
198 | 191 | # Bind method according to current mode |
199 | - if(mode == 'ZOOMSELECT'): | |
192 | + if(mode == const.STATE_ZOOM_SL): | |
200 | 193 | style = vtk.vtkInteractorStyleRubberBandZoom() |
201 | 194 | else: |
202 | 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 | 204 | self.interactor.Bind(wx.EVT_LEFT_DCLICK, self.OnUnZoom) |
214 | 205 | else: |
215 | 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 | 208 | self.style = style |
226 | 209 | self.interactor.SetInteractorStyle(style) |
210 | + | |
211 | + | |
227 | 212 | |
228 | 213 | def __set_mode_editor(self, pubsub_evt): |
229 | - self.append_mode('EDITOR') | |
214 | + self.append_mode(const.SLICE_STATE_EDITOR) | |
230 | 215 | self.mouse_pressed = 0 |
231 | 216 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK)) |
232 | - #------------------------------------------ | |
233 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_EDITOR) | |
234 | 217 | |
235 | 218 | def __set_mode_spin(self, pubsub_evt): |
236 | 219 | self.append_mode('SPIN') |
237 | 220 | self.mouse_pressed = 0 |
238 | 221 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) |
239 | - #------------------------------------------ | |
240 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_SPIN) | |
241 | - | |
242 | - | |
222 | + | |
243 | 223 | def __set_mode_zoom(self, pubsub_evt): |
244 | 224 | #print "Zoom" |
245 | 225 | self.append_mode('ZOOM') |
... | ... | @@ -247,46 +227,34 @@ class Viewer(wx.Panel): |
247 | 227 | ICON_IMAGE = wx.Image(os.path.join(const.ICON_DIR, |
248 | 228 | "tool_zoom.png"),wx.BITMAP_TYPE_PNG) |
249 | 229 | self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) |
250 | - #------------------------------------------ | |
251 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_ZOOM) | |
252 | 230 | |
253 | 231 | def __set_mode_pan(self, pubsub_evt): |
254 | 232 | self.append_mode('PAN') |
255 | 233 | self.mouse_pressed = 0 |
256 | 234 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) |
257 | - #------------------------------------------ | |
258 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_PAN) | |
259 | 235 | |
260 | 236 | def __set_mode_zoom_select(self, pubsub_evt): |
261 | 237 | self.append_mode('ZOOMSELECT') |
262 | 238 | ICON_IMAGE = wx.Image(os.path.join(const.ICON_DIR, |
263 | 239 | "tool_zoom.png"),wx.BITMAP_TYPE_PNG) |
264 | 240 | self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) |
265 | - #------------------------------------------ | |
266 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_SL) | |
267 | 241 | |
268 | 242 | def __set_mode_window_level(self, pubsub_evt): |
269 | 243 | self.append_mode('WINDOWLEVEL') |
270 | 244 | self.mouse_pressed = 0 |
271 | 245 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) |
272 | 246 | self.interactor.Render() |
273 | - #------------------------------------------ | |
274 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_WL) | |
275 | 247 | |
276 | 248 | |
277 | 249 | def __set_mode_slice_scroll(self, pubsub_evt): |
278 | 250 | self.append_mode('CHANGESLICE') |
279 | 251 | self.mouse_pressed = 0 |
280 | 252 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) |
281 | - #------------------------------------------ | |
282 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_SCROLL) | |
283 | 253 | |
284 | 254 | def __set_mode_cross(self, pubsub_evt): |
285 | 255 | self.append_mode('CROSS') |
286 | 256 | self.mouse_pressed = 0 |
287 | 257 | self.cross_actor.VisibilityOn() |
288 | - #------------------------------------------ | |
289 | - ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_CROSS) | |
290 | 258 | |
291 | 259 | def OnWindowLevelMove(self, evt, obj): |
292 | 260 | if self.mouse_pressed: |
... | ... | @@ -785,6 +753,7 @@ class Viewer(wx.Panel): |
785 | 753 | 'Set edition operation') |
786 | 754 | |
787 | 755 | ### |
756 | + """ | |
788 | 757 | ps.Publisher().subscribe(self.__set_mode_pan, |
789 | 758 | ('Set interaction mode', |
790 | 759 | const.MODE_MOVE)) |
... | ... | @@ -809,17 +778,26 @@ class Viewer(wx.Panel): |
809 | 778 | ps.Publisher().subscribe(self.__set_mode_cross, |
810 | 779 | ('Set interaction mode', |
811 | 780 | const.MODE_SLICE_CROSS)) |
812 | - | |
781 | + """ | |
782 | + | |
813 | 783 | ps.Publisher().subscribe(self.UpdateWindowLevelValue,\ |
814 | 784 | 'Update window level value') |
815 | 785 | |
816 | 786 | ps.Publisher().subscribe(self.__set_cross_visibility,\ |
817 | 787 | 'Set cross visibility') |
818 | - | |
819 | 788 | ### |
820 | 789 | ps.Publisher().subscribe(self.__set_layout, |
821 | 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 | 801 | def ChangeBrushOperation(self, pubsub_evt): |
824 | 802 | #print pubsub_evt.data |
825 | 803 | self._brush_cursor_op = pubsub_evt.data |
... | ... | @@ -925,7 +903,7 @@ class Viewer(wx.Panel): |
925 | 903 | |
926 | 904 | self.EnableText() |
927 | 905 | # Insert cursor |
928 | - self.append_mode('EDITOR') | |
906 | + self.append_mode(const.SLICE_STATE_EDITOR) | |
929 | 907 | |
930 | 908 | self.__build_cross_lines() |
931 | 909 | ... | ... |
invesalius/gui/frame.py
... | ... | @@ -36,11 +36,11 @@ import session as ses |
36 | 36 | # Object toolbar |
37 | 37 | OBJ_TOOLS = [ID_ZOOM, ID_ZOOM_SELECT, ID_ROTATE, ID_MOVE, |
38 | 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 | 45 | # Slice toolbar |
46 | 46 | SLICE_TOOLS = [ID_SLICE_SCROLL, ID_CROSS] = [wx.NewId() for number in range(2)] |
... | ... | @@ -672,12 +672,13 @@ class ObjectToolBar(wx.ToolBar): |
672 | 672 | state = self.GetToolState(id) |
673 | 673 | |
674 | 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 | 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 | ... | ... |