g.gui.mapswipe.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: Map Swipe
  5. # AUTHOR(S): Anna Kratochvilova
  6. # PURPOSE: The Map Swipe is a wxGUI component which allows the user to
  7. # interactively compare two maps
  8. # COPYRIGHT: (C) 2012 by Anna Kratochvilova, and the GRASS Development Team
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. ############################################################################
  21. #%module
  22. #% description: Allows to interactively compare two maps by swiping.
  23. #%end
  24. #%option G_OPT_R_INPUT
  25. #% key: first
  26. #% description: First (top/right) raster map
  27. #% required: no
  28. #%end
  29. #%option G_OPT_R_INPUT
  30. #% key: second
  31. #% description: Second (bottom/left) raster map
  32. #% required: no
  33. #%end
  34. import os
  35. import sys
  36. import wx
  37. import gettext
  38. import grass.script as grass
  39. if __name__ == '__main__':
  40. sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "gui", "wxpython"))
  41. from core.settings import UserSettings
  42. from core.giface import StandaloneGrassInterface
  43. from mapswipe.frame import SwipeMapFrame
  44. def main():
  45. gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
  46. driver = UserSettings.Get(group = 'display', key = 'driver', subkey = 'type')
  47. if driver == 'png':
  48. os.environ['GRASS_RENDER_IMMEDIATE'] = 'png'
  49. else:
  50. os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
  51. options, flags = grass.parser()
  52. first = options['first']
  53. second = options['second']
  54. for mapName in [first, second]:
  55. if mapName:
  56. gfile = grass.find_file(name = mapName)
  57. if not gfile['name']:
  58. grass.fatal(_("Raster map <%s> not found") % mapName)
  59. app = wx.PySimpleApp()
  60. wx.InitAllImageHandlers()
  61. frame = SwipeMapFrame(parent = None, giface = StandaloneGrassInterface())
  62. if first:
  63. frame.SetFirstRaster(first)
  64. if second:
  65. frame.SetSecondRaster(second)
  66. frame.Show()
  67. app.MainLoop()
  68. if __name__ == '__main__':
  69. main()