Commit 1e35898ea879f1a593b6e93855d685793cc9b873

Authored by Paulo Henrique Junqueira Amorim
1 parent 985022bd

ADD: Tool to change slices with left button

Showing 1 changed file with 100 additions and 17 deletions   Show diff stats
invesalius/gui/frame.py
... ... @@ -99,7 +99,9 @@ class Frame(wx.Frame):
99 99 t1 = ProjectToolBar(self)
100 100 #t2 = LayoutToolBar(self)
101 101 t3 = ObjectToolBar(self)
  102 + t4 = SliceToolBar(self)
102 103 else:
  104 + t4 = SliceToolBar(self)
103 105 t3 = ProjectToolBar(self)
104 106 #t2 = LayoutToolBar(self)
105 107 t1 = ObjectToolBar(self)
... ... @@ -119,6 +121,10 @@ class Frame(wx.Frame):
119 121 ToolbarPane().Top().Floatable(False).
120 122 LeftDockable(False).RightDockable(False))
121 123  
  124 + aui_manager.AddPane(t4, wx.aui.AuiPaneInfo().
  125 + Name("Slice Toolbar").
  126 + ToolbarPane().Top().Floatable(False).
  127 + LeftDockable(False).RightDockable(False))
122 128  
123 129 aui_manager.Update()
124 130  
... ... @@ -290,8 +296,9 @@ class ProjectToolBar(wx.ToolBar):
290 296 def __init__(self, parent):
291 297 wx.ToolBar.__init__(self, parent, -1, wx.DefaultPosition,
292 298 wx.DefaultSize, wx.TB_FLAT|wx.TB_NODIVIDER)
293   - if sys.platform == 'darwin':
294   - self.SetToolBitmapSize(wx.Size(32,32))
  299 +
  300 + self.SetToolBitmapSize(wx.Size(32,32))
  301 +
295 302 self.parent = parent
296 303 self.__init_items()
297 304 self.__bind_events()
... ... @@ -335,13 +342,15 @@ class ProjectToolBar(wx.ToolBar):
335 342 def __bind_events(self):
336 343 pass
337 344  
  345 +# ------------------------------------------------------------------------------
  346 +
338 347 class ObjectToolBar(wx.ToolBar):
339 348 # TODO: what will appear in menubar?
340 349 def __init__(self, parent):
341 350 wx.ToolBar.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize,
342 351 wx.TB_FLAT|wx.TB_NODIVIDER | wx.TB_DOCKABLE)
343   - if sys.platform == 'darwin':
344   - self.SetToolBitmapSize(wx.Size(32,32))
  352 +
  353 + self.SetToolBitmapSize(wx.Size(32,32))
345 354  
346 355 self.parent = parent
347 356 self.__init_items()
... ... @@ -369,28 +378,28 @@ class ObjectToolBar(wx.ToolBar):
369 378 BMP_CONTRAST = wx.Bitmap("../icons/tool_contrast.png", wx.BITMAP_TYPE_PNG)
370 379  
371 380  
372   - self.AddLabelTool(1, "Zoom in image", BMP_ZOOM, kind = wx.ITEM_CHECK)
373   - self.AddLabelTool(2, "Zoom out image", BMP_ZOOM_SELECT, kind = wx.ITEM_CHECK)
374   - self.AddLabelTool(3, "Rotate image", BMP_ROTATE, kind = wx.ITEM_CHECK)
375   - self.AddLabelTool(4, "Translate image", BMP_TRANSLATE, kind = wx.ITEM_CHECK)
376   - self.AddLabelTool(5, "Bright and contrast adjustment", BMP_CONTRAST, kind = wx.ITEM_CHECK)
  381 + self.AddLabelTool(0, "Zoom in image", BMP_ZOOM, kind = wx.ITEM_CHECK)
  382 + self.AddLabelTool(1, "Zoom out image", BMP_ZOOM_SELECT, kind = wx.ITEM_CHECK)
  383 + self.AddLabelTool(2, "Rotate image", BMP_ROTATE, kind = wx.ITEM_CHECK)
  384 + self.AddLabelTool(3, "Translate image", BMP_TRANSLATE, kind = wx.ITEM_CHECK)
  385 + self.AddLabelTool(4, "Bright and contrast adjustment", BMP_CONTRAST, kind = wx.ITEM_CHECK)
377 386  
378   - self.Bind(wx.EVT_TOOL, self.OnClick)
379 387 self.Realize()
380   -
381   - self.states = {1:"Set Zoom Mode", 2:"Set Zoom Select Mode",
382   - 3:"Set Spin Mode", 4:"Set Pan Mode",
383   - 5: "Bright and contrast adjustment"}
  388 +
  389 + self.states = {0:"Set Zoom Mode", 1:"Set Zoom Select Mode",
  390 + 2:"Set Spin Mode", 3:"Set Pan Mode",
  391 + 4: "Bright and contrast adjustment"}
