toolbars.py 5.6 KB

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