Skip to content

Commit

Permalink
show default filepath in Export plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
gibsongreen committed May 28, 2024
1 parent ec80391 commit 41ed5d8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ New Features
- Descriptions are shown in the color mode dropdown for image layers to help describe the use-cases
for ``Colormap`` vs ``Color``. [#2894]

- Display default filepath in Export plugin. [#2896]

Cubeviz
^^^^^^^

Expand Down
16 changes: 15 additions & 1 deletion jdaviz/configs/default/plugins/export/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class Export(PluginTemplateMixin, ViewerSelectMixin, SubsetSelectMixin,
filename_auto = Bool(True).tag(sync=True)
filename_invalid_msg = Unicode('').tag(sync=True)

default_filepath = Unicode().tag(sync=True)

# if selected subset is spectral or composite, display message and disable export
subset_invalid_msg = Unicode().tag(sync=True)
data_invalid_msg = Unicode().tag(sync=True)
Expand Down Expand Up @@ -254,6 +256,12 @@ def _set_filename_default(self, *args, **kwargs):
else:
self.filename_default = ''

# Call to initially set the default filepath
if hasattr(self, 'viewer_format') and self.filename_default:
self._normalize_filename(filename=self.filename_default,
filetype=self.viewer_format.selected,
default_path=True)

@observe('filename_value')
def _is_filename_changed(self, event):
# Clear overwrite warning when user changes filename
Expand Down Expand Up @@ -333,7 +341,7 @@ def _set_dataset_not_supported_msg(self, msg=None):
else:
self.data_invalid_msg = ''

def _normalize_filename(self, filename=None, filetype=None, overwrite=False):
def _normalize_filename(self, filename=None, filetype=None, overwrite=False, default_path=False): # noqa: E501
# Make sure filename is valid and file does not end up in weird places in standalone mode.
if not filename:
raise ValueError("Invalid filename")
Expand All @@ -349,6 +357,12 @@ def _normalize_filename(self, filename=None, filetype=None, overwrite=False):
elif ((not filepath or str(filepath).startswith(".")) and os.environ.get("JDAVIZ_START_DIR", "")): # noqa: E501 # pragma: no cover
filename = os.environ["JDAVIZ_START_DIR"] / filename

# Set the default filepath to inform user where file will be exported to
if default_path:
if not filepath.is_absolute():
abs_path = filepath.resolve()
self.default_filepath = str(abs_path)

if filename.exists() and not overwrite:
self.overwrite_warn = True
else:
Expand Down
12 changes: 12 additions & 0 deletions jdaviz/configs/default/plugins/export/export.vue
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,18 @@
<div style="display: grid; position: relative"> <!-- overlay container -->
<div style="grid-area: 1/1">

<v-row class="row-no-outside-padding row-min-bottom-padding">
<v-col>
<v-text-field
:value="filepath_value"
label="Filepath"
hint="Default filepath export location."
persistent-hint
disabled
></v-text-field>
</v-col>
</v-row>

<plugin-auto-label
:value.sync="filename_value"
:default="filename_default"
Expand Down

0 comments on commit 41ed5d8

Please sign in to comment.