toolbars.py 4.0 KB

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