toolbars.py 3.5 KB

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