GRASS Programmer's Manual
6.5.svn(2014)-r66266
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
mapdisp/main.py
Go to the documentation of this file.
1
"""!
2
@package mapdisp.main
3
4
@brief Start Map Display as standalone application
5
6
Classes:
7
- mapdisp::MapApp
8
9
Usage:
10
python mapdisp/main.py monitor-identifier /path/to/map/file /path/to/command/file /path/to/env/file
11
12
(C) 2006-2014 by the GRASS Development Team
13
14
This program is free software under the GNU General Public License
15
(>=v2). Read the file COPYING that comes with GRASS for details.
16
17
@author Michael Barton
18
@author Jachym Cepicky
19
@author Martin Landa <landa.martin gmail.com>
20
@author Vaclav Petras <wenzeslaus gmail.com> (MapFrameBase)
21
@author Anna Kratochvilova <kratochanna gmail.com> (MapFrameBase)
22
"""
23
24
import
os
25
import
sys
26
27
if
__name__ ==
"__main__"
:
28
sys.path.append(os.path.join(os.getenv(
'GISBASE'
),
'etc'
,
'gui'
,
'wxpython'
))
29
from
core
import
globalvar
30
import
wx
31
32
from
core.gcmd
import
RunCommand
33
from
core.render
import
Map
34
from
mapdisp.frame
import
MapFrame
35
from
grass.script
import
core
as
grass
36
37
# for standalone app
38
monFile = {
'cmd'
:
None
,
39
'map'
:
None
,
40
'env'
:
None
,
41
}
42
monName =
None
43
monSize = list(globalvar.MAP_WINDOW_SIZE)
44
45
46
class
MapApp
(wx.App):
47
def
OnInit
(self):
48
if
not
globalvar.CheckWxVersion
([2, 9]):
49
wx.InitAllImageHandlers()
50
if
__name__ ==
"__main__"
:
51
self.
cmdTimeStamp
= os.path.getmtime(monFile[
'cmd'
])
52
self.
Map
=
Map
(cmdfile = monFile[
'cmd'
], mapfile = monFile[
'map'
],
53
envfile = monFile[
'env'
], monitor = monName)
54
else
:
55
self.
Map
=
None
56
57
self.
mapFrm
= MapFrame(parent =
None
, id = wx.ID_ANY, Map = self.
Map
,
58
size = monSize)
59
# self.SetTopWindow(Map)
60
self.mapFrm.Show()
61
62
if
__name__ ==
"__main__"
:
63
self.
timer
= wx.PyTimer(self.
watcher
)
64
#check each 0.5s
65
global
mtime
66
mtime = 500
67
self.timer.Start(mtime)
68
69
return
True
70
71
def
OnExit
(self):
72
if
__name__ ==
"__main__"
:
73
# stop the timer
74
# self.timer.Stop()
75
# terminate thread
76
for
f
in
monFile.itervalues():
77
grass.try_remove(f)
78
79
def
watcher
(self):
80
"""!Redraw, if new layer appears (check's timestamp of
81
cmdfile)
82
"""
83
# todo: events
84
if
os.path.getmtime(monFile[
'cmd'
]) > self.
cmdTimeStamp
:
85
self.timer.Stop()
86
self.
cmdTimeStamp
= os.path.getmtime(monFile[
'cmd'
])
87
self.mapFrm.OnDraw(
None
)
88
self.mapFrm.GetMap().GetLayersFromCmdFile()
89
self.timer.Start(mtime)
90
91
if
__name__ ==
"__main__"
:
92
# set command variable
93
if
len(sys.argv) < 5:
94
print
__doc__
95
sys.exit(1)
96
97
monName = sys.argv[1]
98
monFile = {
'map'
: sys.argv[2],
99
'cmd'
: sys.argv[3],
100
'env'
: sys.argv[4],
101
}
102
if
len(sys.argv) >= 6:
103
try
:
104
monSize[0] = int(sys.argv[5])
105
except
ValueError:
106
pass
107
108
if
len(sys.argv) == 7:
109
try
:
110
monSize[1] = int(sys.argv[6])
111
except
ValueError:
112
pass
113
114
import
gettext
115
gettext.install(
'grasswxpy'
, os.path.join(os.getenv(
"GISBASE"
),
'locale'
), unicode =
True
)
116
117
grass.verbose(_(
"Starting map display <%s>..."
) % (monName))
118
119
RunCommand
(
'g.gisenv'
,
120
set =
'MONITOR_%s_PID=%d'
% (monName, os.getpid()))
121
122
gmMap =
MapApp
(0)
123
# set title
124
gmMap.mapFrm.SetTitle(_(
"GRASS GIS %(version)s Map Display: %(name)s - Location: %(location)s"
) % \
125
{
'version'
: grass.version()[
'version'
],
126
'name'
: monName,
127
'location'
: grass.gisenv()[
"LOCATION_NAME"
] })
128
129
gmMap.MainLoop()
130
131
grass.verbose(_(
"Stopping map display <%s>..."
) % (monName))
132
133
# clean up GRASS env variables
134
env = grass.gisenv()
135
env_name =
'MONITOR_%s'
% monName
136
for
key
in
env.keys():
137
if
key.find(env_name) == 0:
138
RunCommand
(
'g.gisenv'
,
139
set =
'%s='
% key)
140
if
key ==
'MONITOR'
and
env[key] == monName:
141
RunCommand
(
'g.gisenv'
,
142
set =
'%s='
% key)
143
144
sys.exit(0)
grass.script
main.MapApp.timer
timer
Definition:
mapdisp/main.py:63
core.gcmd
wxGUI command interface
globalvar.CheckWxVersion
def CheckWxVersion
Check wx version.
Definition:
globalvar.py:36
main.MapApp.watcher
def watcher
Redraw, if new layer appears (check's timestamp of cmdfile)
Definition:
mapdisp/main.py:79
main.MapApp.cmdTimeStamp
cmdTimeStamp
Definition:
mapdisp/main.py:51
mapdisp.frame
Map display with toolbar for various display management functions, and additional toolbars (vector di...
main.MapApp.OnExit
def OnExit
Definition:
mapdisp/main.py:71
main.MapApp.Map
Map
Definition:
mapdisp/main.py:52
main.MapApp
Definition:
mapdisp/main.py:46
main.MapApp.mapFrm
mapFrm
Definition:
mapdisp/main.py:57
core.render
Rendering map layers and overlays into map composition image.
main.MapApp.OnInit
def OnInit
Definition:
mapdisp/main.py:47
gcmd.RunCommand
def RunCommand
Run GRASS command.
Definition:
gcmd.py:625
gui
wxpython
mapdisp
main.py
Generated on Sat Jan 2 2016 01:46:48 for GRASS Programmer's Manual by
1.8.5