infomanager.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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). Consider creating a new Location with a CRS "
  34. "specific to your area. You can do it now or anytime later from "
  35. "the toolbar above."
  36. ).format(loc=gisenv()["LOCATION_NAME"])
  37. self.infoBar.ShowMessage(message, wx.ICON_INFORMATION, buttons)
  38. def ShowImportDataInfo(self, OnImportOgrLayersHandler, OnImportGdalLayersHandler):
  39. """Show info about the data import focused on the first-time user"""
  40. buttons = [
  41. (_("Import vector data"), OnImportOgrLayersHandler),
  42. (_("Import raster data"), OnImportGdalLayersHandler),
  43. ]
  44. message = _(
  45. "You have successfully created a new Location {loc}. "
  46. "Currently you are in its PERMANENT Mapset which is used for "
  47. "storing your base maps to make them readily available in other "
  48. "Mapsets. You can create new Mapsets for different tasks by right "
  49. "clicking on the Location name.\n\n"
  50. "To import data, go to the toolbar above or use the buttons below."
  51. ).format(loc=gisenv()["LOCATION_NAME"])
  52. self.infoBar.ShowMessage(message, wx.ICON_INFORMATION, buttons)
  53. def ShowFallbackSessionInfo(self, reason_id):
  54. """Show info when last used mapset is not usable"""
  55. string = self._text_from_reason_id(reason_id)
  56. message = _(
  57. "{string} GRASS GIS has started in a temporary Location. "
  58. "To continue, use Data Catalog below to switch to a different Location."
  59. ).format(
  60. string=string,
  61. )
  62. self.infoBar.ShowMessage(message, wx.ICON_INFORMATION)
  63. def ShowLockedMapsetInfo(self, OnSwitchMapsetHandler):
  64. """Show info when last used mapset is locked"""
  65. last_used_mapset_path = gisenv()["LAST_MAPSET_PATH"]
  66. buttons = [(_("Switch to last used mapset"), OnSwitchMapsetHandler)]
  67. message = _(
  68. "Last used mapset in path '{mapsetpath}' is currently in use. "
  69. "GRASS GIS has started in a temporary Location. "
  70. "To continue, use Data Catalog below to switch to a different Location "
  71. "or remove lock file and switch to the last used mapset."
  72. ).format(mapsetpath=last_used_mapset_path)
  73. self.infoBar.ShowMessage(message, wx.ICON_INFORMATION, buttons)
  74. def _text_from_reason_id(self, reason_id):
  75. """ Get string for infobar message based on the reason."""
  76. last_used_mapset_path = gisenv()["LAST_MAPSET_PATH"]
  77. reason = None
  78. if reason_id == "non-existent":
  79. reason = _(
  80. "Last used mapset in path '{mapsetpath}' does not exist."
  81. ).format(mapsetpath=last_used_mapset_path)
  82. elif reason_id == "invalid":
  83. reason = _("Last used mapset in path '{mapsetpath}' is invalid.").format(
  84. mapsetpath=last_used_mapset_path
  85. )
  86. elif reason_id == "different-owner":
  87. owner = get_mapset_owner(last_used_mapset_path)
  88. reason = _(
  89. "Last used mapset in path '{mapsetpath}' has different owner {owner}."
  90. ).format(owner=owner, mapsetpath=last_used_mapset_path)
  91. return reason
  92. def _onLearnMore(self, event):
  93. self._giface.Help(entry="grass_database")