toolbars.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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(img="redraw", label=_("Reload GRASS locations")),
  17. "reloadMapset": MetaIcon(img="reload", label=_("Reload current GRASS mapset only")),
  18. "unlocked": MetaIcon(
  19. img="edit", label=_("Restrict edits to the current mapset only")
  20. ),
  21. "locked": MetaIcon(
  22. img="edit", label=_("Allow edits outside of the current mapset")
  23. ),
  24. "addGrassDB": MetaIcon(
  25. img="grassdb-add", label=_("Add existing or create new database")
  26. ),
  27. "addMapset": MetaIcon(
  28. img="mapset-add", label=_("Create new mapset in current location")
  29. ),
  30. "addLocation": MetaIcon(
  31. img="location-add", label=_("Create new location in current GRASS database")
  32. ),
  33. "downloadLocation": MetaIcon(
  34. img="location-download",
  35. label=_("Download sample location to current GRASS database"),
  36. ),
  37. "importRaster": MetaIcon(
  38. img="raster-import", label=_("Import raster data [r.import]")
  39. ),
  40. "importVector": MetaIcon(
  41. img="vector-import", label=_("Import vector data [v.import]")
  42. ),
  43. "importLayer": MetaIcon(
  44. img="layer-import", label=_("Select another import option")
  45. ),
  46. }
  47. class DataCatalogSearch(SearchCtrl):
  48. def __init__(self, parent, filter_function):
  49. super().__init__(parent)
  50. self.filter_function = filter_function
  51. self.filter_element = None
  52. self.SetDescriptiveText(_("Search"))
  53. self.ShowCancelButton(True)
  54. self.Bind(
  55. wx.EVT_TEXT,
  56. lambda event: self.filter_function(self.GetValue(), self.filter_element),
  57. )
  58. self.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, lambda evt: self.filter_function(""))
  59. filterMenu = wx.Menu()
  60. item = filterMenu.AppendRadioItem(-1, "All")
  61. self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
  62. item = filterMenu.AppendRadioItem(-1, "Raster maps")
  63. self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
  64. item = filterMenu.AppendRadioItem(-1, "Vector maps")
  65. self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
  66. item = filterMenu.AppendRadioItem(-1, "3D raster maps")
  67. self.Bind(wx.EVT_MENU, self.OnFilterMenu, item)
  68. self.SetMenu(filterMenu)
  69. helpTip = _(
  70. "Type to search database by map type or name. "
  71. "Use Python regular expressions to refine your search."
  72. )
  73. self.SetToolTip(helpTip)
  74. def OnFilterMenu(self, event):
  75. """Decide the element to filter by"""
  76. filterMenu = self.GetMenu().GetMenuItems()
  77. self.filter_element = None
  78. if filterMenu[1].IsChecked():
  79. self.filter_element = "raster"
  80. elif filterMenu[2].IsChecked():
  81. self.filter_element = "vector"
  82. elif filterMenu[3].IsChecked():
  83. self.filter_element = "raster_3d"
  84. # trigger filter on change
  85. if self.GetValue():
  86. self.filter_function(self.GetValue(), self.filter_element)
  87. class DataCatalogToolbar(BaseToolbar):
  88. """Main data catalog toolbar"""
  89. def __init__(self, parent):
  90. """Main toolbar constructor"""
  91. BaseToolbar.__init__(self, parent)
  92. self.InitToolbar(self._toolbarData())
  93. # realize the toolbar
  94. self.Realize()
  95. def _toolbarData(self):
  96. """Returns toolbar data (name, icon, handler)"""
  97. # BaseIcons are a set of often used icons. It is possible
  98. # to reuse icons in ./trunk/gui/icons/grass or add new ones there.
  99. return self._getToolbarData(
  100. (
  101. (
  102. ("reloadTree", icons["reloadTree"].label),
  103. icons["reloadTree"],
  104. self.parent.OnReloadTree,
  105. ),
  106. (
  107. ("reloadMapset", icons["reloadMapset"].label),
  108. icons["reloadMapset"],
  109. self.parent.OnReloadCurrentMapset,
  110. ),
  111. (
  112. ("lock", icons["locked"].label),
  113. icons["locked"],
  114. self.OnSetRestriction,
  115. wx.ITEM_CHECK,
  116. ),
  117. (
  118. ("addGrassDB", icons["addGrassDB"].label),
  119. icons["addGrassDB"],
  120. self.parent.OnAddGrassDB,
  121. ),
  122. (
  123. ("addLocation", icons["addLocation"].label),
  124. icons["addLocation"],
  125. self.parent.OnCreateLocation,
  126. ),
  127. (
  128. ("downloadLocation", icons["downloadLocation"].label),
  129. icons["downloadLocation"],
  130. self.parent.OnDownloadLocation,
  131. ),
  132. (
  133. ("addMapset", icons["addMapset"].label),
  134. icons["addMapset"],
  135. self.parent.OnCreateMapset,
  136. ),
  137. (
  138. ("importRaster", icons["importRaster"].label),
  139. icons["importRaster"],
  140. self.parent.OnImportGdalLayers,
  141. ),
  142. (
  143. ("importVector", icons["importVector"].label),
  144. icons["importVector"],
  145. self.parent.OnImportOgrLayers,
  146. ),
  147. (
  148. ("importLayer", icons["importLayer"].label),
  149. icons["importLayer"],
  150. self.parent.OnImportMenu,
  151. ),
  152. )
  153. )
  154. def OnSetRestriction(self, event):
  155. if self.GetToolState(self.lock):
  156. self.SetToolNormalBitmap(self.lock, icons["unlocked"].GetBitmap())
  157. self.SetToolShortHelp(self.lock, icons["unlocked"].GetLabel())
  158. self.parent.SetRestriction(restrict=False)
  159. else:
  160. self.SetToolNormalBitmap(self.lock, icons["locked"].GetBitmap())
  161. self.SetToolShortHelp(self.lock, icons["locked"].GetLabel())
  162. self.parent.SetRestriction(restrict=True)