toolbars.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. """
  2. @package example.toolbars
  3. @brief Example toolbars and icons.
  4. Classes:
  5. - toolbars::ExampleMapToolbar
  6. - toolbars::ExampleMainToolbar
  7. - toolbars::ExampleMiscToolbar
  8. (C) 2011-2014 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 Petrasova <kratochanna gmail.com>
  13. """
  14. import wx
  15. from gui_core.toolbars import BaseToolbar, BaseIcons
  16. class ExampleMapToolbar(BaseToolbar):
  17. """!Map toolbar (to control map zoom and rendering)"""
  18. def __init__(self, parent, toolSwitcher):
  19. """!Map toolbar constructor"""
  20. BaseToolbar.__init__(self, parent, toolSwitcher)
  21. self.InitToolbar(self._toolbarData())
  22. # realize the toolbar
  23. self.Realize()
  24. self._default = self.pan
  25. for tool in (self.pan, self.zoomIn, self.zoomOut):
  26. self.toolSwitcher.AddToolToGroup(group="mouseUse", toolbar=self, tool=tool)
  27. self.EnableTool(self.zoomBack, False)
  28. def _toolbarData(self):
  29. """!Returns toolbar data (name, icon, handler)"""
  30. # BaseIcons are a set of often used icons. It is possible
  31. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  32. icons = BaseIcons
  33. return self._getToolbarData(
  34. (
  35. (
  36. ("displaymap", icons["display"].label),
  37. icons["display"],
  38. self.parent.OnDraw,
  39. ),
  40. (
  41. ("rendermap", icons["render"].label),
  42. icons["render"],
  43. self.parent.OnRender,
  44. ),
  45. (
  46. ("erase", icons["erase"].label),
  47. icons["erase"],
  48. self.parent.OnErase,
  49. ),
  50. (None,), # creates separator
  51. (
  52. ("pan", icons["pan"].label),
  53. icons["pan"],
  54. self.parent.OnPan,
  55. wx.ITEM_CHECK,
  56. ), # toggle tool
  57. (
  58. ("zoomIn", icons["zoomIn"].label),
  59. icons["zoomIn"],
  60. self.parent.OnZoomIn,
  61. wx.ITEM_CHECK,
  62. ),
  63. (
  64. ("zoomOut", icons["zoomOut"].label),
  65. icons["zoomOut"],
  66. self.parent.OnZoomOut,
  67. wx.ITEM_CHECK,
  68. ),
  69. (None,),
  70. (
  71. ("zoomBack", icons["zoomBack"].label),
  72. icons["zoomBack"],
  73. self.parent.OnZoomBack,
  74. ),
  75. (
  76. ("zoomToMap", icons["zoomExtent"].label),
  77. icons["zoomExtent"],
  78. self.parent.OnZoomToMap,
  79. ),
  80. )
  81. )
  82. class ExampleMainToolbar(BaseToolbar):
  83. """!Toolbar with tools related to application functionality"""
  84. def __init__(self, parent):
  85. """!Toolbar constructor"""
  86. BaseToolbar.__init__(self, parent)
  87. self.InitToolbar(self._toolbarData())
  88. # realize the toolbar
  89. self.Realize()
  90. def _toolbarData(self):
  91. """!Toolbar data"""
  92. return self._getToolbarData(
  93. (
  94. ("addRaster", BaseIcons["addRast"].label),
  95. BaseIcons["addRast"],
  96. self.parent.OnSelectRaster,
  97. ),
  98. )
  99. class ExampleMiscToolbar(BaseToolbar):
  100. """!Toolbar with miscellaneous tools related to app"""
  101. def __init__(self, parent):
  102. """!Toolbar constructor"""
  103. BaseToolbar.__init__(self, parent)
  104. self.InitToolbar(self._toolbarData())
  105. # realize the toolbar
  106. self.Realize()
  107. def _toolbarData(self):
  108. """!Toolbar data"""
  109. icons = BaseIcons
  110. return self._getToolbarData(
  111. (
  112. ("help", icons["help"].label),
  113. icons["help"],
  114. self.parent.OnHelp,
  115. ),
  116. (
  117. ("quit", icons["quit"].label),
  118. icons["quit"],
  119. self.parent.OnCloseWindow,
  120. ),
  121. )