Commit 2e32edc719b326604ab928a9357485435f3392c6

Authored by Thiago Franco de Moraes
1 parent f6c43378
Exists in mactoolbar_bkp

Some tests to make toolbar toggle work in mac

Showing 1 changed file with 53 additions and 36 deletions   Show diff stats
invesalius/gui/frame.py
@@ -29,6 +29,8 @@ from wx.lib.pubsub import pub as Publisher @@ -29,6 +29,8 @@ from wx.lib.pubsub import pub as Publisher
29 import wx.lib.agw.toasterbox as TB 29 import wx.lib.agw.toasterbox as TB
30 import wx.lib.popupctl as pc 30 import wx.lib.popupctl as pc
31 31
  32 +from wx.lib.agw.aui.auibar import AuiToolBar
  33 +
32 import constants as const 34 import constants as const
33 import default_tasks as tasks 35 import default_tasks as tasks
34 import default_viewers as viewers 36 import default_viewers as viewers
@@ -182,42 +184,46 @@ class Frame(wx.Frame): @@ -182,42 +184,46 @@ class Frame(wx.Frame):
182 # This is pretty tricky -- order on win32 is inverted when 184 # This is pretty tricky -- order on win32 is inverted when
183 # compared to linux2 & darwin 185 # compared to linux2 & darwin
184 if sys.platform == 'win32': 186 if sys.platform == 'win32':
185 - t1 = ProjectToolBar(self)  
186 - t2 = HistoryToolBar(self)  
187 - t3 = LayoutToolBar(self)  
188 - t4 = ObjectToolBar(self) 187 + #t1 = ProjectToolBar(self)
  188 + #t2 = HistoryToolBar(self)
  189 + #t3 = LayoutToolBar(self)
  190 + #t4 = ObjectToolBar(self)
189 t5 = SliceToolBar(self) 191 t5 = SliceToolBar(self)
190 else: 192 else:
191 - t5 = ProjectToolBar(self)  
192 - t4 = HistoryToolBar(self)  
193 - t3 = LayoutToolBar(self)  
194 - t2 = ObjectToolBar(self) 193 + #t5 = ProjectToolBar(self)
  194 + #t4 = HistoryToolBar(self)
  195 + #t3 = LayoutToolBar(self)
  196 + #t2 = ObjectToolBar(self)
195 t1 = SliceToolBar(self) 197 t1 = SliceToolBar(self)
196 198
  199 +
  200 + #self.SetToolBar(t1)
  201 + #t1.Realize()
  202 +
197 aui_manager.AddPane(t1, wx.aui.AuiPaneInfo(). 203 aui_manager.AddPane(t1, wx.aui.AuiPaneInfo().
198 Name("General Features Toolbar"). 204 Name("General Features Toolbar").
199 ToolbarPane().Top().Floatable(False). 205 ToolbarPane().Top().Floatable(False).
200 LeftDockable(False).RightDockable(False)) 206 LeftDockable(False).RightDockable(False))
201 207
202 - aui_manager.AddPane(t2, wx.aui.AuiPaneInfo().  
203 - Name("Layout Toolbar").  
204 - ToolbarPane().Top().Floatable(False).  
205 - LeftDockable(False).RightDockable(False)) 208 + #aui_manager.AddPane(t2, wx.aui.AuiPaneInfo().
  209 + #Name("Layout Toolbar").
  210 + #ToolbarPane().Top().Floatable(False).
  211 + #LeftDockable(False).RightDockable(False))
206 212
207 - aui_manager.AddPane(t3, wx.aui.AuiPaneInfo().  
208 - Name("Project Toolbar").  
209 - ToolbarPane().Top().Floatable(False).  
210 - LeftDockable(False).RightDockable(False)) 213 + #aui_manager.AddPane(t3, wx.aui.AuiPaneInfo().
  214 + #Name("Project Toolbar").
  215 + #ToolbarPane().Top().Floatable(False).
  216 + #LeftDockable(False).RightDockable(False))
211 217
212 - aui_manager.AddPane(t4, wx.aui.AuiPaneInfo().  
213 - Name("Slice Toolbar").  
214 - ToolbarPane().Top().Floatable(False).  
215 - LeftDockable(False).RightDockable(False)) 218 + #aui_manager.AddPane(t4, wx.aui.AuiPaneInfo().
  219 + #Name("Slice Toolbar").
  220 + #ToolbarPane().Top().Floatable(False).
  221 + #LeftDockable(False).RightDockable(False))
216 222
217 - aui_manager.AddPane(t5, wx.aui.AuiPaneInfo().  
218 - Name("History Toolbar").  
219 - ToolbarPane().Top().Floatable(False).  
220 - LeftDockable(False).RightDockable(False)) 223 + #aui_manager.AddPane(t5, wx.aui.AuiPaneInfo().
  224 + #Name("History Toolbar").
  225 + #ToolbarPane().Top().Floatable(False).
  226 + #LeftDockable(False).RightDockable(False))
