g.gui.mapswipe.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #%option
  35. #% key: mode
  36. #% description: View mode
  37. #% options: swipe,mirror
  38. #% descriptions:swipe;swiping the upper map layer to show the map layer below ;mirror;synchronized maps side by side
  39. #% answer: swipe
  40. #% required: no
  41. #%end
  42. import os
  43. import sys
  44. import wx
  45. import gettext
  46. import grass.script as grass
  47. if __name__ == '__main__':
  48. sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "gui", "wxpython"))
  49. from core.settings import UserSettings
  50. from core.giface import StandaloneGrassInterface
  51. from mapswipe.frame import SwipeMapFrame
  52. def main():
  53. gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
  54. driver = UserSettings.Get(group = 'display', key = 'driver', subkey = 'type')
  55. if driver == 'png':
  56. os.environ['GRASS_RENDER_IMMEDIATE'] = 'png'
  57. else:
  58. os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
  59. options, flags = grass.parser()
  60. first = options['first']
  61. second = options['second']
  62. mode = options['mode']
  63. for mapName in [first, second]:
  64. if mapName:
  65. gfile = grass.find_file(name = mapName)
  66. if not gfile['name']:
  67. grass.fatal(_("Raster map <%s> not found") % mapName)
  68. app = wx.PySimpleApp()
  69. wx.InitAllImageHandlers()
  70. frame = SwipeMapFrame(parent = None, giface = StandaloneGrassInterface())
  71. if first:
  72. frame.SetFirstRaster(first)
  73. if second:
  74. frame.SetSecondRaster(second)
  75. if first or second:
  76. frame.SetRasterNames()
  77. frame.SetViewMode(mode)
  78. frame.ZoomToMap()
  79. frame.Show()
  80. app.MainLoop()
  81. if __name__ == '__main__':
  82. main()