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: Add fix for wxGUI Data import Python error #4504

Merged
merged 7 commits into from
Oct 18, 2024
Merged
Changes from 1 commit
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
43 changes: 41 additions & 2 deletions gui/wxpython/modules/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"""

import os
from collections import deque

from pathlib import Path

Expand Down Expand Up @@ -60,6 +61,8 @@ def __init__(

self.commandId = -1 # id of running command

self._commands_running = deque()

wx.Dialog.__init__(
self, parent, id, title, style=style, name="MultiImportDialog"
)
Expand Down Expand Up @@ -122,16 +125,17 @@ def __init__(
# buttons
#
# cancel
self._DEFAULT_CLOSE_BTN_TEXT = "Close dialog"
ww2406 marked this conversation as resolved.
Show resolved Hide resolved
self.btn_close = CloseButton(parent=self.panel)
self.btn_close.SetToolTip(_("Close dialog"))
self.btn_close.SetToolTip(_(self._DEFAULT_CLOSE_BTN_TEXT))
self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose)
# run
self.btn_run = Button(parent=self.panel, id=wx.ID_OK, label=_("&Import"))
self.btn_run.SetToolTip(_("Import selected layers"))
self.btn_run.SetDefault()
self.btn_run.Bind(wx.EVT_BUTTON, self.OnRun)

self.Bind(wx.EVT_CLOSE, lambda evt: self.Destroy())
self.Bind(wx.EVT_CLOSE, self._handleCloseEvent)

self.notebook = GNotebook(parent=self, style=globalvar.FNPageDStyle)

Expand Down Expand Up @@ -270,6 +274,30 @@ def _validateOutputMapName(self):
return False
return True

def _handleCloseEvent(self, *args, **kwargs):
if len(self._commands_running) > 0:
# prevent dialog close while async commands are running
return
ww2406 marked this conversation as resolved.
Show resolved Hide resolved
self.Destroy()

def _addToCommandQueue(self):
self._commands_running.append(True)

# disable the dialog close button
self.btn_close.SetToolTip(_("Dialog cannot be closed while command is running."))
ww2406 marked this conversation as resolved.
Show resolved Hide resolved
self.btn_close.Disable()

def _removeFromCommandQueue(self):
try:
self._commands_running.pop()
except IndexError:
pass
finally:
if len(self._commands_running) == 0:
# enable the dialog close button
self.btn_close.Enable()
self.btn_close.SetToolTip(self._DEFAULT_CLOSE_BTN_TEXT)

def OnClose(self, event=None):
"""Close dialog"""
self.Close()
Expand Down Expand Up @@ -519,6 +547,7 @@ def OnRun(self, event):
):
cmd.append("--overwrite")

self._addToCommandQueue()
# run in Layer Manager
self._giface.RunCmd(
cmd, onDone=self.OnCmdDone, userData=userData, addLayer=False
Expand All @@ -527,9 +556,11 @@ def OnRun(self, event):
def OnCmdDone(self, event):
"""Load layers and close if required"""
if not hasattr(self, "AddLayers"):
self._removeFromCommandQueue()
return

self.AddLayers(event.returncode, event.cmd, event.userData)
self._removeFromCommandQueue()

if event.returncode == 0 and self.closeOnFinish.IsChecked():
self.Close()
Expand Down Expand Up @@ -670,6 +701,7 @@ def OnRun(self, event):
):
cmd.append("--overwrite")

self._addToCommandQueue()
# run in Layer Manager
self._giface.RunCmd(
cmd, onDone=self.OnCmdDone, userData=userData, addLayer=False
Expand All @@ -678,10 +710,13 @@ def OnRun(self, event):
def OnCmdDone(self, event):
"""Load layers and close if required"""
if not hasattr(self, "AddLayers"):
self._removeFromCommandQueue()
return

self.AddLayers(event.returncode, event.cmd, event.userData)

self._removeFromCommandQueue()

if self.popOGR:
os.environ.pop("GRASS_VECTOR_OGR")

Expand Down Expand Up @@ -880,16 +915,20 @@ def OnRun(self, event):
):
cmd.append("--overwrite")

self._commands_running.append(True)
# run in Layer Manager
self._giface.RunCmd(cmd, onDone=self.OnCmdDone, addLayer=False)

def OnCmdDone(self, event):
"""Load layers and close if required"""
if not hasattr(self, "AddLayers"):
self._removeFromCommandQueue()
return

self.AddLayers(event.returncode, event.cmd)

self._removeFromCommandQueue()

if self.closeOnFinish.IsChecked():
self.Close()

Expand Down
Loading