Skip to content

Commit

Permalink
Do not touch a map file for non-rendering modules; also delete it if …
Browse files Browse the repository at this point in the history
…created by display driver; they are all blank
  • Loading branch information
HuidaeCho committed Mar 15, 2024
1 parent 915659f commit b8b7f21
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions display/d.mon/render_cmd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
import os
import sys
import glob
import tempfile
from pathlib import Path

Expand All @@ -23,6 +24,19 @@
)


# remove empty mapfile from non-rendering modules
def remove_mapfile(mapfile):
# adopted from Map.DeleteLayer() in gui/wxpython/core/render.py
base = os.path.split(mapfile)[0]
mapfile = os.path.split(mapfile)[1]
tempbase = mapfile.split(".")[0]
if base == "" or tempbase == "":
return
basefile = os.path.join(base, tempbase) + r".*"
for f in glob.glob(basefile):
os.remove(f)


# read environment variables from file
def read_env_file(env_file):
width = height = legfile = None
Expand Down Expand Up @@ -57,6 +71,11 @@ def render(cmd, mapfile):
env["GRASS_RENDER_FILE"] = mapfile
try:
grass.run_command(cmd[0], env=env, **cmd[1])
# display driver can generate a blank map file unnecessarily for
# non-rendering modules; delete it
if cmd[0] in non_rendering_modules and os.path.exists(mapfile):
remove_mapfile(mapfile)

except CalledModuleError as e:
grass.debug("Unable to render: {0}".format(e), 1)

Expand Down Expand Up @@ -159,8 +178,10 @@ def read_stdin(cmd):
mapfile += ".png"
else:
mapfile += ".ppm"
# to force rendering by wx monitors
Path(mapfile).touch()
# to force rendering by wx monitors, but don't create a map file for
# non-rendering modules
if cmd[0] not in ("d.redraw",) + non_rendering_modules:
Path(mapfile).touch()
else:
mapfile = None
adjust_region(width, height)
Expand Down

0 comments on commit b8b7f21

Please sign in to comment.