toolbars.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. self.filterId = wx.NewId()
  38. self.filter = wx.TextCtrl(parent=self, id=self.filterId)
  39. self.filter.SetSize((120, self.filter.GetBestSize()[1]))
  40. self.filter.Bind(wx.EVT_TEXT,
  41. lambda event: self.parent.Filter(
  42. self.filter.GetValue()))
  43. self.AddControl(wx.StaticText(self, label=_("Search:")))
  44. self.AddControl(self.filter)
  45. help = _("Type to search database by map type or name. "
  46. "Use prefix 'r:', 'v:' and 'r3:'"
  47. "to show only raster, vector or 3D raster data, respectively. "
  48. "Use Python regular expressions to refine your search.")
  49. self.SetToolShortHelp(self.filterId, help)
  50. # realize the toolbar
  51. self.Realize()
  52. def _toolbarData(self):
  53. """Returns toolbar data (name, icon, handler)"""
  54. # BaseIcons are a set of often used icons. It is possible
  55. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  56. return self._getToolbarData((("reloadTree", icons["reloadTree"],
  57. self.parent.OnReloadTree),
  58. ("reloadMapset", icons["reloadMapset"],
  59. self.parent.OnReloadCurrentMapset),
  60. ("lock", icons['locked'],
  61. self.OnSetRestriction, wx.ITEM_CHECK)
  62. ))
  63. def OnSetRestriction(self, event):
  64. if self.GetToolState(self.lock):
  65. self.SetToolNormalBitmap(self.lock, icons['unlocked'].GetBitmap())
  66. self.SetToolShortHelp(self.lock, icons['unlocked'].GetLabel())
  67. self.parent.SetRestriction(restrict=False)
  68. else:
  69. self.SetToolNormalBitmap(self.lock, icons['locked'].GetBitmap())
  70. self.SetToolShortHelp(self.lock, icons['locked'].GetLabel())
  71. self.parent.SetRestriction(restrict=True)