toolbars.py 5.2 KB

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