221 227
222 aui_manager.Update() 228 aui_manager.Update()
223 self.aui_manager = aui_manager 229 self.aui_manager = aui_manager
@@ -1238,14 +1244,14 @@ class ObjectToolBar(wx.ToolBar): @@ -1238,14 +1244,14 @@ class ObjectToolBar(wx.ToolBar):
1238 # ------------------------------------------------------------------ 1244 # ------------------------------------------------------------------
1239 # ------------------------------------------------------------------ 1245 # ------------------------------------------------------------------
1240 1246
1241 -class SliceToolBar(wx.ToolBar): 1247 +class SliceToolBar(AuiToolBar):
1242 """ 1248 """
1243 Toolbar related to 2D slice specific operations, including: cross 1249 Toolbar related to 2D slice specific operations, including: cross
1244 intersection reference and scroll slices. 1250 intersection reference and scroll slices.
1245 """ 1251 """
1246 def __init__(self, parent): 1252 def __init__(self, parent):
1247 style = wx.TB_FLAT|wx.TB_NODIVIDER | wx.TB_DOCKABLE 1253 style = wx.TB_FLAT|wx.TB_NODIVIDER | wx.TB_DOCKABLE
1248 - wx.ToolBar.__init__(self, parent, -1, wx.DefaultPosition, 1254 + AuiToolBar.__init__(self, parent, -1, wx.DefaultPosition,
1249 wx.DefaultSize, 1255 wx.DefaultSize,
1250 style) 1256 style)
1251 1257
@@ -1279,13 +1285,17 @@ class SliceToolBar(wx.ToolBar): @@ -1279,13 +1285,17 @@ class SliceToolBar(wx.ToolBar):
1279 path = os.path.join(d,"cross.png") 1285 path = os.path.join(d,"cross.png")
1280 BMP_CROSS = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) 1286 BMP_CROSS = wx.Bitmap(path, wx.BITMAP_TYPE_PNG)
1281 1287
1282 - self.AddCheckTool(const.SLICE_STATE_SCROLL,  
1283 - BMP_SLICE,  
1284 - shortHelp = _("Scroll slices")) 1288 + self.sst = self.AddToggleTool(const.SLICE_STATE_SCROLL,
  1289 + BMP_SLICE,#, kind=wx.ITEM_CHECK)
  1290 + wx.NullBitmap,
  1291 + toggle=True,
  1292 + short_help_string=_("Scroll slices"))
1285 1293
1286 - self.AddCheckTool(const.SLICE_STATE_CROSS,  
1287 - BMP_CROSS,  
1288 - shortHelp = _("Slices' cross intersection")) 1294 + self.sct = self.AddToggleTool(const.SLICE_STATE_CROSS,
  1295 + BMP_CROSS,#, kind=wx.ITEM_CHECK)
  1296 + wx.NullBitmap,
  1297 + toggle=True,
  1298 + short_help_string=_("Slices' cross intersection"))
1289 1299
1290 def __bind_events(self): 1300 def __bind_events(self):
1291 """ 1301 """
@@ -1331,7 +1341,9 @@ class SliceToolBar(wx.ToolBar): @@ -1331,7 +1341,9 @@ class SliceToolBar(wx.ToolBar):
1331 should be toggle each time). 1341 should be toggle each time).
1332 """ 1342 """
1333 id = evt.GetId() 1343 id = evt.GetId()
1334 - state = self.GetToolState(id) 1344 + evt.Skip()
  1345 +
  1346 + state = self.GetToolToggled(id)
1335 1347
1336 if state: 1348 if state:
1337 Publisher.sendMessage('Enable style', id) 1349 Publisher.sendMessage('Enable style', id)
@@ -1339,12 +1351,17 @@ class SliceToolBar(wx.ToolBar): @@ -1339,12 +1351,17 @@ class SliceToolBar(wx.ToolBar):
1339 else: 1351 else:
1340 Publisher.sendMessage('Disable style', id) 1352 Publisher.sendMessage('Disable style', id)
1341 1353
1342 - for item in const.TOOL_SLICE_STATES:  
1343 - state = self.GetToolState(item) 1354 + for item in self.enable_items:
  1355 + state = self.GetToolToggled(item)
1344 if state and (item != id): 1356 if state and (item != id):
  1357 + print ">>>>", item
1345 self.ToggleTool(item, False) 1358 self.ToggleTool(item, False)
  1359 + #self.ToggleTool(const.SLICE_STATE_SCROLL, self.GetToolToggled(const.SLICE_STATE_CROSS))
  1360 + #self.Update()
  1361 + ##self.sst.SetToggle(self.sct.IsToggled())
  1362 + ##print ">>>", self.sst.IsToggled()
  1363 + #print ">>>", self.sst.GetState()
1346 1364
1347 - evt.Skip()  
1348 1365
1349 def SetStateProjectClose(self): 1366 def SetStateProjectClose(self):
1350 """ 1367 """