toolbars.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. from icons.icon import MetaIcon
  17. class ExampleMapToolbar(BaseToolbar):
  18. """!Map toolbar (to control map zoom and rendering)
  19. """
  20. def __init__(self, parent, toolSwitcher):
  21. """!Map toolbar constructor
  22. """
  23. BaseToolbar.__init__(self, parent, toolSwitcher)
  24. self.InitToolbar(self._toolbarData())
  25. # realize the toolbar
  26. self.Realize()
  27. self._default = self.pan
  28. for tool in (self.pan, self.zoomIn, self.zoomOut):
  29. self.toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self, tool=tool)
  30. self.EnableTool(self.zoomBack, False)
  31. def _toolbarData(self):
  32. """!Returns toolbar data (name, icon, handler)"""
  33. # BaseIcons are a set of often used icons. It is possible
  34. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  35. icons = BaseIcons
  36. return self._getToolbarData((("displaymap", icons["display"],
  37. self.parent.OnDraw),
  38. ("rendermap", icons["render"],
  39. self.parent.OnRender),
  40. ("erase", icons["erase"],
  41. self.parent.OnErase),
  42. (None, ), # creates separator
  43. ("pan", icons["pan"],
  44. self.parent.OnPan,
  45. wx.ITEM_CHECK), # toggle tool
  46. ("zoomIn", icons["zoomIn"],
  47. self.parent.OnZoomIn,
  48. wx.ITEM_CHECK),
  49. ("zoomOut", icons["zoomOut"],
  50. self.parent.OnZoomOut,
  51. wx.ITEM_CHECK),
  52. (None, ),
  53. ("zoomBack", icons["zoomBack"],
  54. self.parent.OnZoomBack),
  55. ("zoomToMap", icons["zoomExtent"],
  56. self.parent.OnZoomToMap),
  57. ))
  58. class ExampleMainToolbar(BaseToolbar):
  59. """!Toolbar with tools related to application functionality
  60. """
  61. def __init__(self, parent):
  62. """!Toolbar constructor
  63. """
  64. BaseToolbar.__init__(self, parent)
  65. self.InitToolbar(self._toolbarData())
  66. # realize the toolbar
  67. self.Realize()
  68. def _toolbarData(self):
  69. """!Toolbar data"""
  70. return self._getToolbarData((("addRaster", BaseIcons['addRast'],
  71. self.parent.OnSelectRaster),
  72. ))
  73. class ExampleMiscToolbar(BaseToolbar):
  74. """!Toolbar with miscellaneous tools related to app
  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. icons = BaseIcons
  86. return self._getToolbarData((("help", icons['help'],
  87. self.parent.OnHelp),
  88. ("quit", icons['quit'],
  89. self.parent.OnCloseWindow),
  90. ))