guiutils.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """
  2. @package startup.guiutils
  3. @brief General GUI-dependent utilities for GUI startup of GRASS GIS
  4. (C) 2018 by Vaclav Petras the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. @author Vaclav Petras <wenzeslaus gmail com>
  8. This is for code which depend on something from GUI (wx or wxGUI).
  9. """
  10. import wx
  11. import grass.script as gs
  12. from core.gcmd import RunCommand
  13. from gui_core.dialogs import TextEntryDialog
  14. from gui_core.widgets import GenericValidator
  15. def SetSessionMapset(database, location, mapset):
  16. """Sets database, location and mapset for the current session"""
  17. RunCommand("g.gisenv", set="GISDBASE=%s" % database)
  18. RunCommand("g.gisenv", set="LOCATION_NAME=%s" % location)
  19. RunCommand("g.gisenv", set="MAPSET=%s" % mapset)
  20. class NewMapsetDialog(TextEntryDialog):
  21. def __init__(self, parent=None, default=None,
  22. validation_failed_handler=None, help_hanlder=None):
  23. if help_hanlder:
  24. style = wx.OK | wx.CANCEL | wx.HELP
  25. else:
  26. style = wx.OK | wx.CANCEL
  27. if validation_failed_handler:
  28. validator=GenericValidator(
  29. gs.legal_name, validation_failed_handler)
  30. else:
  31. validator = None
  32. TextEntryDialog.__init__(
  33. self, parent=parent,
  34. message=_("Name for the new mapset:"),
  35. caption=_("Create new mapset"),
  36. defaultValue=default,
  37. validator=validator,
  38. style=style
  39. )
  40. if help_hanlder:
  41. help_button = self.FindWindowById(wx.ID_HELP)
  42. help_button.Bind(wx.EVT_BUTTON, help_hanlder)