infomanager.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. """
  2. @package datacatalog.infomanager
  3. @brief Class for managing info messages
  4. in Data Catalog
  5. Classes:
  6. - infomanager::DataCatalogInfoManager
  7. (C) 2020 by the GRASS Development Team
  8. This program is free software under the GNU General Public License
  9. (>=v2). Read the file COPYING that comes with GRASS for details.
  10. @author Linda Kladivova
  11. @author Anna Petrasova <kratochanna gmail.com>
  12. @author Vaclav Petras <wenzeslaus gmail.com>
  13. """
  14. import wx
  15. from grass.script import gisenv
  16. from grass.grassdb.checks import get_mapset_owner
  17. class DataCatalogInfoManager:
  18. """Manager for all things related to info bar in Data Catalog"""
  19. def __init__(self, infobar, giface):
  20. self.infoBar = infobar
  21. self._giface = giface
  22. def ShowDataStructureInfo(self, onCreateLocationHandler):
  23. """Show info about the data hierarchy focused on the first-time user"""
  24. buttons = [
  25. (_("Create new Location"), onCreateLocationHandler),
  26. (_("Learn more"), self._onLearnMore),
  27. ]
  28. message = _(
  29. "GRASS GIS helps you organize your data using Locations (projects) "
  30. "which contain Mapsets (subprojects). All data in one Location is "
  31. "in the same coordinate reference system (CRS).\n\n"
  32. "You are currently in Mapset PERMANENT in default Location {loc} "
  33. "which uses WGS 84 (EPSG:4326). "
  34. "Consider creating a new Location with a CRS "
  35. "specific to your area. You can do it now or anytime later from "
  36. "the toolbar above."
  37. ).format(loc=gisenv()["LOCATION_NAME"])
  38. self.infoBar.ShowMessage(message, wx.ICON_INFORMATION, buttons)
  39. def ShowImportDataInfo(self, OnImportOgrLayersHandler, OnImportGdalLayersHandler):
  40. """Show info about the data import focused on the first-time user"""
  41. buttons = [
  42. (_("Import vector data"), OnImportOgrLayersHandler),
  43. (_("Import raster data"), OnImportGdalLayersHandler),
  44. ]
  45. message = _(
  46. "You have successfully created a new Location {loc}. "
  47. "Currently you are in its PERMANENT Mapset which is used for "
  48. "storing your base maps to make them readily available in other "
  49. "Mapsets. You can create new Mapsets for different tasks by right "
  50. "clicking on the Location name.\n\n"
  51. "To import data, go to the toolbar above or use the buttons below."
  52. ).format(loc=gisenv()["LOCATION_NAME"])
  53. self.infoBar.ShowMessage(message, wx.ICON_INFORMATION, buttons)
  54. def ShowLazyLoadingOn(self, setLazyLoadingOnHandler, doNotAskHandler):
  55. """Show info about lazy loading"""
  56. message = _(
  57. "Loading of Data catalog content took rather long. "
  58. "To prevent delay, you can enable loading of current mapset only. "
  59. "You can change that later in GUI Settings, General tab."
  60. )
  61. buttons = [
  62. (_("Enable loading current mapset only"), setLazyLoadingOnHandler),
  63. (_("No change, don't ask me again"), doNotAskHandler),
  64. ]
  65. self.infoBar.ShowMessage(message, wx.ICON_INFORMATION, buttons)
  66. def ShowFallbackSessionInfo(self, reason_id):
  67. """Show info when last used mapset is not usable"""
  68. string = self._text_from_reason_id(reason_id)
  69. message = _(
  70. "{string} GRASS GIS has started in a temporary Location. "
  71. "To continue, use Data Catalog below to switch to a different Location."
  72. ).format(
  73. string=string,
  74. )
  75. self.infoBar.ShowMessage(message, wx.ICON_INFORMATION)
  76. def ShowLockedMapsetInfo(self, OnSwitchMapsetHandler):
  77. """Show info when last used mapset is locked"""
  78. last_used_mapset_path = gisenv()["LAST_MAPSET_PATH"]
  79. buttons = [(_("Switch to last used mapset"), OnSwitchMapsetHandler)]
  80. message = _(
  81. "Last used mapset in path '{mapsetpath}' is currently in use. "
  82. "GRASS GIS has started in a temporary Location. "
  83. "To continue, use Data Catalog below to switch to a different Location "
  84. "or remove lock file and switch to the last used mapset."
  85. ).format(mapsetpath=last_used_mapset_path)
  86. self.infoBar.ShowMessage(message, wx.ICON_INFORMATION, buttons)
  87. def _text_from_reason_id(self, reason_id):
  88. """Get string for infobar message based on the reason."""
  89. last_used_mapset_path = gisenv()["LAST_MAPSET_PATH"]
  90. reason = None
  91. if reason_id == "non-existent":
  92. reason = _(
  93. "Last used mapset in path '{mapsetpath}' does not exist."
  94. ).format(mapsetpath=last_used_mapset_path)
  95. elif reason_id == "invalid":
  96. reason = _("Last used mapset in path '{mapsetpath}' is invalid.").format(
  97. mapsetpath=last_used_mapset_path
  98. )
  99. elif reason_id == "different-owner":
  100. owner = get_mapset_owner(last_used_mapset_path)
  101. reason = _(
  102. "Last used mapset in path '{mapsetpath}' has different owner {owner}."
  103. ).format(owner=owner, mapsetpath=last_used_mapset_path)
  104. return reason
  105. def _onLearnMore(self, event):
  106. self._giface.Help(entry="grass_database")