toolbars.py 3.3 KB

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