toolbars.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. """!
  2. @package swipe.toolbars
  3. @brief Map Swipe toolbars and icons.
  4. Classes:
  5. - toolbars::swipeMapToolbar
  6. - toolbars::swipeMainToolbar
  7. (C) 2006-2012 by the GRASS Development Team
  8. This program is free software under the GNU General Public
  9. License (>=v2). Read the file COPYING that comes with GRASS
  10. for details.
  11. @author Anna Kratochvilova <kratochanna gmail.com>
  12. """
  13. import wx
  14. from gui_core.toolbars import BaseToolbar, BaseIcons
  15. from icons.icon import MetaIcon
  16. swipeIcons = {
  17. 'tools': MetaIcon(img = 'tools', label = _('Tools')),
  18. }
  19. class SwipeMapToolbar(BaseToolbar):
  20. """!Map toolbar (to control map zoom and rendering)
  21. """
  22. def __init__(self, parent):
  23. """!Map toolbar constructor
  24. """
  25. BaseToolbar.__init__(self, parent)
  26. self.InitToolbar(self._toolbarData())
  27. # realize the toolbar
  28. self.Realize()
  29. self.action = { 'id' : self.pan }
  30. self.defaultAction = { 'id' : self.pan,
  31. 'bind' : self.parent.OnPan }
  32. self.EnableTool(self.zoomBack, False)
  33. def _toolbarData(self):
  34. """!Returns toolbar data (name, icon, handler)"""
  35. # BaseIcons are a set of often used icons. It is possible
  36. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  37. icons = BaseIcons
  38. return self._getToolbarData((("displaymap", icons["display"],
  39. self.parent.OnDraw),
  40. ("rendermap", icons["render"],
  41. self.parent.OnRender),
  42. ("erase", icons["erase"],
  43. self.parent.OnErase),
  44. (None, ), # creates separator
  45. ("pan", icons["pan"],
  46. self.parent.OnPan,
  47. wx.ITEM_CHECK), # toggle tool
  48. ("zoomIn", icons["zoomIn"],
  49. self.parent.OnZoomIn,
  50. wx.ITEM_CHECK),
  51. ("zoomOut", icons["zoomOut"],
  52. self.parent.OnZoomOut,
  53. wx.ITEM_CHECK),
  54. (None, ),
  55. ("zoomBack", icons["zoomBack"],
  56. self.parent.OnZoomBack),
  57. ("zoomToMap", icons["zoomExtent"],
  58. self.parent.OnZoomToMap),
  59. ))
  60. def SetActiveMap(self, index):
  61. """!Set currently selected map.
  62. Unused, needed because of DoubleMapFrame API.
  63. """
  64. pass
  65. class SwipeMainToolbar(BaseToolbar):
  66. """!Toolbar with tools related to application functionality
  67. """
  68. def __init__(self, parent):
  69. """!Toolbar constructor
  70. """
  71. BaseToolbar.__init__(self, parent)
  72. self.InitToolbar(self._toolbarData())
  73. # realize the toolbar
  74. self.Realize()
  75. def _toolbarData(self):
  76. """!Toolbar data"""
  77. icons = swipeIcons
  78. return self._getToolbarData((("addRaster", BaseIcons['addRast'],
  79. self.parent.OnSelectRasters),
  80. (None, ),
  81. ("tools", swipeIcons['tools'],
  82. self.OnToolMenu)
  83. ))
  84. def OnToolMenu(self, event):
  85. """!Menu for additional tools"""
  86. point = wx.GetMousePosition()
  87. toolMenu = wx.Menu()
  88. for label, itype, handler, desc in (
  89. (_("Switch orientation"),
  90. wx.ITEM_NORMAL, self.parent.OnSwitchOrientation, "switchOrientation"),
  91. (_("Switch maps"),
  92. wx.ITEM_NORMAL, self.parent.OnSwitchWindows, "switchMaps")):
  93. # Add items to the menu
  94. item = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  95. text = label,
  96. kind = itype)
  97. toolMenu.AppendItem(item)
  98. self.parent.GetWindow().Bind(wx.EVT_MENU, handler, item)
  99. # Popup the menu. If an item is selected then its handler
  100. # will be called before PopupMenu returns.
  101. self.parent.GetWindow().PopupMenu(toolMenu)
  102. toolMenu.Destroy()