toolbars.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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, SearchCtrl
  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 existing or create new 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_element = None
  50. self.filter = SearchCtrl(parent=self)
  51. self.filter.SetDescriptiveText(_('Search'))
  52. self.filter.ShowCancelButton(True)
  53. self.filter.SetSize((150, self.filter.GetBestSize()[1]))
  54. self.filter.Bind(wx.EVT_TEXT,
  55. lambda event: self.parent.Filter(
  56. self.filter.GetValue(), self.filter_element))
  57. self.filter.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN,
  58. lambda evt: self.parent.Filter(''))
  59. self.AddControl(self.filter)
  60. filterMenu = wx.Menu()
  61. item = filterMenu.AppendRadioItem(-1, "All")
  62. self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
  63. item = filterMenu.AppendRadioItem(-1, "Raster maps")
  64. self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
  65. item = filterMenu.AppendRadioItem(-1, "Vector maps")
  66. self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
  67. item = filterMenu.AppendRadioItem(-1, "3D raster maps")
  68. self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
  69. self.filter.SetMenu(filterMenu)
  70. help = _("Type to search database by map type or name. "
  71. "Use Python regular expressions to refine your search.")
  72. self.SetToolShortHelp(self.filter.GetId(), help)
  73. # realize the toolbar
  74. self.Realize()
  75. def _toolbarData(self):
  76. """Returns toolbar data (name, icon, handler)"""
  77. # BaseIcons are a set of often used icons. It is possible
  78. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  79. return self._getToolbarData((("reloadTree", icons["reloadTree"],
  80. self.parent.OnReloadTree),
  81. ("reloadMapset", icons["reloadMapset"],
  82. self.parent.OnReloadCurrentMapset),
  83. ("lock", icons['locked'],
  84. self.OnSetRestriction, wx.ITEM_CHECK),
  85. ("addGrassDB", icons['addGrassDB'],
  86. self.parent.OnAddGrassDB),
  87. ("addLocation", icons['addLocation'],
  88. self.parent.OnCreateLocation),
  89. ("downloadLocation", icons['downloadLocation'],
  90. self.parent.OnDownloadLocation),
  91. ("addMapset", icons['addMapset'],
  92. self.parent.OnCreateMapset)
  93. ))
  94. def OnFilterMenu(self, event):
  95. """Decide the element to filter by"""
  96. filterMenu = self.filter.GetMenu().GetMenuItems()
  97. self.filter_element = None
  98. if filterMenu[1].IsChecked():
  99. self.filter_element = 'raster'
  100. elif filterMenu[2].IsChecked():
  101. self.filter_element = 'vector'
  102. elif filterMenu[3].IsChecked():
  103. self.filter_element = 'raster_3d'
  104. # trigger filter on change
  105. if self.filter.GetValue():
  106. self.parent.Filter(self.filter.GetValue(), self.filter_element)
  107. def OnSetRestriction(self, event):
  108. if self.GetToolState(self.lock):
  109. self.SetToolNormalBitmap(self.lock, icons['unlocked'].GetBitmap())
  110. self.SetToolShortHelp(self.lock, icons['unlocked'].GetLabel())
  111. self.parent.SetRestriction(restrict=False)
  112. else:
  113. self.SetToolNormalBitmap(self.lock, icons['locked'].GetBitmap())
  114. self.SetToolShortHelp(self.lock, icons['locked'].GetLabel())
  115. self.parent.SetRestriction(restrict=True)