g.gui.mapswipe.py 2.9 KB

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