Skip to content

Commit

Permalink
Export Data: Open folder with exported file
Browse files Browse the repository at this point in the history
This patch adds a button to the final notification dialog to allow
a user to open a folder where the exported file is saved.
  • Loading branch information
pgathogo committed Sep 18, 2024
1 parent f95279f commit 8a49c79
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
4 changes: 2 additions & 2 deletions stdm/composer/document_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def set_attr_value_formatters(self, formattermapping: dict):
"""
self._attr_value_formatters = formattermapping

def add_attr_value_formatter(self, attributeName, formatterFunc):
def add_attr_value_formatter(self, attributeName: str, formatterFunc: EntityValueFormatter):
"""
Add a new attribute value formatter configuration to the collection.
"""
Expand All @@ -217,7 +217,7 @@ def attr_value_formatters(self):
"""
return self._attr_value_formatters

def data_source_exists(self, data_source):
def data_source_exists(self, data_source: ComposerDataSource):
"""
:param data_source: Data source object containing table/view name and
corresponding columns.
Expand Down
7 changes: 3 additions & 4 deletions stdm/ui/doc_generator_dlg.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _set_ds_columns(self):
def model(self):
return self._base_model

def data_source(self):
def data_source(self) -> str:
return self._data_source

def data_source_columns(self):
Expand Down Expand Up @@ -243,14 +243,14 @@ def _entity_config_from_profile(self, table_name, short_name):
else:
return None

def dialog(self):
def dialog(self) -> 'DocumentGeneratorDialog':
"""
:return: Returns an instance of the DocumentGeneratorDialog.
:rtype: DocumentGeneratorDialog
"""
return self._doc_gen_dlg

def exec_(self):
def exec_(self) -> int:
"""
Show the dialog as a modal dialog.
:return: DialogCode result
Expand Down Expand Up @@ -738,7 +738,6 @@ def onGenerate(self):
"Document generation has successfully completed.")
)


except SQLAlchemyError as sqlerr:
LOGGER.debug(str(sqlerr))
err_msg = QApplication.translate("DocumentGeneratorDialog",
Expand Down
44 changes: 41 additions & 3 deletions stdm/ui/export_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
* *
***************************************************************************/
"""
import os
import subprocess
import sys

import sqlalchemy
from qgis.PyQt import uic
from qgis.PyQt.QtCore import (
Qt
Qt,
QUrl,
QFileInfo
)
from qgis.PyQt.QtGui import (
QTextOption
Expand All @@ -35,6 +40,7 @@
QMessageBox,
QComboBox
)
from qgis.utils import QDesktopServices

from stdm.exceptions import DummyException
from stdm.data.importexport import (
Expand Down Expand Up @@ -293,10 +299,26 @@ def execExport(self):
self, self.srcTab, resultSet, self.selectedColumns(),
self.geomColumn
)

ft = QApplication.translate('ExportData', 'Features in ')

succ = QApplication.translate(
'ExportData', 'have been successfully exported!')
self.InfoMessage('{}{} {}'.format(ft, self.srcTab, succ))
'ExportData', ' have been successfully exported!')

msg_box = QMessageBox()
msg_box.setIcon(QMessageBox.Information)
msg_box.setText(self.tr("{} `{}` {}".format(ft, self.srcTab, succ)))
msg_box.setInformativeText(
self.tr('Would you like to open the exported file?')
)
msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
msg_box.setDefaultButton(QMessageBox.No)
ret = msg_box.exec_()

if ret == QMessageBox.Yes:
self.open_export_folder(targetFile)

# self.InfoMessage('{}{} {}'.format(ft, self.srcTab, succ))

# Update directory info in the registry
setVectorFileDir(targetFile)
Expand All @@ -308,6 +330,22 @@ def execExport(self):

return succeed

def open_export_folder(self, targetFile: str):
"""
Open the folder where the exported file is located
:rtype: None
"""
folder = QFileInfo(targetFile).path()

if sys.platform.startswith('win32'):
os.startfile(folder)

if sys.platform.startswith('linux'):
subprocess.Popen(['xdg-open', folder])

if sys.platform.startswith('darwin'):
subprocess.Popen(['open', folder])

def filter_clearQuery(self):
# Deletes all the text in the SQL text editor
self.txtWhereQuery.clear()
Expand Down
13 changes: 10 additions & 3 deletions stdm/ui/feature_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* *
***************************************************************************/
"""
import logging
import re
from collections import OrderedDict
from typing import Optional
Expand Down Expand Up @@ -90,11 +91,14 @@
# TODO: the base class here shouldn't really be QWidget, but
# the levels of inheritance here prohibit us to make the subclass
# a QObject subclass without causing diamond inheritance issues

LOGGER = logging.getLogger("stdm")
LOGGER.setLevel(logging.DEBUG)

class LayerSelectionHandler(QWidget):
"""
Handles all tasks related to the layer.
"""

def __init__(self, parent, plugin):
super().__init__(parent)
"""
Expand Down Expand Up @@ -1022,8 +1026,11 @@ def search_spatial_unit(self, entity, spatial_unit_ids, select_matching_features
self.add_root_children(db_model, root, str_records)

if select_matching_features:
#self.layer.selectByIds( list(self.feature_models.keys()))
self.layer.selectByIds([spu_id])
#self.layer.selectByIds(list(self.feature_models.keys()))
try:
self.layer.selectByIds([spu_id])
except DummyException:
LOGGER.debug('No features selected')

# self.zoom_to_selected(self.layer)

Expand Down

0 comments on commit 8a49c79

Please sign in to comment.