Skip to content

Commit

Permalink
wxGUI: rewrite and document core.utils.ListOfMapsets to not cause GUI…
Browse files Browse the repository at this point in the history
… crash in certain circumstances (OSGeo#3226)
  • Loading branch information
petrasovaa authored and neteler committed Jan 10, 2024
1 parent 6ba89a1 commit 8121c95
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,38 +280,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):
Expand Down

0 comments on commit 8121c95

Please sign in to comment.