toolbars.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. (None, ),
  62. ('saveFile', icons['saveFile'],
  63. self.parent.SaveToFile),
  64. ))
  65. def SetActiveMap(self, index):
  66. """!Set currently selected map.
  67. Unused, needed because of DoubleMapFrame API.
  68. """
  69. pass
  70. class SwipeMainToolbar(BaseToolbar):
  71. """!Toolbar with tools related to application functionality
  72. """
  73. def __init__(self, parent):
  74. """!Toolbar constructor
  75. """
  76. BaseToolbar.__init__(self, parent)
  77. self.InitToolbar(self._toolbarData())
  78. # realize the toolbar
  79. self.Realize()
  80. def _toolbarData(self):
  81. """!Toolbar data"""
  82. return self._getToolbarData((("addRaster", swipeIcons['addRast'],
  83. self.parent.OnSelectRasters),
  84. (None, ),
  85. ("tools", swipeIcons['tools'],
  86. self.OnToolMenu)
  87. ))
  88. def OnToolMenu(self, event):
  89. """!Menu for additional tools"""
  90. toolMenu = wx.Menu()
  91. for label, itype, handler, desc in (
  92. (_("Switch orientation"),
  93. wx.ITEM_NORMAL, self.parent.OnSwitchOrientation, "switchOrientation"),
  94. (_("Switch maps"),
  95. wx.ITEM_NORMAL, self.parent.OnSwitchWindows, "switchMaps")):
  96. # Add items to the menu
  97. item = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  98. text = label,
  99. kind = itype)
  100. toolMenu.AppendItem(item)
  101. self.parent.GetWindow().Bind(wx.EVT_MENU, handler, item)
  102. # Popup the menu. If an item is selected then its handler
  103. # will be called before PopupMenu returns.
  104. self.parent.GetWindow().PopupMenu(toolMenu)
  105. toolMenu.Destroy()
  106. class SwipeMiscToolbar(BaseToolbar):
  107. """!Toolbar with miscellaneous tools related to app
  108. """
  109. def __init__(self, parent):
  110. """!Toolbar constructor
  111. """
  112. BaseToolbar.__init__(self, parent)
  113. self.InitToolbar(self._toolbarData())
  114. # realize the toolbar
  115. self.Realize()
  116. def _toolbarData(self):
  117. """!Toolbar data"""
  118. return self._getToolbarData((("help", BaseIcons['help'],
  119. self.parent.OnHelp),
  120. ("quit", swipeIcons['quit'],
  121. self.parent.OnCloseWindow),
  122. ))