toolbars.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. """
  2. @package datacatalog.toolbars
  3. @brief Data Catalog toolbars
  4. Classes:
  5. - toolbars::DataCatalogToolbar(BaseToolbar)
  6. (C) 2016 by the GRASS Development Team
  7. This program is free software under the GNU General Public License
  8. (>=v2). Read the file COPYING that comes with GRASS for details.
  9. @author Martin Landa <landa.martin gmail.com>
  10. """
  11. import wx
  12. from gui_core.toolbars import BaseToolbar
  13. from icons.icon import MetaIcon
  14. from core.utils import _
  15. icons = {
  16. 'reloadTree': MetaIcon(
  17. img='redraw',
  18. label=_("Reload GRASS locations")),
  19. 'reloadMapset': MetaIcon(
  20. img='reload',
  21. label=_("Reload current GRASS mapset only")),
  22. 'unlocked': MetaIcon(
  23. img='unlocked',
  24. label=_("Click to restrict editing to current mapset only")),
  25. 'locked': MetaIcon(
  26. img='locked',
  27. label=_("Click to allow editing other mapsets")),
  28. }
  29. class DataCatalogToolbar(BaseToolbar):
  30. """Main data catalog toolbar
  31. """
  32. def __init__(self, parent):
  33. """Main toolbar constructor
  34. """
  35. BaseToolbar.__init__(self, parent)
  36. self.InitToolbar(self._toolbarData())
  37. # realize the toolbar
  38. self.Realize()
  39. def _toolbarData(self):
  40. """Returns toolbar data (name, icon, handler)"""
  41. # BaseIcons are a set of often used icons. It is possible
  42. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  43. return self._getToolbarData((("reloadTree", icons["reloadTree"],
  44. self.parent.OnReloadTree),
  45. ("reloadMapset", icons["reloadMapset"],
  46. self.parent.OnReloadCurrentMapset),
  47. ("lock", icons['locked'],
  48. self.OnSetRestriction, wx.ITEM_CHECK)
  49. ))
  50. def OnSetRestriction(self, event):
  51. if self.GetToolState(self.lock):
  52. self.SetToolNormalBitmap(self.lock, icons['unlocked'].GetBitmap())
  53. self.SetToolShortHelp(self.lock, icons['unlocked'].GetLabel())
  54. self.parent.SetRestriction(restrict=False)
  55. else:
  56. self.SetToolNormalBitmap(self.lock, icons['locked'].GetBitmap())
  57. self.SetToolShortHelp(self.lock, icons['locked'].GetLabel())
  58. self.parent.SetRestriction(restrict=True)