Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui: Pyrefact gui #335

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions gui/wxpython/animation/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,9 @@ def _update(self):
if isStart:
self.animationData.startRegion = isStart
else:
if isStart:
self.animationData.startRegion = isStart
else:
if not isStart:
raise GException(_("Region information is not complete"))
self.animationData.startRegion = isStart
if isEnd:
self.animationData.endRegion = self.endRegion.GetValue()
self.animationData.zoomRegionValue = None
Expand Down
21 changes: 10 additions & 11 deletions gui/wxpython/animation/nviztask.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,15 @@ def _processVolume(self, volume, mapName):
if isosurfaces:
res_value = volume["draw"]["resolution"]["isosurface"]["value"]
self._setMultiTaskParam("volume_resolution", res_value)
attributes = ("topo", "color", "shine", "transp")

parameters = (
(None, "isosurf_level"),
("isosurf_color_map", "isosurf_color_value"),
("isosurf_shininess_map", "isosurf_shininess_value"),
("isosurf_transparency_map", "isosurf_transparency_value"),
)
for isosurface in isosurfaces:
attributes = ("topo", "color", "shine", "transp")
parameters = (
(None, "isosurf_level"),
("isosurf_color_map", "isosurf_color_value"),
("isosurf_shininess_map", "isosurf_shininess_value"),
("isosurf_transparency_map", "isosurf_transparency_value"),
)
for attr, params in zip(attributes, parameters):
mapname = None
const = None
Expand Down Expand Up @@ -299,12 +300,10 @@ def GetCommandSeries(self, layerList, paramName):

if len(layerList) > 1:
raise GException(_("Please add only one layer in the list."))
return
layer = layerList[0]
if hasattr(layer, "maps"):
series = layer.maps
else:
if not hasattr(layer, "maps"):
raise GException(_("No map series nor space-time dataset is added."))
series = layer.maps

for value in series:
self.task.set_param(paramName, value)
Expand Down
17 changes: 9 additions & 8 deletions gui/wxpython/animation/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,14 +757,15 @@ def Clear(self):
Debug.msg(4, "MapFilesPool.Clear")

for key in list(self.dictionary.keys()):
if self.referenceCount[key] <= 0:
name, ext = os.path.splitext(self.dictionary[key])
os.remove(self.dictionary[key])
if ext == ".ppm":
os.remove(name + ".pgm")
del self.dictionary[key]
del self.referenceCount[key]
del self.size[key]
if self.referenceCount[key] > 0:
continue
name, ext = os.path.splitext(self.dictionary[key])
os.remove(self.dictionary[key])
if ext == ".ppm":
os.remove(name + ".pgm")
del self.dictionary[key]
del self.referenceCount[key]
del self.size[key]


class BitmapPool(DictRefCounter):
Expand Down
45 changes: 19 additions & 26 deletions gui/wxpython/animation/temporal_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@

import datetime
from operator import itemgetter
from pathlib import Path

import grass.script as gs
import grass.temporal as tgis
from core.gcmd import GException
from core.settings import UserSettings
from animation.utils import validateTimeseriesName, TemporalType

A_TEST_WITH_INPUT_FILES = "A test with input files"


class DataMode:
SIMPLE = 1
Expand Down Expand Up @@ -411,28 +414,24 @@ def createAbsoluteInterval():
gs.mapcalc(exp="temp_6 = rand(0, 650)", overwrite=True)

