toolbars.py 3.0 KB

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