toolbars.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 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. 'importRaster': MetaIcon(
  41. img='raster-import',
  42. label=_("Import raster data [r.import]")),
  43. 'importVector': MetaIcon(
  44. img='vector-import',
  45. label=_("Import vector data [v.import]")),
  46. 'importLayer': MetaIcon(
  47. img='layer-import',
  48. label=_("Select another import option"))
  49. }
  50. class DataCatalogToolbar(BaseToolbar):
  51. """Main data catalog toolbar
  52. """
  53. def __init__(self, parent):
  54. """Main toolbar constructor
  55. """
  56. BaseToolbar.__init__(self, parent)
  57. self.InitToolbar(self._toolbarData())
  58. self.filter_element = None
  59. self.filter = SearchCtrl(parent=self)
  60. self.filter.SetDescriptiveText(_('Search'))
  61. self.filter.ShowCancelButton(True)
  62. self.filter.SetSize((150, self.filter.GetBestSize()[1]))
  63. self.filter.Bind(wx.EVT_TEXT,
  64. lambda event: self.parent.Filter(
  65. self.filter.GetValue(), self.filter_element))
  66. self.filter.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN,
  67. lambda evt: self.parent.Filter(''))
  68. self.AddControl(self.filter)
  69. filterMenu = wx.Menu()
  70. item = filterMenu.AppendRadioItem(-1, "All")
  71. self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
  72. item = filterMenu.AppendRadioItem(-1, "Raster maps")
  73. self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
  74. item = filterMenu.AppendRadioItem(-1, "Vector maps")
  75. self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
  76. item = filterMenu.AppendRadioItem(-1, "3D raster maps")
  77. self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
  78. self.filter.SetMenu(filterMenu)
  79. help = _("Type to search database by map type or name. "
  80. "Use Python regular expressions to refine your search.")
  81. self.SetToolShortHelp(self.filter.GetId(), help)
  82. # realize the toolbar
  83. self.Realize()
  84. def _toolbarData(self):
  85. """Returns toolbar data (name, icon, handler)"""
  86. # BaseIcons are a set of often used icons. It is possible
  87. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  88. return self._getToolbarData((("reloadTree", icons["reloadTree"],
  89. self.parent.OnReloadTree),
  90. ("reloadMapset", icons["reloadMapset"],
  91. self.parent.OnReloadCurrentMapset),
  92. ("lock", icons['locked'],
  93. self.OnSetRestriction, wx.ITEM_CHECK),
  94. ("addGrassDB", icons['addGrassDB'],
  95. self.parent.OnAddGrassDB),
  96. ("addLocation", icons['addLocation'],
  97. self.parent.OnCreateLocation),
  98. ("downloadLocation", icons['downloadLocation'],
  99. self.parent.OnDownloadLocation),
  100. ("addMapset", icons['addMapset'],
  101. self.parent.OnCreateMapset),
  102. ("importRaster", icons['importRaster'],
  103. self.parent.OnImportGdalLayers),
  104. ("importVector", icons['importVector'],
  105. self.parent.OnImportOgrLayers),
  106. ("importLayer", icons['importLayer'],
  107. self.parent.OnImportMenu)))
  108. def OnFilterMenu(self, event):
  109. """Decide the element to filter by"""
  110. filterMenu = self.filter.GetMenu().GetMenuItems()
  111. self.filter_element = None
  112. if filterMenu[1].IsChecked():
  113. self.filter_element = 'raster'
  114. elif filterMenu[2].IsChecked():
  115. self.filter_element = 'vector'
  116. elif filterMenu[3].IsChecked():
  117. self.filter_element = 'raster_3d'
  118. # trigger filter on change
  119. if self.filter.GetValue():
  120. self.parent.Filter(self.filter.GetValue(), self.filter_element)
  121. def OnSetRestriction(self, event):
  122. if self.GetToolState(self.lock):
  123. self.SetToolNormalBitmap(self.lock, icons['unlocked'].GetBitmap())
  124. self.SetToolShortHelp(self.lock, icons['unlocked'].GetLabel())
  125. self.parent.SetRestriction(restrict=False)
  126. else:
  127. self.SetToolNormalBitmap(self.lock, icons['locked'].GetBitmap())
  128. self.SetToolShortHelp(self.lock, icons['locked'].GetLabel())
  129. self.parent.SetRestriction(restrict=True)