n1 = gs.read_command("g.tempfile", pid=1, flags="d").strip()
fd = open(n1, "w")
fd.write(
Path(n1).write_text(
"prec_1|2001-01-01|2001-02-01\n"
"prec_2|2001-04-01|2001-05-01\n"
"prec_3|2001-05-01|2001-09-01\n"
"prec_4|2001-09-01|2002-01-01\n"
"prec_5|2002-01-01|2002-05-01\n"
"prec_6|2002-05-01|2002-07-01\n"
)
fd.close()

n2 = gs.read_command("g.tempfile", pid=2, flags="d").strip()
fd = open(n2, "w")
fd.write(
Path(n2).write_text(
"temp_1|2000-10-01|2001-01-01\n"
"temp_2|2001-04-01|2001-05-01\n"
"temp_3|2001-05-01|2001-09-01\n"
"temp_4|2001-09-01|2002-01-01\n"
"temp_5|2002-01-01|2002-05-01\n"
"temp_6|2002-05-01|2002-07-01\n"
)
fd.close()
name1 = "absinterval1"
name2 = "absinterval2"
gs.run_command(
Expand All @@ -448,8 +447,8 @@ def createAbsoluteInterval():
type="strds",
temporaltype="absolute",
output=name,
title="A test with input files",
descr="A test with input files",
title=A_TEST_WITH_INPUT_FILES,
descr=A_TEST_WITH_INPUT_FILES,
)
gs.run_command("t.register", flags="i", input=name, file=fname, overwrite=True)

Expand Down Expand Up @@ -486,28 +485,24 @@ def createRelativeInterval():
gs.mapcalc(exp="temp_6 = rand(0, 650)", overwrite=True)

n1 = gs.read_command("g.tempfile", pid=1, flags="d").strip()
fd = open(n1, "w")
fd.write(
Path(n1).write_text(
"prec_1|1|4\n"
"prec_2|6|7\n"
"prec_3|7|10\n"
"prec_4|10|11\n"
"prec_5|11|14\n"
"prec_6|14|17\n"
)
fd.close()

n2 = gs.read_command("g.tempfile", pid=2, flags="d").strip()
fd = open(n2, "w")
fd.write(
Path(n2).write_text(
"temp_1|5|6\n"
"temp_2|6|7\n"
"temp_3|7|10\n"
"temp_4|10|11\n"
"temp_5|11|18\n"
"temp_6|19|22\n"
)
fd.close()
name1 = "relinterval1"
name2 = "relinterval2"
gs.run_command(
Expand All @@ -523,8 +518,8 @@ def createRelativeInterval():
type="strds",
temporaltype="relative",
output=name,
title="A test with input files",
descr="A test with input files",
title=A_TEST_WITH_INPUT_FILES,
descr=A_TEST_WITH_INPUT_FILES,
)
gs.run_command(
"t.register",
Expand Down Expand Up @@ -560,25 +555,23 @@ def createAbsolutePoint():
gs.mapcalc(exp="prec_6 = rand(0, 650)", overwrite=True)

n1 = gs.read_command("g.tempfile", pid=1, flags="d").strip()
fd = open(n1, "w")
fd.write(
Path(n1).write_text(
"prec_1|2001-01-01\n"
"prec_2|2001-03-01\n"
"prec_3|2001-04-01\n"
"prec_4|2001-05-01\n"
"prec_5|2001-08-01\n"
"prec_6|2001-09-01\n"
)
fd.close()
name = "abspoint"
gs.run_command(
"t.create",
overwrite=True,
type="strds",
temporaltype="absolute",
output=name,
title="A test with input files",
descr="A test with input files",
title=A_TEST_WITH_INPUT_FILES,
descr=A_TEST_WITH_INPUT_FILES,
)

gs.run_command("t.register", flags="i", input=name, file=n1, overwrite=True)
Expand Down Expand Up @@ -608,18 +601,18 @@ def createRelativePoint():
gs.mapcalc(exp="prec_6 = rand(0, 650)", overwrite=True)

n1 = gs.read_command("g.tempfile", pid=1, flags="d").strip()
fd = open(n1, "w")
fd.write("prec_1|1\nprec_2|3\nprec_3|5\nprec_4|7\nprec_5|11\nprec_6|13\n")
fd.close()
Path(n1).write_text(
"prec_1|1\nprec_2|3\nprec_3|5\nprec_4|7\nprec_5|11\nprec_6|13\n"
)
name = "relpoint"
gs.run_command(
"t.create",
overwrite=True,
type="strds",
temporaltype="relative",
output=name,
title="A test with input files",
descr="A test with input files",
title=A_TEST_WITH_INPUT_FILES,
descr=A_TEST_WITH_INPUT_FILES,
)

gs.run_command("t.register", unit="day", input=name, file=n1, overwrite=True)
Expand Down
53 changes: 27 additions & 26 deletions gui/wxpython/animation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,18 @@ def validateMapNames(names, etype):
for name in names:
if name.find("@") >= 0:
nameShort, mapset = name.split("@", 1)
if nameShort in mapDict[mapset]:
newNames.append(name)
else:
raise GException(_("Map <%s> not found.") % name)
else:
found = False
for mapset, mapNames in mapDict.items():
if name in mapNames:
found = True
newNames.append(name + "@" + mapset)
if not found:
if nameShort not in mapDict[mapset]:
raise GException(_("Map <%s> not found.") % name)
newNames.append(name)

continue
found = False
for mapset, mapNames in mapDict.items():
if name in mapNames:
found = True
newNames.append(name + "@" + mapset)
if not found:
raise GException(_("Map <%s> not found.") % name)
return newNames


Expand Down Expand Up @@ -331,21 +331,22 @@ def layerListToCmdsMatrix(layerList):
continue
if hasattr(layer, "maps"):
for i, part in enumerate(layer.cmd):
if part.startswith("map="):
cmd = layer.cmd[:]
cmds = []
for map_ in layer.maps:
# check if dataset uses layers instead of maps
mapName, mapLayer = getNameAndLayer(map_)
cmd[i] = "map={name}".format(name=mapName)
if mapLayer:
try:
idx = cmd.index("layer")
cmd[idx] = "layer={layer}".format(layer=mapLayer)
except ValueError:
cmd.append("layer={layer}".format(layer=mapLayer))
cmds.append(cmd[:])
cmdsForComposition.append(cmds)
if not part.startswith("map="):
continue
cmd = layer.cmd[:]
cmds = []
for map_ in layer.maps:
# check if dataset uses layers instead of maps
mapName, mapLayer = getNameAndLayer(map_)
cmd[i] = "map={name}".format(name=mapName)
if mapLayer:
try:
idx = cmd.index("layer")
cmd[idx] = "layer={layer}".format(layer=mapLayer)
except ValueError:
cmd.append("layer={layer}".format(layer=mapLayer))
cmds.append(cmd[:])
cmdsForComposition.append(cmds)
else:
cmdsForComposition.append([layer.cmd] * count)

Expand Down
38 changes: 19 additions & 19 deletions gui/wxpython/core/gcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,25 @@ def __init__(self, args, **kwargs):
# "^" must be the first character in the list to avoid double
# escaping.
for c in ("^", "|", "&", "<", ">"):
if c in args[i]:
if "=" in args[i]:
a = args[i].split("=")
k = a[0] + "="
v = "=".join(a[1 : len(a)])
else:
k = ""
v = args[i]

# If there are spaces, the argument was already
# esscaped with double quotes, so don't escape it
# again.
if c in v and " " not in v:
# Here, we escape each ^ in ^^^ with ^^ and a
# <special character> with ^ + <special character>,
# so we need 7 carets.

v = v.replace(c, "^^^^^^^" + c)
args[i] = k + v
if c not in args[i]:
continue
if "=" in args[i]:
a = args[i].split("=")
k = a[0] + "="
v = "=".join(a[1 : len(a)])
else:
k = ""
v = args[i]

# If there are spaces, the argument was already
# escaped with double quotes, so don't escape it
# again.
if c in v and " " not in v:
# Here, we escape each ^ in ^^^ with ^^ and a
# <special character> with ^ + <special character>,
# so we need 7 carets.
v = v.replace(c, "^^^^^^^" + c)
args[i] = k + v

subprocess.Popen.__init__(self, args, **kwargs)

Expand Down
5 changes: 3 additions & 2 deletions gui/wxpython/core/layerlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def GetSelectedLayers(self, activeOnly=True):
layers = []
for layer in self._list:
if layer.IsSelected():
if activeOnly and layer.IsActive():
layers.append(layer)
if activeOnly:
if layer.IsActive():
layers.append(layer)
else:
layers.append(layer)
return layers
Expand Down
Loading
Loading