g.gui.mapswipe.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/env python3
  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: Interactively compares two maps by swiping a visibility bar.
  23. #% keyword: general
  24. #% keyword: GUI
  25. #% keyword: 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 grass.script as gscript
  47. def main():
  48. options, flags = gscript.parser()
  49. import wx
  50. from grass.script.setup import set_gui_path
  51. set_gui_path()
  52. from core.settings import UserSettings
  53. from core.giface import StandaloneGrassInterface
  54. from mapswipe.frame import SwipeMapFrame
  55. driver = UserSettings.Get(group='display', key='driver', subkey='type')
  56. if driver == 'png':
  57. os.environ['GRASS_RENDER_IMMEDIATE'] = 'png'
  58. else:
  59. os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
  60. first = options['first']
  61. second = options['second']
  62. mode = options['mode']
  63. for mapName in [first, second]:
  64. if mapName:
  65. gfile = gscript.find_file(name=mapName)
  66. if not gfile['name']:
  67. gscript.fatal(_("Raster map <%s> not found") % mapName)
  68. app = wx.App()
  69. frame = SwipeMapFrame(parent=None, giface=StandaloneGrassInterface())
  70. if first:
  71. frame.SetFirstRaster(first)
  72. if second:
  73. frame.SetSecondRaster(second)
  74. if first or second:
  75. frame.SetRasterNames()
  76. frame.SetViewMode(mode)
  77. frame.Show()
  78. app.MainLoop()
  79. if __name__ == '__main__':
  80. main()