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/locdownload: show progress of downloading new location as Data Catalog info bar message #3287

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions gui/wxpython/datacatalog/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def __init__(
# tree with layers
self.tree = DataCatalogTree(self, giface=giface)
self.tree.showNotification.connect(self.showNotification)
self.tree.showDownloadingNewLocationInfoMessage.connect(
self.showDownloadingNewLocationInfoMessage
)
self.tree.dismissShowInfoBarMessage.connect(self.dismissInfobar)

# infobar for data catalog
delay = 2000
Expand Down Expand Up @@ -140,6 +144,18 @@ def showImportDataInfo(self):
self.OnImportOgrLayers, self.OnImportGdalLayers
)

def showDownloadingNewLocationInfoMessage(self, message, buttons):
"""Show progress of downloading new location info message

:param str message: text message
:param list buttons: list of info bar widget buttons
[(button_label, button_click_event_handler),...]
"""
self.infoManager.ShowDownloadingNewLocationInfo(
message=message,
buttons=buttons,
)

def LoadItems(self):
"""Reload tree - full or lazy - based on user settings"""
self._startLoadingTime = clock()
Expand Down
17 changes: 17 additions & 0 deletions gui/wxpython/datacatalog/infomanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ def ShowLockedMapsetInfo(self, OnSwitchMapsetHandler):
).format(mapsetpath=last_used_mapset_path)
self.infoBar.ShowMessage(message, wx.ICON_INFORMATION, buttons)

def ShowDownloadingNewLocationInfo(self, message, buttons):
"""Show progress of downloading new location info message

:param str message: message text
:param list buttons: list of info bar widget buttons
[(buton_label, button_click_event_handler),...]
"""
self.infoBar.ShowMessage(message, wx.ICON_INFORMATION, remove_buttons=False)
if buttons:
for btn in buttons:
if btn["btnsAction"]["addBtn"]:
# Add btn widget here, to prevent blinking widget
self.infoBar.AddButton(btnid=btn["id"], label=btn["label"])
self.infoBar.Bind(wx.EVT_BUTTON, btn["handler"], id=btn["id"])
if btn["btnsAction"]["removeBtn"]:
self.infoBar.RemoveButtons()

def _text_from_reason_id(self, reason_id):
"""Get string for infobar message based on the reason."""
last_used_mapset_path = gisenv()["LAST_MAPSET_PATH"]
Expand Down
32 changes: 27 additions & 5 deletions gui/wxpython/datacatalog/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ def __init__(
self.showNotification = Signal("Tree.showNotification")
self.showImportDataInfo = Signal("Tree.showImportDataInfo")
self.loadingDone = Signal("Tree.loadingDone")
self.showDownloadingNewLocationInfoMessage = Signal(
"Tree.showDownloadingNewLocationInfoMessage"
)
self.dismissShowInfoBarMessage = Signal("Tree.dismissShowInfoBarMessage")
self.parent = parent
self.contextMenu.connect(self.OnRightClick)
self.itemActivated.connect(self.OnDoubleClick)
Expand Down Expand Up @@ -1612,17 +1616,35 @@ def OnDeleteLocation(self, event):
for change in changes:
self._giface.grassdbChanged.emit(**change)

def AddDownloadedNewLocation(self):
"""
Add downloaded new location into tree
"""
location = self.loc_download.GetLocation()
if location:
self._reloadGrassDBNode(self.selected_grassdb[0])
self.UpdateCurrentDbLocationMapsetNode()
self.RefreshItems()
self.showNotification.emit(
message=_(
"The new location <{}> has been downloaded successfully"
).format(location)
)

def DownloadLocation(self, grassdb_node):
"""
Download new location interactively.
"""
grassdatabase, location, mapset = download_location_interactively(
self.loc_download = download_location_interactively(
self, grassdb_node.data["name"]
)
if location:
self._reloadGrassDBNode(grassdb_node)
self.UpdateCurrentDbLocationMapsetNode()
self.RefreshItems()
self.loc_download.newLocationIsDownloaded.connect(self.AddDownloadedNewLocation)
self.loc_download.showInfoBarMessage.connect(
self.showDownloadingNewLocationInfoMessage
)
self.loc_download.dismissShowInfoBarMessage.connect(
self.dismissShowInfoBarMessage
)

def OnDownloadLocation(self, event):
"""
Expand Down
6 changes: 4 additions & 2 deletions gui/wxpython/gui_core/infobar.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ def _unInitLayout(self):
else:
sizer.Detach(i)

def ShowMessage(self, message, icon, buttons=None):
def ShowMessage(self, message, icon, buttons=None, remove_buttons=True):
"""Show message with buttons (optional).
Buttons are list of tuples (label, handler)"""
self.Hide()
self.RemoveButtons()
if remove_buttons:
self.RemoveButtons()
if buttons:
self.SetButtons(buttons)
super().ShowMessage(message, icon)
Expand All @@ -122,6 +123,7 @@ def AddButton(self, btnid, label):
self._button.Hide()

button = wx.Button(self, btnid, label)
self.button_ids.append(btnid)
button.SetBackgroundColour(self._background_color)
button.SetForegroundColour(self._foreground_color)

Expand Down
18 changes: 6 additions & 12 deletions gui/wxpython/startup/guiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,23 +319,17 @@ def download_location_interactively(guiparent, grassdb):
"""
Download new location using Location Wizard.

Returns tuple (database, location, mapset) where mapset is "PERMANENT"
by default or in future it could be the mapset the user may want to
switch to.
:param guiparent object: gui parent object
:param str grassdb: GRASS GIS database path string

:return object loc_download: Download location dialog instance object
"""
from startup.locdownload import LocationDownloadDialog

result = (None, None, None)
loc_download = LocationDownloadDialog(parent=guiparent, database=grassdb)
loc_download.Centre()
loc_download.ShowModal()

if loc_download.GetLocation() is not None:
# Returns database and location created by user
# and a mapset user may want to switch to
result = (grassdb, loc_download.GetLocation(), "PERMANENT")
loc_download.Destroy()
return result
loc_download.Show()
return loc_download


def delete_mapset_interactively(guiparent, grassdb, location, mapset):
Expand Down
Loading
Loading