1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#!/usr/bin/env python3
############################################################################
#
# MODULE: g.gui.iclass
# AUTHOR(S): Anna Petrasova
# PURPOSE: Example GUI application
# COPYRIGHT: (C) 2012-2014 by the GRASS Development Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
############################################################################
# %module
# % description: Example GUI app which displays raster map and further information
# % keyword: example
# % keyword: GUI
# % keyword: raster
# %end
# %option G_OPT_R_INPUT
# % description: Name of raster map to load
# % required: no
# %end
import os
import sys
# i18n is taken care of in the grass library code.
# So we need to import it before any of the GUI code.
import grass.script.core as gcore
if __name__ == "__main__":
wxbase = os.path.join(os.getenv("GISBASE"), "etc", "gui", "wxpython")
if wxbase not in sys.path:
sys.path.append(wxbase)
def main():
options, flags = gcore.parser()
import wx
from grass.script.setup import set_gui_path
set_gui_path()
from core.globalvar import CheckWxVersion, MAP_WINDOW_SIZE
from core.giface import StandaloneGrassInterface
from core.settings import UserSettings
from example.frame import ExampleMapDisplay
if options["input"]:
map_name = gcore.find_file(name=options["input"], element="cell")["fullname"]
if not map_name:
gcore.fatal(
_("Raster map <{raster}> not found").format(raster=options["input"])
)
# define display driver (avoid 'no graphics device selected' error at start up)
driver = UserSettings.Get(group="display", key="driver", subkey="type")
if driver == "png":
os.environ["GRASS_RENDER_IMMEDIATE"] = "png"
else:
os.environ["GRASS_RENDER_IMMEDIATE"] = "cairo"
# launch application
app = wx.App()
if not CheckWxVersion([2, 9]):
wx.InitAllImageHandlers()
# show main frame
frame = wx.Frame(
parent=None, size=MAP_WINDOW_SIZE, title=_("Example Tool - GRASSGIS")
)
frame = ExampleMapDisplay(
parent=frame,
giface=StandaloneGrassInterface(),
)
if options["input"]:
frame.giface.WriteLog(
_("Loading raster map <{raster}>...").format(raster=map_name)
)
frame.SetLayer(map_name)
frame.Show()
app.MainLoop()
if __name__ == "__main__":
main()
|