toolbars.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. """!
  2. @package swipe.toolbars
  3. @brief Map Swipe toolbars and icons.
  4. Classes:
  5. - toolbars::SwipeMapToolbar
  6. - toolbars::SwipeMainToolbar
  7. - toolbars::SwipeMiscToolbar
  8. (C) 2012 by the GRASS Development Team
  9. This program is free software under the GNU General Public License
  10. (>=v2). Read the file COPYING that comes with GRASS 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. 'quit' : BaseIcons['quit'].SetLabel(_("Quit Map Swipe")),
  19. 'addRast' : BaseIcons['addRast'].SetLabel(_("Select raster maps")),
  20. }
  21. class SwipeMapToolbar(BaseToolbar):
  22. """!Map toolbar (to control map zoom and rendering)
  23. """
  24. def __init__(self, parent):
  25. """!Map toolbar constructor
  26. """
  27. BaseToolbar.__init__(self, parent)
  28. self.InitToolbar(self._toolbarData())
  29. # realize the toolbar
  30. self.Realize()
  31. self.action = { 'id' : self.pan }
  32. self.defaultAction = { 'id' : self.pan,
  33. 'bind' : self.parent.OnPan }
  34. self.EnableTool(self.zoomBack, False)
  35. def _toolbarData(self):
  36. """!Returns toolbar data (name, icon, handler)"""
  37. # BaseIcons are a set of often used icons. It is possible
  38. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  39. icons = BaseIcons
  40. return self._getToolbarData((("displaymap", icons["display"],
  41. self.parent.OnDraw),
  42. ("rendermap", icons["render"],
  43. self.parent.OnRender),
  44. ("erase", icons["erase"],
  45. self.parent.OnErase),
  46. (None, ), # creates separator
  47. ("pan", icons["pan"],
  48. self.parent.OnPan,
  49. wx.ITEM_CHECK), # toggle tool
  50. ("zoomIn", icons["zoomIn"],
  51. self.parent.OnZoomIn,
  52. wx.ITEM_CHECK),
  53. ("zoomOut", icons["zoomOut"],
  54. self.parent.OnZoomOut,
  55. wx.ITEM_CHECK),
  56. (None, ),
  57. ("zoomBack", icons["zoomBack"],
  58. self.parent.OnZoomBack),
  59. ("zoomToMap", icons["zoomExtent"],
  60. self.parent.OnZoomToMap),
  61. ))
  62. def SetActiveMap(self, index):
  63. """!Set currently selected map.
  64. Unused, needed because of DoubleMapFrame API.
  65. """
  66. pass
  67. class SwipeMainToolbar(BaseToolbar):
  68. """!Toolbar with tools related to application functionality
  69. """
  70. def __init__(self, parent):
  71. """!Toolbar constructor
  72. """
  73. BaseToolbar.__init__(self, parent)
  74. self.InitToolbar(self._toolbarData())
  75. # realize the toolbar
  76. self.Realize()
  77. def _toolbarData(self):
  78. """!Toolbar data"""
  79. return self._getToolbarData((("addRaster", swipeIcons['addRast'],
  80. self.parent.OnSelectRasters),
  81. (None, ),
  82. ("tools", swipeIcons['tools'],
  83. self.OnToolMenu)
  84. ))
  85. def OnToolMenu(self, event):
  86. """!Menu for additional tools"""
  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()
  103. class SwipeMiscToolbar(BaseToolbar):
  104. """!Toolbar with miscellaneous tools related to app
  105. """
  106. def __init__(self, parent):
  107. """!Toolbar constructor
  108. """
  109. BaseToolbar.__init__(self, parent)
  110. self.InitToolbar(self._toolbarData())
  111. # realize the toolbar
  112. self.Realize()
  113. def _toolbarData(self):
  114. """!Toolbar data"""
  115. return self._getToolbarData((("help", BaseIcons['help'],
  116. self.parent.OnHelp),
  117. ("quit", swipeIcons['quit'],
  118. self.parent.OnCloseWindow),
  119. ))