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

wxGUI/datacalog: distinguish vector map layer type by icon #909

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added gui/icons/grass/vector_3d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/icons/grass/vector_db_disconnect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/icons/grass/vector_link_without_src.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 75 additions & 10 deletions gui/wxpython/datacatalog/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import re
import copy
from multiprocessing import Process, Queue, cpu_count
import subprocess

import wx

Expand Down Expand Up @@ -131,7 +132,46 @@ def getLocationTree(gisdbase, location, queue, mapsets=None, lazy=False):
for each in listOfMaps:
ltype, wholename = each.split("/")
name, mapset = wholename.split("@", maxsplit=1)
maps_dict[mapset].append({"name": name, "type": ltype})
if ltype == "vector":
p = gs.pipe_command(
"v.info",
flags="t",
map=wholename,
layer=1,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env,
)
stdout, stderr = p.communicate()
stdout = gs.decode(stdout)
stderr = gs.decode(stderr)

if not stderr:
map_info = dict(
[(kv.split("=")) for kv in stdout.split("\n") if kv]
)
if map_info and int(map_info["map3d"]):
maps_dict[mapset].append(
{"name": name, "type": "vector_3d"},
)
elif map_info:
maps_dict[mapset].append(
{"name": name, "type": "vector"},
)
# Vector map layer is stored in the db
elif "Connection refused" in stderr:
maps_dict[mapset].append(
{"name": name, "type": "vector_db_disconnect"},
)
# Link external vector map layer
elif "Unable to open OGR data source" in stderr:
maps_dict[mapset].append(
{"name": name, "type": "vector_link_without_src"},
)
else:
maps_dict[mapset].append({"name": name, "type": ltype})
else:
maps_dict[mapset].append({"name": name, "type": ltype})

queue.put((maps_dict, None))
gs.try_remove(tmp_gisrc_file)
Expand Down Expand Up @@ -228,6 +268,12 @@ def __init__(

self._giface = giface
self._restricted = True
self.vector = [
"vector",
"vector_3d",
"vector_db_disconnect",
"vector_link_without_src",
]

self.showNotification = Signal("Tree.showNotification")
self.showImportDataInfo = Signal("Tree.showImportDataInfo")
Expand All @@ -242,8 +288,8 @@ def __init__(
"location",
"mapset",
"raster",
"vector",
"raster_3d",
*self.vector,
]
self._initImages()
self.thread = gThread()
Expand Down Expand Up @@ -769,6 +815,13 @@ def _initImages(self):
"raster": MetaIcon(img="raster").GetBitmap(bmpsize),
"vector": MetaIcon(img="vector").GetBitmap(bmpsize),
"raster_3d": MetaIcon(img="raster3d").GetBitmap(bmpsize),
"vector_3d": MetaIcon(img="vector3d").GetBitmap(bmpsize),
"vector_db_disconnect": MetaIcon(img="vector_db_disconnect").GetBitmap(
bmpsize
),
"vector_link_without_src": MetaIcon(
img="vector_link_without_src"
).GetBitmap(bmpsize),
}
il = wx.ImageList(bmpsize[0], bmpsize[1], mask=False)
for each in self._iconTypes:
Expand All @@ -785,7 +838,7 @@ def DefineItems(self, selected):
mixed = []
for item in selected:
type = item.data["type"]
if type in {"raster", "raster_3d", "vector"}:
if type in {"raster", "raster_3d", *self.vector}:
self.selected_layer.append(item)
self.selected_mapset.append(item.parent)
self.selected_location.append(item.parent.parent)
Expand Down Expand Up @@ -1233,7 +1286,7 @@ def Rename(self, old, new):
)
label = _("Renaming map <{name}>...").format(name=string)
self.showNotification.emit(message=label)
if self.selected_layer[0].data["type"] == "vector":
if self.selected_layer[0].data["type"] in self.vector:
renamed, cmd = self._runCommand("g.rename", vector=string, env=env)
elif self.selected_layer[0].data["type"] == "raster":
renamed, cmd = self._runCommand("g.rename", raster=string, env=env)
Expand Down Expand Up @@ -1325,9 +1378,9 @@ def OnPasteMap(self, event):
else:
label = _("Moving <{name}>...").format(name=string)
self.showNotification.emit(message=label)
if self.copy_layer[i].data["type"] == "vector":
if self.copy_layer[i].data["type"] in self.vector:
pasted, cmd = self._runCommand("g.copy", vector=string, env=env)
node = "vector"
node = self.copy_layer[i].data["type"]
elif self.copy_layer[i].data["type"] == "raster":
pasted, cmd = self._runCommand("g.copy", raster=string, env=env)
node = "raster"
Expand Down Expand Up @@ -1433,7 +1486,7 @@ def _onDoneReprojection(
def _removeMapAfterCopy(self, cLayer, cMapset, env):
removed, cmd = self._runCommand(
"g.remove",
type=cLayer.data["type"],
type=self._getMapLayerType(cLayer.data["type"]),
name=cLayer.data["name"],
flags="f",
env=env,
Expand Down Expand Up @@ -1537,7 +1590,9 @@ def OnDeleteMap(self, event):
removed, cmd = self._runCommand(
"g.remove",
flags="f",
type=self.selected_layer[i].data["type"],
type=self._getMapLayerType(
self.selected_layer[i].data["type"],
),
name=self.selected_layer[i].data["name"],
env=env,
)
Expand Down Expand Up @@ -1678,7 +1733,11 @@ def DisplayLayer(self):
+ "@"
+ self.selected_mapset[i].data["name"]
)
names[self.selected_layer[i].data["type"]].append(name)
names[
self._getMapLayerType(
self.selected_layer[i].data["type"],
)
].append(name)
all_names.append(name)
# if self.selected_location[0].data['name'] == gisenv()['LOCATION_NAME'] and
# self.selected_mapset[0]:
Expand Down Expand Up @@ -1894,7 +1953,7 @@ def done(event):
for i in range(len(self.selected_layer)):
if self.selected_layer[i].data["type"] == "raster":
cmd = ["r.info"]
elif self.selected_layer[i].data["type"] == "vector":
elif self.selected_layer[i].data["type"] in self.vector:
cmd = ["v.info"]
elif self.selected_layer[i].data["type"] == "raster_3d":
cmd = ["r3.info"]
Expand Down Expand Up @@ -2268,3 +2327,9 @@ def _popupMenuEmpty(self):
item.Enable(False)
self.PopupMenu(menu)
menu.Destroy()

def _getMapLayerType(self, ltype):
"""Get map layer type"""
if ltype in self.vector:
return "vector"
return ltype
Loading