Commit 60b7adb20af35c5aa28ab32a4502650c8bf69415
1 parent
e057d08d
Exists in
master
and in
68 other branches
ENH: Constants are being used to relate frame and viewer_slice modes
Showing
3 changed files
with
216 additions
and
162 deletions
Show diff stats
invesalius/constants.py
| ... | ... | @@ -162,3 +162,28 @@ RAYCASTING_TYPES.sort() |
| 162 | 162 | RAYCASTING_OFF_LABEL = ' Off' |
| 163 | 163 | RAYCASTING_TOOLS = ["Cut plane"] |
| 164 | 164 | |
| 165 | + | |
| 166 | + | |
| 167 | +#### | |
| 168 | +MODE_ZOOM = 0 #"Set Zoom Mode", | |
| 169 | +MODE_ZOOM_SELECTION = 1 #:"Set Zoom Select Mode", | |
| 170 | +MODE_ROTATE = 2#:"Set Spin Mode", | |
| 171 | +MODE_MOVE = 3#:"Set Pan Mode", | |
| 172 | +MODE_WW_WL = 4#:"Bright and contrast adjustment"} | |
| 173 | + | |
| 174 | + | |
| 175 | +# self.states = {0:"Set Zoom Mode", 1:"Set Zoom Select Mode", | |
| 176 | +# 2:"Set Spin Mode", 3:"Set Pan Mode", | |
| 177 | +# 4:"Bright and contrast adjustment"} | |
| 178 | + | |
| 179 | + | |
| 180 | +#ps.Publisher().sendMessage('Set interaction mode %d'% | |
| 181 | +# (MODE_BY_ID[id])) | |
| 182 | + | |
| 183 | +#('Set Editor Mode') | |
| 184 | +#{0:"Set Change Slice Mode"} | |
| 185 | + | |
| 186 | +#### | |
| 187 | +MODE_SLICE_SCROLL = -1 | |
| 188 | +MODE_SLICE_EDITOR = -2 | |
| 189 | + | ... | ... |
invesalius/data/viewer_slice.py
| ... | ... | @@ -21,15 +21,16 @@ import itertools |
| 21 | 21 | |
| 22 | 22 | import vtk |
| 23 | 23 | from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor |
| 24 | + | |
| 24 | 25 | import wx |
| 25 | 26 | import wx.lib.pubsub as ps |
| 26 | 27 | |
| 27 | -import data.slice_ as sl | |
| 28 | + | |
| 28 | 29 | import constants as const |
| 29 | -import project | |
| 30 | 30 | import cursor_actors as ca |
| 31 | +import data.slice_ as sl | |
| 31 | 32 | import data.vtk_utils as vtku |
| 32 | - | |
| 33 | +import project | |
| 33 | 34 | from slice_data import SliceData |
| 34 | 35 | |
| 35 | 36 | class Viewer(wx.Panel): |
| ... | ... | @@ -169,39 +170,39 @@ class Viewer(wx.Panel): |
| 169 | 170 | self.style = style |
| 170 | 171 | self.interactor.SetInteractorStyle(style) |
| 171 | 172 | |
| 172 | - def EditorMode(self, pubsub_evt): | |
| 173 | + def __set_mode_editor(self, pubsub_evt): | |
| 173 | 174 | self.append_mode('EDITOR') |
| 174 | 175 | self.mouse_pressed = 0 |
| 175 | 176 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK)) |
| 176 | 177 | |
| 177 | - def SpinMode(self, pubsub_evt): | |
| 178 | + def __set_mode_spin(self, pubsub_evt): | |
| 178 | 179 | self.append_mode('SPIN') |
| 179 | 180 | self.mouse_pressed = 0 |
| 180 | 181 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) |
| 181 | 182 | |
| 182 | - def ZoomMode(self, pubsub_evt): | |
| 183 | + def __set_mode_zoom(self, pubsub_evt): | |
| 183 | 184 | self.append_mode('ZOOM') |
| 184 | 185 | self.mouse_pressed = 0 |
| 185 | 186 | ICON_IMAGE = wx.Image("../icons/tool_zoom.png",wx.BITMAP_TYPE_PNG) |
| 186 | 187 | self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) |
| 187 | 188 | |
| 188 | - def PanMode(self, pubsub_evt): | |
| 189 | + def __set_mode_pan(self, pubsub_evt): | |
| 189 | 190 | self.append_mode('PAN') |
| 190 | 191 | self.mouse_pressed = 0 |
| 191 | 192 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) |
| 192 | 193 | |
| 193 | - def ZoomSelectMode(self, pubsub_evt): | |
| 194 | + def __set_mode_zoom_select(self, pubsub_evt): | |
| 194 | 195 | self.append_mode('ZOOMSELECT') |
| 195 | 196 | ICON_IMAGE = wx.Image("../icons/tool_zoom.png",wx.BITMAP_TYPE_PNG) |
| 196 | 197 | self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) |
| 197 | 198 | |
| 198 | - def WindowLevelMode(self, pubsub_evt): | |
| 199 | + def __set_mode_window_level(self, pubsub_evt): | |
| 199 | 200 | self.append_mode('WINDOWLEVEL') |
| 200 | 201 | self.mouse_pressed = 0 |
| 201 | 202 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) |
| 202 | 203 | self.interactor.Render() |
| 203 | 204 | |
| 204 | - def ChangeSliceMode(self, pubsub_evt): | |
| 205 | + def __set_mode_slice_scroll(self, pubsub_evt): | |
| 205 | 206 | self.append_mode('CHANGESLICE') |
| 206 | 207 | self.mouse_pressed = 0 |
| 207 | 208 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) |
| ... | ... | @@ -617,22 +618,30 @@ class Viewer(wx.Panel): |
| 617 | 618 | 'Set brush format') |
| 618 | 619 | ps.Publisher().subscribe(self.ChangeBrushOperation, |
| 619 | 620 | 'Set edition operation') |
| 620 | - ps.Publisher().subscribe(self.PanMode, | |
| 621 | - 'Set Pan Mode') | |
| 622 | - ps.Publisher().subscribe(self.EditorMode, | |
| 623 | - 'Set Editor Mode') | |
| 624 | - ps.Publisher().subscribe(self.SpinMode, | |
| 625 | - 'Set Spin Mode') | |
| 626 | - ps.Publisher().subscribe(self.ZoomMode, | |
| 627 | - 'Set Zoom Mode') | |
| 628 | - ps.Publisher().subscribe(self.ZoomSelectMode, | |
| 629 | - 'Set Zoom Select Mode') | |
| 630 | - ps.Publisher().subscribe(self.ZoomSelectMode, | |
| 631 | - 'Set Zoom Select Mode') | |
| 632 | - ps.Publisher().subscribe(self.ChangeSliceMode, | |
| 633 | - 'Set Change Slice Mode') | |
| 634 | - ps.Publisher().subscribe(self.WindowLevelMode, | |
| 635 | - 'Bright and contrast adjustment') | |
| 621 | + | |
| 622 | + ### | |
| 623 | + ps.Publisher().subscribe(self.__set_mode_pan, | |
| 624 | + ('Set interaction mode', | |
| 625 | + const.MODE_MOVE)) | |
| 626 | + ps.Publisher().subscribe(self.__set_mode_editor, | |
| 627 | + ('Set interaction mode', | |
| 628 | + const.MODE_SLICE_EDITOR)) | |
| 629 | + ps.Publisher().subscribe(self.__set_mode_spin, | |
| 630 | + ('Set interaction mode', | |
| 631 | + const.MODE_ROTATE)) | |
| 632 | + ps.Publisher().subscribe(self.__set_mode_zoom, | |
| 633 | + ('Set interaction mode', | |
| 634 | + const.MODE_ZOOM)) | |
| 635 | + ps.Publisher().subscribe(self.__set_mode_zoom_select, | |
| 636 | + ('Set interaction mode', | |
| 637 | + const.MODE_ZOOM_SELECTION)) | |
| 638 | + ps.Publisher().subscribe(self.__set_mode_slice_scroll, | |
| 639 | + ('Set interaction mode', | |
| 640 | + const.MODE_SLICE_SCROLL)) | |
| 641 | + ps.Publisher().subscribe(self.__set_mode_window_level, | |
| 642 | + ('Set interaction mode', | |
| 643 | + const.MODE_WW_WL)) | |
| 644 | + #### | |
| 636 | 645 | ps.Publisher().subscribe(self.UpdateText,\ |
| 637 | 646 | 'Update window and level text') |
| 638 | 647 | ... | ... |
invesalius/gui/frame.py
| 1 | -#-------------------------------------------------------------------------- | |
| 1 | +#-------------------------------------------------------------------- | |
| 2 | 2 | # Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas |
| 3 | 3 | # Copyright: (C) 2001 Centro de Pesquisas Renato Archer |
| 4 | 4 | # Homepage: http://www.softwarepublico.gov.br |
| 5 | 5 | # Contact: invesalius@cti.gov.br |
| 6 | 6 | # License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt) |
| 7 | -#-------------------------------------------------------------------------- | |
| 7 | +#-------------------------------------------------------------------- | |
| 8 | 8 | # Este programa e software livre; voce pode redistribui-lo e/ou |
| 9 | 9 | # modifica-lo sob os termos da Licenca Publica Geral GNU, conforme |
| 10 | 10 | # publicada pela Free Software Foundation; de acordo com a versao 2 |
| ... | ... | @@ -15,21 +15,37 @@ |
| 15 | 15 | # COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM |
| 16 | 16 | # PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais |
| 17 | 17 | # detalhes. |
| 18 | -#-------------------------------------------------------------------------- | |
| 18 | +#-------------------------------------------------------------------- | |
| 19 | + | |
| 20 | +import math | |
| 19 | 21 | import sys |
| 20 | 22 | |
| 21 | 23 | import wx |
| 22 | 24 | import wx.aui |
| 23 | 25 | import wx.lib.agw.aui as aui |
| 24 | 26 | import wx.lib.pubsub as ps |
| 25 | -import math | |
| 26 | 27 | |
| 28 | +import constants as const | |
| 27 | 29 | import default_tasks as tasks |
| 28 | 30 | import default_viewers as viewers |
| 29 | 31 | import import_panel as imp |
| 30 | 32 | |
| 33 | +# File toolbar | |
| 34 | +[ID_FILE_IMPORT, ID_FILE_LOAD_INTERNET, ID_FILE_SAVE, ID_FILE_PHOTO, | |
| 35 | +ID_FILE_PRINT] = [wx.NewId() for number in range(5)] | |
| 31 | 36 | |
| 32 | -[ID_FILE_IMPORT, ID_FILE_LOAD_INTERNET, ID_FILE_SAVE, ID_FILE_PRINT] = [wx.NewId() for number in range(4)] | |
| 37 | +# Object toolbar | |
| 38 | +OBJ_TOOLS = [ID_ZOOM, ID_ZOOM_SELECT, ID_ROTATE, ID_MOVE, | |
| 39 | +ID_CONTRAST] = [wx.NewId() for number in range(5)] | |
| 40 | +MODE_BY_ID = {ID_ZOOM: const.MODE_ZOOM, | |
| 41 | + ID_ZOOM_SELECT: const.MODE_ZOOM_SELECTION, | |
| 42 | + ID_ROTATE: const.MODE_ROTATE, | |
| 43 | + ID_MOVE: const.MODE_MOVE, | |
| 44 | + ID_CONTRAST: const.MODE_WW_WL} | |
| 45 | + | |
| 46 | +# Slice toolbar | |
| 47 | +SLICE_TOOLS = [ID_SLICE_SCROLL] = [wx.NewId() for number in range(1)] | |
| 48 | +SLICE_MODE_BY_ID = {ID_SLICE_SCROLL: const.MODE_SLICE_SCROLL} | |
| 33 | 49 | |
| 34 | 50 | class Frame(wx.Frame): |
| 35 | 51 | def __init__(self, prnt): |
| ... | ... | @@ -218,7 +234,7 @@ class MenuBar(wx.MenuBar): |
| 218 | 234 | print "Open" |
| 219 | 235 | event.Skip() |
| 220 | 236 | |
| 221 | -# ------------------------------------------------------------------------------ | |
| 237 | +# ------------------------------------------------------------------ | |
| 222 | 238 | class ProgressBar(wx.Gauge): |
| 223 | 239 | |
| 224 | 240 | def __init__(self, parent): |
| ... | ... | @@ -228,7 +244,8 @@ class ProgressBar(wx.Gauge): |
| 228 | 244 | self.__bind_events() |
| 229 | 245 | |
| 230 | 246 | def __bind_events(self): |
| 231 | - ps.Publisher().subscribe(self.Reposition, 'ProgressBar Reposition') | |
| 247 | + ps.Publisher().subscribe(self.Reposition, | |
| 248 | + 'ProgressBar Reposition') | |
| 232 | 249 | |
| 233 | 250 | def UpdateValue(self, value): |
| 234 | 251 | #value = int(math.ceil(evt_pubsub.data[0])) |
| ... | ... | @@ -245,7 +262,7 @@ class ProgressBar(wx.Gauge): |
| 245 | 262 | self.SetPosition((rect.x + 2, rect.y + 2)) |
| 246 | 263 | self.SetSize((rect.width - 4, rect.height - 4)) |
| 247 | 264 | |
| 248 | -# ------------------------------------------------------------------------------ | |
| 265 | +# ------------------------------------------------------------------ | |
| 249 | 266 | class StatusBar(wx.StatusBar): |
| 250 | 267 | def __init__(self, parent): |
| 251 | 268 | wx.StatusBar.__init__(self, parent, -1) |
| ... | ... | @@ -260,7 +277,8 @@ class StatusBar(wx.StatusBar): |
| 260 | 277 | self.__bind_events() |
| 261 | 278 | |
| 262 | 279 | def __bind_events(self): |
| 263 | - ps.Publisher().subscribe(self.UpdateStatus, 'Update status in GUI') | |
| 280 | + ps.Publisher().subscribe(self.UpdateStatus, | |
| 281 | + 'Update status in GUI') | |
| 264 | 282 | ps.Publisher().subscribe(self.UpdateStatusLabel, |
| 265 | 283 | 'Update status text in GUI') |
| 266 | 284 | |
| ... | ... | @@ -274,7 +292,7 @@ class StatusBar(wx.StatusBar): |
| 274 | 292 | self.SetStatusText(label, 0) |
| 275 | 293 | |
| 276 | 294 | |
| 277 | -# ------------------------------------------------------------------------------ | |
| 295 | +# ------------------------------------------------------------------ | |
| 278 | 296 | |
| 279 | 297 | class TaskBarIcon(wx.TaskBarIcon): |
| 280 | 298 | def __init__(self, parent=None): |
| ... | ... | @@ -291,17 +309,17 @@ class TaskBarIcon(wx.TaskBarIcon): |
| 291 | 309 | def OnTaskBarActivate(self): |
| 292 | 310 | pass |
| 293 | 311 | |
| 294 | -# ------------------------------------------------------------------------------ | |
| 312 | +# ------------------------------------------------------------------ | |
| 295 | 313 | |
| 296 | 314 | class ProjectToolBar(aui.AuiToolBar): |
| 297 | 315 | def __init__(self, parent): |
| 298 | 316 | aui.AuiToolBar.__init__(self, parent, -1, wx.DefaultPosition, |
| 299 | - wx.DefaultSize, | |
| 300 | - aui.AUI_TB_DEFAULT_STYLE) | |
| 317 | + wx.DefaultSize, aui.AUI_TB_DEFAULT_STYLE) | |
| 301 | 318 | |
| 302 | - self.SetToolBitmapSize(wx.Size(32,32)) | |
| 319 | + self.SetToolBitmapSize(wx.Size(16,16)) | |
| 303 | 320 | |
| 304 | 321 | self.parent = parent |
| 322 | + | |
| 305 | 323 | self.__init_items() |
| 306 | 324 | self.__bind_events() |
| 307 | 325 | |
| ... | ... | @@ -319,187 +337,189 @@ class ProjectToolBar(aui.AuiToolBar): |
| 319 | 337 | BMP_PHOTO = wx.Bitmap("../icons/tool_photo.png", |
| 320 | 338 | wx.BITMAP_TYPE_PNG) |
| 321 | 339 | |
| 322 | - self.AddSimpleTool(ID_FILE_IMPORT, "Import medical image...", BMP_IMPORT) | |
| 323 | - self.AddSimpleTool(ID_FILE_LOAD_INTERNET, "Load medical image...", | |
| 324 | - BMP_NET) | |
| 325 | - self.AddSimpleTool(ID_FILE_SAVE, "Save InVesalius project", BMP_SAVE) | |
| 326 | - self.AddSimpleTool(101, "Take photo of screen", BMP_PHOTO) | |
| 327 | - self.AddSimpleTool(ID_FILE_PRINT, "Print medical image...", BMP_PRINT) | |
| 328 | - | |
| 340 | + self.AddSimpleTool(ID_FILE_IMPORT, | |
| 341 | + "Import medical image...", | |
| 342 | + BMP_IMPORT) | |
| 343 | + self.AddSimpleTool(ID_FILE_LOAD_INTERNET, | |
| 344 | + "Load medical image...", | |
| 345 | + BMP_NET) | |
| 346 | + self.AddSimpleTool(ID_FILE_SAVE, | |
| 347 | + "Save InVesalius project", | |
| 348 | + BMP_SAVE) | |
| 349 | + self.AddSimpleTool(ID_FILE_PHOTO, | |
| 350 | + "Take photo of screen", | |
| 351 | + BMP_PHOTO) | |
| 352 | + self.AddSimpleTool(ID_FILE_PRINT, | |
| 353 | + "Print medical image...", | |
| 354 | + BMP_PRINT) | |
| 329 | 355 | |
| 330 | 356 | self.Realize() |
| 331 | 357 | |
| 332 | 358 | def __bind_events(self): |
| 333 | 359 | pass |
| 334 | 360 | |
| 335 | -# ------------------------------------------------------------------------------ | |
| 361 | +# ------------------------------------------------------------------ | |
| 336 | 362 | |
| 337 | -class ObjectToolBar(wx.ToolBar): | |
| 338 | - # TODO: what will appear in menubar? | |
| 363 | +class ObjectToolBar(aui.AuiToolBar): | |
| 339 | 364 | def __init__(self, parent): |
| 340 | - wx.ToolBar.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize, | |
| 341 | - wx.TB_FLAT|wx.TB_NODIVIDER | wx.TB_DOCKABLE) | |
| 342 | - | |
| 343 | - self.SetToolBitmapSize(wx.Size(32,32)) | |
| 365 | + aui.AuiToolBar.__init__(self, parent, -1, wx.DefaultPosition, | |
| 366 | + wx.DefaultSize, aui.AUI_TB_DEFAULT_STYLE) | |
| 367 | + self.SetToolBitmapSize(wx.Size(16,16)) | |
| 344 | 368 | |
| 345 | 369 | self.parent = parent |
| 370 | + | |
| 346 | 371 | self.__init_items() |
| 347 | 372 | self.__bind_events() |
| 373 | + self.__bind_events_wx() | |
| 348 | 374 | |
| 349 | 375 | def __init_items(self): |
| 350 | 376 | |
| 351 | 377 | |
| 352 | - if sys.platform == 'darwin': | |
| 353 | - BMP_ROTATE = wx.Bitmap("../icons/tool_rotate_original.gif", | |
| 354 | - wx.BITMAP_TYPE_GIF) | |
| 355 | - BMP_TRANSLATE = wx.Bitmap("../icons/tool_translate_original.png", | |
| 356 | - wx.BITMAP_TYPE_PNG) | |
| 357 | - BMP_ZOOM = wx.Bitmap("../icons/tool_zoom_original.png", | |
| 358 | - wx.BITMAP_TYPE_PNG) | |
| 359 | - BMP_ZOOM_SELECT = wx.Bitmap("../icons/tool_zoom_select_original.png", | |
| 378 | + BMP_ROTATE = wx.Bitmap("../icons/tool_rotate.gif", | |
| 379 | + wx.BITMAP_TYPE_GIF) | |
| 380 | + BMP_MOVE = wx.Bitmap("../icons/tool_translate.gif", | |
| 381 | + wx.BITMAP_TYPE_GIF) | |
| 382 | + BMP_ZOOM = wx.Bitmap("../icons/tool_zoom.png", | |
| 383 | + wx.BITMAP_TYPE_PNG) | |
| 384 | + BMP_ZOOM_SELECT = wx.Bitmap("../icons/tool_zoom_select.png", | |
| 360 | 385 | wx.BITMAP_TYPE_PNG) |
| 361 | - BMP_CONTRAST = wx.Bitmap("../icons/tool_contrast.png", | |
| 362 | - wx.BITMAP_TYPE_PNG) | |
| 363 | - else: | |
| 364 | - BMP_ROTATE = wx.Bitmap("../icons/tool_rotate.gif", wx.BITMAP_TYPE_GIF) | |
| 365 | - BMP_TRANSLATE = wx.Bitmap("../icons/tool_translate.gif", wx.BITMAP_TYPE_GIF) | |
| 366 | - BMP_ZOOM = wx.Bitmap("../icons/tool_zoom.png", wx.BITMAP_TYPE_PNG) | |
| 367 | - BMP_ZOOM_SELECT = wx.Bitmap("../icons/tool_zoom_select.png", wx.BITMAP_TYPE_PNG) | |
| 368 | - BMP_CONTRAST = wx.Bitmap("../icons/tool_contrast.png", wx.BITMAP_TYPE_PNG) | |
| 369 | - | |
| 370 | - | |
| 371 | - self.AddLabelTool(0, "Zoom in image", BMP_ZOOM, kind = wx.ITEM_CHECK) | |
| 372 | - self.AddLabelTool(1, "Zoom out image", BMP_ZOOM_SELECT, kind = wx.ITEM_CHECK) | |
| 373 | - self.AddLabelTool(2, "Rotate image", BMP_ROTATE, kind = wx.ITEM_CHECK) | |
| 374 | - self.AddLabelTool(3, "Translate image", BMP_TRANSLATE, kind = wx.ITEM_CHECK) | |
| 375 | - self.AddLabelTool(4, "Bright and contrast adjustment", BMP_CONTRAST, kind = wx.ITEM_CHECK) | |
| 376 | - | |
| 386 | + BMP_CONTRAST = wx.Bitmap("../icons/tool_contrast.png", | |
| 387 | + wx.BITMAP_TYPE_PNG) | |
| 388 | + | |
| 389 | + | |
| 390 | + self.AddSimpleTool(ID_ZOOM, | |
| 391 | + "Zoom", | |
| 392 | + BMP_ZOOM, | |
| 393 | + kind = aui.ITEM_RADIO) | |
| 394 | + | |
| 395 | + self.AddSimpleTool(ID_ZOOM_SELECT, | |
| 396 | + "Zoom based on selection", | |
| 397 | + BMP_ZOOM_SELECT, | |
| 398 | + kind = aui.ITEM_RADIO) | |
| 399 | + | |
| 400 | + self.AddSimpleTool(ID_ROTATE, | |
| 401 | + "Rotate", BMP_ROTATE, | |
| 402 | + kind = aui.ITEM_RADIO) | |
| 403 | + | |
| 404 | + self.AddSimpleTool(ID_MOVE, | |
| 405 | + "Move", BMP_MOVE, | |
| 406 | + kind = aui.ITEM_RADIO) | |
| 407 | + | |
| 408 | + self.AddSimpleTool(ID_CONTRAST, | |
| 409 | + "Window and Level", BMP_CONTRAST, | |
| 410 | + kind = aui.ITEM_RADIO) | |
| 377 | 411 | self.Realize() |
| 378 | 412 | |
| 379 | - self.states = {0:"Set Zoom Mode", 1:"Set Zoom Select Mode", | |
| 380 | - 2:"Set Spin Mode", 3:"Set Pan Mode", | |
| 381 | - 4: "Bright and contrast adjustment"} | |
| 382 | 413 | |
| 383 | - def __bind_events(self): | |
| 414 | + def __bind_events_wx(self): | |
| 384 | 415 | self.Bind(wx.EVT_TOOL, self.OnClick) |
| 385 | - ps.Publisher().subscribe(self.UnToggleAllItem, 'UnToogle All Object Item') | |
| 386 | 416 | |
| 387 | - def OnClick(self, evt): | |
| 417 | + def __bind_events(self): | |
| 418 | + ps.Publisher().subscribe(self.UntoggleAllItems, | |
| 419 | + 'Untoggle object toolbar items') | |
| 388 | 420 | |
| 421 | + def OnClick(self, evt): | |
| 422 | + print "OnClick", evt.GetId() | |
| 389 | 423 | id = evt.GetId() |
| 390 | - exist_enable_state = 0 | |
| 391 | - | |
| 392 | - for x in xrange(0,len(self.states)): | |
| 393 | - #necessary if the usurio enable another state | |
| 394 | - #with a longer allow, disable the previous state | |
| 395 | - state = self.GetToolState(x) | |
| 396 | - if not (x == id) and (state == True): | |
| 397 | - self.ToggleTool(x, False) | |
| 398 | - elif(state == True) and (id == x): | |
| 399 | - ps.Publisher().sendMessage(self.states[id]) | |
| 400 | - exist_enable_state = 1 | |
| 401 | - | |
| 402 | - #Not exist's tool enbled, change to default state | |
| 403 | - if not (exist_enable_state): | |
| 404 | - ps.Publisher().sendMessage('Set Editor Mode') | |
| 405 | - | |
| 406 | - ps.Publisher().sendMessage('UnToogle All Slice Item') | |
| 424 | + state = self.GetToolToggled(id) | |
| 425 | + label = self.GetToolLabel(id) | |
| 426 | + | |
| 427 | + #if id != ID_ZOOM: | |
| 428 | + # print "Toggled zoom off" | |
| 429 | + # self.ToggleTool(ID_ZOOM, 0) | |
| 430 | + | |
| 431 | + if state: | |
| 432 | + ps.Publisher().sendMessage(('Set interaction mode', | |
| 433 | + MODE_BY_ID[id])) | |
| 434 | + else: | |
| 435 | + ps.Publisher().sendMessage(('Set interaction mode', | |
| 436 | + MODE_SLICE_EDITOR)) | |
| 437 | + ps.Publisher().sendMessage('Untoggle slice toolbar items') | |
| 438 | + | |
| 439 | + for id in OBJ_TOOLS: | |
| 440 | + print "-- id: %d, state: %d", id, self.GetToolToggled(id) | |
| 441 | + | |
| 442 | + | |
| 407 | 443 | evt.Skip() |
| 408 | 444 | |
| 445 | + def UntoggleAllItems(self, pubsub_evt): | |
| 446 | + for id in OBJ_TOOLS: | |
| 447 | + state = self.GetToolToggled(id) | |
| 448 | + if state: | |
| 449 | + self.ToggleTool(id, False) | |
| 409 | 450 | |
| 410 | - def UnToggleAllItem(self, pubsub_evt): | |
| 411 | - for x in xrange(0,len(self.states)): | |
| 412 | - #necessary if the usurio enable another state | |
| 413 | - #with a longer allow, disable the previous state | |
| 414 | - state = self.GetToolState(x) | |
| 415 | - if not (x == id) and (state == True): | |
| 416 | - self.ToggleTool(x, False) | |
| 451 | +# ------------------------------------------------------------------- | |
| 417 | 452 | |
| 418 | -# ------------------------------------------------------------------------------ | |
| 419 | - | |
| 420 | -class SliceToolBar(wx.ToolBar): | |
| 421 | - # TODO: what will appear in menubar? | |
| 453 | +class SliceToolBar(aui.AuiToolBar): | |
| 422 | 454 | def __init__(self, parent): |
| 423 | - wx.ToolBar.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_FLAT|wx.TB_NODIVIDER) | |
| 424 | - | |
| 425 | - self.SetToolBitmapSize(wx.Size(32,32)) | |
| 455 | + aui.AuiToolBar.__init__(self, parent, -1, wx.DefaultPosition, | |
| 456 | + wx.DefaultSize, aui.AUI_TB_DEFAULT_STYLE) | |
| 457 | + self.SetToolBitmapSize(wx.Size(16,16)) | |
| 426 | 458 | |
| 427 | 459 | self.parent = parent |
| 428 | 460 | self.__init_items() |
| 429 | 461 | self.__bind_events() |
| 462 | + self.__bind_events_wx() | |
| 430 | 463 | |
| 431 | 464 | def __init_items(self): |
| 432 | - if sys.platform == 'darwin': | |
| 433 | - BMP_SLICE = wx.Bitmap("../icons/slice_original.png", | |
| 434 | - wx.BITMAP_TYPE_PNG) | |
| 435 | - else: | |
| 436 | - BMP_SLICE = wx.Bitmap("../icons/slice.png", | |
| 437 | - wx.BITMAP_TYPE_PNG) | |
| 438 | - | |
| 439 | - self.AddLabelTool(0, "Change Slice", BMP_SLICE, kind = wx.ITEM_CHECK) | |
| 465 | + BMP_SLICE = wx.Bitmap("../icons/slice.png", | |
| 466 | + wx.BITMAP_TYPE_PNG) | |
| 467 | + self.AddSimpleTool(ID_SLICE_SCROLL, "Scroll slice", | |
| 468 | + BMP_SLICE, kind = aui.ITEM_RADIO) | |
| 440 | 469 | |
| 441 | 470 | self.Realize() |
| 442 | 471 | |
| 443 | - self.states = {0:"Set Change Slice Mode"} | |
| 472 | + def __bind_events_wx(self): | |
| 473 | + self.Bind(wx.EVT_TOOL, self.OnClick) | |
| 444 | 474 | |
| 445 | 475 | def __bind_events(self): |
| 446 | - self.Bind(wx.EVT_TOOL, self.OnClick) | |
| 447 | - ps.Publisher().subscribe(self.UnToggleAllItem, "UnToogle All Slice Item") | |
| 476 | + ps.Publisher().subscribe(self.UntoggleAllItem, | |
| 477 | + 'Untoggle slice toolbar items') | |
| 448 | 478 | |
| 449 | 479 | def OnClick(self, evt): |
| 450 | 480 | |
| 451 | 481 | id = evt.GetId() |
| 452 | - exist_enable_state = 0 | |
| 482 | + state = self.GetToolToggled(id) | |
| 483 | + label = self.GetToolLabel(id) | |
| 453 | 484 | |
| 454 | - for x in xrange(0,len(self.states)): | |
| 455 | - #necessary if the usurio enable another state | |
| 456 | - #with a longer allow, disable the previous state | |
| 457 | - state = self.GetToolState(x) | |
| 458 | - if not (x == id) and (state == True): | |
| 459 | - self.ToggleTool(x, False) | |
| 460 | - elif(state == True) and (id == x): | |
| 461 | - ps.Publisher().sendMessage(self.states[x]) | |
| 462 | - exist_enable_state = 1 | |
| 463 | - | |
| 464 | - #Not exist's tool enbled, change to default state | |
| 465 | - if not (exist_enable_state): | |
| 466 | - ps.Publisher().sendMessage('Set Editor Mode') | |
| 467 | - | |
| 468 | - ps.Publisher().sendMessage('UnToogle All Object Item') | |
| 485 | + if state: | |
| 486 | + ps.Publisher().sendMessage(('Set interaction mode', | |
| 487 | + SLICE_MODE_BY_ID[id])) | |
| 488 | + else: | |
| 489 | + ps.Publisher().sendMessage(('Set interaction mode', | |
| 490 | + const.MODE_SLICE_EDITOR)) | |
| 491 | + ps.Publisher().sendMessage('Untoggle object toolbar items') | |
| 469 | 492 | |
| 470 | 493 | evt.Skip() |
| 471 | 494 | |
| 472 | - def UnToggleAllItem(self, pubsub_evt): | |
| 473 | - for x in xrange(0, len(self.states)): | |
| 474 | - #necessary if the usurio enable another state | |
| 475 | - #with a longer allow, disable the previous state | |
| 476 | - state = self.GetToolState(x) | |
| 477 | - if not (x == id) and (state == True): | |
| 478 | - self.ToggleTool(x, False) | |
| 479 | 495 | |
| 480 | -# ------------------------------------------------------------------------------ | |
| 496 | + def UntoggleAllItem(self, pubsub_evt): | |
| 497 | + for id in SLICE_TOOLS: | |
| 498 | + state = self.GetToolToggled(id) | |
| 499 | + if state: | |
| 500 | + self.ToggleTool(id, False) | |
| 501 | + | |
| 502 | +# --------------------------------------------------------------------- | |
| 481 | 503 | |
| 482 | -class LayoutToolBar(wx.ToolBar): | |
| 504 | +class LayoutToolBar(aui.AuiToolBar): | |
| 483 | 505 | # TODO: what will appear in menubar? |
| 484 | 506 | def __init__(self, parent): |
| 485 | - wx.ToolBar.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_FLAT|wx.TB_NODIVIDER) | |
| 507 | + aui.AuiToolBar.__init__(self, parent, -1, wx.DefaultPosition, | |
| 508 | + wx.DefaultSize, aui.AUI_TB_DEFAULT_STYLE) | |
| 486 | 509 | |
| 487 | - self.SetToolBitmapSize(wx.Size(32,32)) | |
| 510 | + self.SetToolBitmapSize(wx.Size(16,16)) | |
| 488 | 511 | |
| 489 | 512 | self.parent = parent |
| 490 | 513 | self.__init_items() |
| 491 | 514 | self.__bind_events() |
| 492 | 515 | |
| 493 | 516 | def __init_items(self): |
| 494 | - if sys.platform == 'darwin': | |
| 495 | - BMP_ROTATE = wx.Bitmap("../icons/layout_data_only_original.gif", wx.BITMAP_TYPE_GIF) | |
| 496 | - BMP_TRANSLATE = wx.Bitmap("../icons/layout_full_original.gif", wx.BITMAP_TYPE_GIF) | |
| 497 | - else: | |
| 498 | - BMP_ROTATE = wx.Bitmap("../icons/layout_data_only.gif", wx.BITMAP_TYPE_GIF) | |
| 499 | - BMP_TRANSLATE = wx.Bitmap("../icons/layout_full.gif", wx.BITMAP_TYPE_GIF) | |
| 500 | - | |
| 501 | - self.AddLabelTool(101, "Rotate image", BMP_ROTATE) | |
| 502 | - self.AddLabelTool(101, "Translate image", BMP_TRANSLATE) | |
| 517 | + BMP_ROTATE = wx.Bitmap("../icons/layout_data_only.gif", | |
| 518 | + wx.BITMAP_TYPE_GIF) | |
| 519 | + BMP_TRANSLATE = wx.Bitmap("../icons/layout_full.gif", | |
| 520 | + wx.BITMAP_TYPE_GIF) | |
| 521 | + self.AddSimpleTool(101, "Rotate image", BMP_ROTATE) | |
| 522 | + self.AddSimpleTool(101, "Translate image", BMP_TRANSLATE) | |
| 503 | 523 | |
| 504 | 524 | self.Realize() |
| 505 | 525 | ... | ... |