GRASS Programmer's Manual
6.4.3(2013)-r
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
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-2011 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
wx.InitAllImageHandlers()
49
if
__name__ ==
"__main__"
:
50
self.
cmdTimeStamp
= os.path.getmtime(monFile[
'cmd'
])
51
self.
Map
=
Map
(cmdfile = monFile[
'cmd'
], mapfile = monFile[
'map'
],
52
envfile = monFile[
'env'
], monitor = monName)
53
else
:
54
self.
Map
=
None
55
56
self.
mapFrm
= MapFrame(parent =
None
, id = wx.ID_ANY, Map = self.
Map
,
57
size = monSize)
58
# self.SetTopWindow(Map)
59
self.mapFrm.Show()
60
61
if
__name__ ==
"__main__"
:
62
self.
timer
= wx.PyTimer(self.
watcher
)
63
#check each 0.5s
64
global
mtime
65
mtime = 500
66
self.timer.Start(mtime)
67
68
return
True
69
70
def
OnExit
(self):
71
if
__name__ ==
"__main__"
:
72
# stop the timer
73
# self.timer.Stop()
74
# terminate thread
75
for
f
in
monFile.itervalues():
76
grass.try_remove(f)
77
78
def
watcher
(self):
79
"""!Redraw, if new layer appears (check's timestamp of
80
cmdfile)
81
"""
82
# todo: events
83
if
os.path.getmtime(monFile[
'cmd'
]) > self.
cmdTimeStamp
:
84
self.timer.Stop()
85
self.
cmdTimeStamp
= os.path.getmtime(monFile[
'cmd'
])
86
self.mapFrm.OnDraw(
None
)
87
self.mapFrm.GetMap().GetLayersFromCmdFile()
88
self.timer.Start(mtime)
89
90
if
__name__ ==
"__main__"
:
91
# set command variable
92
if
len(sys.argv) < 5:
93
print
__doc__
94
sys.exit(1)
95
96
monName = sys.argv[1]
97
monFile = {
'map'
: sys.argv[2],
98
'cmd'
: sys.argv[3],
99
'env'
: sys.argv[4],
100
}
101
if
len(sys.argv) >= 6:
102
try
:
103
monSize[0] =
int
(sys.argv[5])
104
except
ValueError:
105
pass
106
107
if
len(sys.argv) == 7:
108
try
:
109
monSize[1] =
int
(sys.argv[6])
110
except
ValueError:
111
pass
112
113
import
gettext
114
gettext.install(
'grasswxpy'
, os.path.join(os.getenv(
"GISBASE"
),
'locale'
), unicode =
True
)
115
116
grass.verbose(_(
"Starting map display <%s>..."
) % (monName))
117
118
RunCommand
(
'g.gisenv'
,
119
set =
'MONITOR_%s_PID=%d'
% (monName, os.getpid()))
120
121
gmMap =
MapApp
(0)
122
# set title
123
gmMap.mapFrm.SetTitle(_(
"GRASS GIS Map Display: "
+
124
monName +
125
" - Location: "
+ grass.gisenv()[
"LOCATION_NAME"
]))
126
127
gmMap.MainLoop()
128
129
grass.verbose(_(
"Stopping map display <%s>..."
) % (monName))
130
131
# clean up GRASS env variables
132
env = grass.gisenv()
133
env_name =
'MONITOR_%s'
% monName
134
for
key
in
env.keys():
135
if
key.find(env_name) == 0:
136
RunCommand
(
'g.gisenv'
,
137
set =
'%s='
% key)
138
if
key ==
'MONITOR'
and
env[key] == monName:
139
RunCommand
(
'g.gisenv'
,
140
set =
'%s='
% key)
141
142
sys.exit(0)
grass.script
main.MapApp.timer
timer
Definition:
mapdisp/main.py:62
core.gcmd
wxGUI command interface
main.MapApp.watcher
def watcher
Redraw, if new layer appears (check's timestamp of cmdfile)
Definition:
mapdisp/main.py:78
int
int
Definition:
y.tab.c:1344
main.MapApp.cmdTimeStamp
cmdTimeStamp
Definition:
mapdisp/main.py:50
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:70
main.MapApp.Map
Map
Definition:
mapdisp/main.py:51
main.MapApp
Definition:
mapdisp/main.py:46
main.MapApp.mapFrm
mapFrm
Definition:
mapdisp/main.py:56
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:633
gui
wxpython
mapdisp
main.py
Generated on Mon Dec 16 2013 12:20:01 for GRASS Programmer's Manual by
1.8.5