toolbars.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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(img='redraw', label=_("Reload GRASS locations")),
  17. 'reloadMapset': MetaIcon(img='reload', label=_("Reload current GRASS mapset only")),
  18. 'unlocked': MetaIcon(img='unlocked', label=_("Click to restrict editing to current mapset only")),
  19. 'locked': MetaIcon(img='locked', label=_("Click to allow editing other mapsets")),
  20. }
  21. class DataCatalogToolbar(BaseToolbar):
  22. """Main data catalog toolbar
  23. """
  24. def __init__(self, parent):
  25. """Main toolbar constructor
  26. """
  27. BaseToolbar.__init__(self, parent)
  28. self.InitToolbar(self._toolbarData())
  29. # realize the toolbar
  30. self.Realize()
  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. return self._getToolbarData((("reloadTree", icons["reloadTree"],
  36. self.parent.OnReloadTree),
  37. ("reloadMapset", icons["reloadMapset"],
  38. self.parent.OnReloadCurrentMapset),
  39. ("lock", icons['locked'],
  40. self.OnSetRestriction, wx.ITEM_CHECK)
  41. ))
  42. def OnSetRestriction(self, event):
  43. if self.GetToolState(self.lock):
  44. self.SetToolNormalBitmap(self.lock, icons['unlocked'].GetBitmap())
  45. self.SetToolShortHelp(self.lock, icons['unlocked'].GetLabel())
  46. self.parent.SetRestriction(restrict=False)
  47. else:
  48. self.SetToolNormalBitmap(self.lock, icons['locked'].GetBitmap())
  49. self.SetToolShortHelp(self.lock, icons['locked'].GetLabel())
  50. self.parent.SetRestriction(restrict=True)