From fa91463e6a1ab3ce996777e031b8b14e6f60c3c2 Mon Sep 17 00:00:00 2001 From: Anna Petrasova Date: Wed, 8 Nov 2023 13:02:14 -0500 Subject: [PATCH] wxGUI: rewrite and document core.utils.ListOfMapsets to not cause GUI crash in certain circumstances (#3226) --- gui/wxpython/core/utils.py | 45 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/gui/wxpython/core/utils.py b/gui/wxpython/core/utils.py index 1aec2ddf032..93a3248c918 100644 --- a/gui/wxpython/core/utils.py +++ b/gui/wxpython/core/utils.py @@ -279,38 +279,39 @@ def ListOfCatsToRange(cats): def ListOfMapsets(get="ordered"): - """Get list of available/accessible mapsets + """Get list of available/accessible mapsets. + Option 'ordered' returns list of all mapsets, first accessible + then not accessible. Raises ValueError for wrong paramater value. :param str get: method ('all', 'accessible', 'ordered') :return: list of mapsets - :return: None on error + :return: [] on error """ - mapsets = [] - if get == "all" or get == "ordered": ret = RunCommand("g.mapsets", read=True, quiet=True, flags="l", sep="newline") - - if ret: - mapsets = ret.splitlines() - ListSortLower(mapsets) - else: - return None + if not ret: + return [] + mapsets_all = ret.splitlines() + ListSortLower(mapsets_all) + if get == "all": + return mapsets_all if get == "accessible" or get == "ordered": ret = RunCommand("g.mapsets", read=True, quiet=True, flags="p", sep="newline") - if ret: - if get == "accessible": - mapsets = ret.splitlines() - else: - mapsets_accessible = ret.splitlines() - for mapset in mapsets_accessible: - mapsets.remove(mapset) - mapsets = mapsets_accessible + mapsets - else: - return None - - return mapsets + if not ret: + return [] + mapsets_accessible = ret.splitlines() + if get == "accessible": + return mapsets_accessible + + mapsets_ordered = mapsets_accessible.copy() + for mapset in mapsets_all: + if mapset not in mapsets_accessible: + mapsets_ordered.append(mapset) + return mapsets_ordered + + raise ValueError("Invalid value for 'get' parameter of ListOfMapsets()") def ListSortLower(list):