384 392  
385 393 def __bind_events(self):
386   - pass
  394 + self.Bind(wx.EVT_TOOL, self.OnClick)
  395 + ps.Publisher().subscribe(self.UnToggleAllItem, 'UnToogle All Object Item')
387 396  
388 397 def OnClick(self, evt):
389 398  
390 399 id = evt.GetId()
391 400 exist_enable_state = 0
392 401  
393   - for x in xrange(1,6):
  402 + for x in xrange(0,len(self.states)):
394 403 #necessary if the usurio enable another state
395 404 #with a longer allow, disable the previous state
396 405 state = self.GetToolState(x)
... ... @@ -403,9 +412,83 @@ class ObjectToolBar(wx.ToolBar):
403 412 #Not exist's tool enbled, change to default state
404 413 if not (exist_enable_state):
405 414 ps.Publisher().sendMessage('Set Editor Mode')
  415 +
  416 + ps.Publisher().sendMessage('UnToogle All Slice Item')
  417 + evt.Skip()
  418 +
  419 +
  420 + def UnToggleAllItem(self, pubsub_evt):
  421 + for x in xrange(0,len(self.states)):
  422 + #necessary if the usurio enable another state
  423 + #with a longer allow, disable the previous state
  424 + state = self.GetToolState(x)
  425 + if not (x == id) and (state == True):
  426 + self.ToggleTool(x, False)
  427 +
  428 +# ------------------------------------------------------------------------------
  429 +
  430 +class SliceToolBar(wx.ToolBar):
  431 + # TODO: what will appear in menubar?
  432 + def __init__(self, parent):
  433 + wx.ToolBar.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_FLAT|wx.TB_NODIVIDER)
  434 +
  435 + self.SetToolBitmapSize(wx.Size(32,32))
406 436  
  437 + self.parent = parent
  438 + self.__init_items()
  439 + self.__bind_events()
  440 +
  441 + def __init_items(self):
  442 + if sys.platform == 'darwin':
  443 + BMP_SLICE = wx.Bitmap("../icons/slice_original.png",
  444 + wx.BITMAP_TYPE_PNG)
  445 + else:
  446 + BMP_SLICE = wx.Bitmap("../icons/slice.png",
  447 + wx.BITMAP_TYPE_PNG)
  448 +
  449 + self.AddLabelTool(0, "Change Slice", BMP_SLICE, kind = wx.ITEM_CHECK)
  450 +
  451 + self.Realize()
  452 +
  453 + self.states = {0:"Set Change Slice Mode"}
  454 +
  455 + def __bind_events(self):
  456 + self.Bind(wx.EVT_TOOL, self.OnClick)
  457 + ps.Publisher().subscribe(self.UnToggleAllItem, "UnToogle All Slice Item")
  458 +
  459 + def OnClick(self, evt):
  460 +
  461 + id = evt.GetId()
  462 + exist_enable_state = 0
  463 +
  464 + for x in xrange(0,len(self.states)):
  465 + #necessary if the usurio enable another state
  466 + #with a longer allow, disable the previous state
  467 + state = self.GetToolState(x)
  468 + if not (x == id) and (state == True):
  469 + self.ToggleTool(x, False)
  470 + elif(state == True) and (id == x):
  471 + ps.Publisher().sendMessage(self.states[x])
  472 + exist_enable_state = 1
  473 +
  474 + #Not exist's tool enbled, change to default state
  475 + if not (exist_enable_state):
  476 + ps.Publisher().sendMessage('Set Editor Mode')
  477 +
  478 + ps.Publisher().sendMessage('UnToogle All Object Item')
  479 +
407 480 evt.Skip()
408 481  
  482 + def UnToggleAllItem(self, pubsub_evt):
  483 + for x in xrange(0, len(self.states)):
  484 + #necessary if the usurio enable another state
  485 + #with a longer allow, disable the previous state
  486 + state = self.GetToolState(x)
  487 + if not (x == id) and (state == True):
  488 + self.ToggleTool(x, False)
  489 +
  490 +# ------------------------------------------------------------------------------
  491 +
409 492 class LayoutToolBar(wx.ToolBar):
410 493 # TODO: what will appear in menubar?
411 494 def __init__(self, parent):
... ... @@ -427,4 +510,4 @@ class LayoutToolBar(wx.ToolBar):
427 510 self.Realize()
428 511  
429 512 def __bind_events(self):
430 513 - pass
  514 + pass
431 515 \ No newline at end of file
... ...