toolbars.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 gui_core.wrap import StaticText, TextCtrl
  14. from icons.icon import MetaIcon
  15. from core.utils import _
  16. icons = {
  17. 'reloadTree': MetaIcon(
  18. img='redraw',
  19. label=_("Reload GRASS locations")),
  20. 'reloadMapset': MetaIcon(
  21. img='reload',
  22. label=_("Reload current GRASS mapset only")),
  23. 'unlocked': MetaIcon(
  24. img='unlocked',
  25. label=_("Click to restrict editing to current mapset only")),
  26. 'locked': MetaIcon(
  27. img='locked',
  28. label=_("Click to allow editing other mapsets")),
  29. }
  30. class DataCatalogToolbar(BaseToolbar):
  31. """Main data catalog toolbar
  32. """
  33. def __init__(self, parent):
  34. """Main toolbar constructor
  35. """
  36. BaseToolbar.__init__(self, parent)
  37. self.InitToolbar(self._toolbarData())
  38. self.filterId = wx.NewId()
  39. self.filter = TextCtrl(parent=self, id=self.filterId)
  40. self.filter.SetSize((120, self.filter.GetBestSize()[1]))
  41. self.filter.Bind(wx.EVT_TEXT,
  42. lambda event: self.parent.Filter(
  43. self.filter.GetValue()))
  44. self.AddControl(StaticText(self, label=_("Search:")))
  45. self.AddControl(self.filter)
  46. help = _("Type to search database by map type or name. "
  47. "Use prefix 'r:', 'v:' and 'r3:'"
  48. "to show only raster, vector or 3D raster data, respectively. "
  49. "Use Python regular expressions to refine your search.")
  50. self.SetToolShortHelp(self.filterId, help)
  51. # realize the toolbar
  52. self.Realize()
  53. def _toolbarData(self):
  54. """Returns toolbar data (name, icon, handler)"""
  55. # BaseIcons are a set of often used icons. It is possible
  56. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  57. return self._getToolbarData((("reloadTree", icons["reloadTree"],
  58. self.parent.OnReloadTree),
  59. ("reloadMapset", icons["reloadMapset"],
  60. self.parent.OnReloadCurrentMapset),
  61. ("lock", icons['locked'],
  62. self.OnSetRestriction, wx.ITEM_CHECK)
  63. ))
  64. def OnSetRestriction(self, event):
  65. if self.GetToolState(self.lock):
  66. self.SetToolNormalBitmap(self.lock, icons['unlocked'].GetBitmap())
  67. self.SetToolShortHelp(self.lock, icons['unlocked'].GetLabel())
  68. self.parent.SetRestriction(restrict=False)
  69. else:
  70. self.SetToolNormalBitmap(self.lock, icons['locked'].GetBitmap())
  71. self.SetToolShortHelp(self.lock, icons['locked'].GetLabel())
  72. self.parent.SetRestriction(restrict=True)