toolbars.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. ("displaymap", icons["display"], self.parent.OnDraw),
  36. ("rendermap", icons["render"], self.parent.OnRender),
  37. ("erase", icons["erase"], self.parent.OnErase),
  38. (None,), # creates separator
  39. ("pan", icons["pan"], self.parent.OnPan, wx.ITEM_CHECK), # toggle tool
  40. ("zoomIn", icons["zoomIn"], self.parent.OnZoomIn, wx.ITEM_CHECK),
  41. ("zoomOut", icons["zoomOut"], self.parent.OnZoomOut, wx.ITEM_CHECK),
  42. (None,),
  43. ("zoomBack", icons["zoomBack"], self.parent.OnZoomBack),
  44. ("zoomToMap", icons["zoomExtent"], self.parent.OnZoomToMap),
  45. )
  46. )
  47. class ExampleMainToolbar(BaseToolbar):
  48. """!Toolbar with tools related to application functionality"""
  49. def __init__(self, parent):
  50. """!Toolbar constructor"""
  51. BaseToolbar.__init__(self, parent)
  52. self.InitToolbar(self._toolbarData())
  53. # realize the toolbar
  54. self.Realize()
  55. def _toolbarData(self):
  56. """!Toolbar data"""
  57. return self._getToolbarData(
  58. (("addRaster", BaseIcons["addRast"], self.parent.OnSelectRaster),)
  59. )
  60. class ExampleMiscToolbar(BaseToolbar):
  61. """!Toolbar with miscellaneous tools related to app"""
  62. def __init__(self, parent):
  63. """!Toolbar constructor"""
  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. icons = BaseIcons
  71. return self._getToolbarData(
  72. (
  73. ("help", icons["help"], self.parent.OnHelp),
  74. ("quit", icons["quit"], self.parent.OnCloseWindow),
  75. )
  76. )