Loading CHANGELOG.md +4 −0 Original line number Diff line number Diff line ### nova-trame, 0.25.0 * FileUpload now supports a return_contents parameter (thanks to John Duggan). ### nova-trame, 0.24.1 * Fixed literalinclude paths in the documentation (thanks to John Duggan). Loading pyproject.toml +1 −1 Original line number Diff line number Diff line [project] name = "nova-trame" version = "0.24.1" version = "0.25.0" description = "A Python Package for injecting curated themes and custom components into Trame applications" authors = [ { name = "John Duggan", email = "dugganjw@ornl.gov" }, Loading src/nova/trame/view/components/file_upload.py +18 −4 Original line number Diff line number Diff line Loading @@ -10,7 +10,14 @@ from .remote_file_input import RemoteFileInput class FileUpload(vuetify.VBtn): """Component for uploading a file from either the user's filesystem or the server filesystem.""" def __init__(self, v_model: str, base_paths: Optional[List[str]] = None, label: str = "", **kwargs: Any) -> None: def __init__( self, v_model: str, base_paths: Optional[List[str]] = None, label: str = "", return_contents: bool = True, **kwargs: Any, ) -> None: """Constructor for FileUpload. Parameters Loading @@ -23,6 +30,9 @@ class FileUpload(vuetify.VBtn): Passed to :ref:`RemoteFileInput <api_remotefileinput>`. label : str, optional The text to display on the upload button. return_contents : bool, optional If true, the file contents will be stored in v_model. If false, a file path will be stored in v_model. Defaults to true. **kwargs All other arguments will be passed to the underlying `Button component <https://trame.readthedocs.io/en/latest/trame.widgets.vuetify3.html#trame.widgets.vuetify3.VBtn>`_. Loading @@ -36,6 +46,7 @@ class FileUpload(vuetify.VBtn): self._base_paths = base_paths else: self._base_paths = ["/"] self._return_contents = return_contents self._ref_name = f"nova__fileupload_{self._next_id}" super().__init__(label, **kwargs) Loading @@ -54,7 +65,10 @@ class FileUpload(vuetify.VBtn): ), ) self.remote_file_input = RemoteFileInput( v_model=self._v_model, base_paths=self._base_paths, input_props={"classes": "d-none"}, return_contents=True v_model=self._v_model, base_paths=self._base_paths, input_props={"classes": "d-none"}, return_contents=self._return_contents, ) with self: Loading @@ -65,7 +79,7 @@ class FileUpload(vuetify.VBtn): @self.server.controller.trigger(f"decode_blob_{self._id}") def _decode_blob(contents: bytes) -> None: self.remote_file_input.decode_file(contents) self.remote_file_input.decode_file(contents, self._return_contents) def select_file(self, value: str) -> None: """Programmatically set the RemoteFileInput path. Loading src/nova/trame/view/components/remote_file_input.py +9 −2 Original line number Diff line number Diff line """View implementation for RemoteFileInput.""" from functools import partial from tempfile import NamedTemporaryFile from typing import Any, Optional, Union, cast from trame.app import get_server Loading Loading @@ -207,9 +208,15 @@ class RemoteFileInput: with open(file_path, mode="rb") as file: self.decode_file(file.read()) def decode_file(self, bytestream: bytes) -> None: def decode_file(self, bytestream: bytes, set_contents: bool = False) -> None: decoded_content = bytestream.decode("latin1") if set_contents: self.set_v_model(decoded_content) else: with NamedTemporaryFile(mode="w", delete=False, encoding="utf-8") as temp_file: temp_file.write(decoded_content) temp_file.flush() self.set_v_model(temp_file.name) def select_file(self, value: str) -> None: """Programmatically set the v_model value.""" Loading src/nova/trame/view/theme/assets/core_style.scss +4 −0 Original line number Diff line number Diff line Loading @@ -149,6 +149,10 @@ html { } } .v-tabs { height: 32px !important; } .v-tab.v-btn { height: 30px !important; min-width: fit-content !important; Loading Loading
CHANGELOG.md +4 −0 Original line number Diff line number Diff line ### nova-trame, 0.25.0 * FileUpload now supports a return_contents parameter (thanks to John Duggan). ### nova-trame, 0.24.1 * Fixed literalinclude paths in the documentation (thanks to John Duggan). Loading
pyproject.toml +1 −1 Original line number Diff line number Diff line [project] name = "nova-trame" version = "0.24.1" version = "0.25.0" description = "A Python Package for injecting curated themes and custom components into Trame applications" authors = [ { name = "John Duggan", email = "dugganjw@ornl.gov" }, Loading
src/nova/trame/view/components/file_upload.py +18 −4 Original line number Diff line number Diff line Loading @@ -10,7 +10,14 @@ from .remote_file_input import RemoteFileInput class FileUpload(vuetify.VBtn): """Component for uploading a file from either the user's filesystem or the server filesystem.""" def __init__(self, v_model: str, base_paths: Optional[List[str]] = None, label: str = "", **kwargs: Any) -> None: def __init__( self, v_model: str, base_paths: Optional[List[str]] = None, label: str = "", return_contents: bool = True, **kwargs: Any, ) -> None: """Constructor for FileUpload. Parameters Loading @@ -23,6 +30,9 @@ class FileUpload(vuetify.VBtn): Passed to :ref:`RemoteFileInput <api_remotefileinput>`. label : str, optional The text to display on the upload button. return_contents : bool, optional If true, the file contents will be stored in v_model. If false, a file path will be stored in v_model. Defaults to true. **kwargs All other arguments will be passed to the underlying `Button component <https://trame.readthedocs.io/en/latest/trame.widgets.vuetify3.html#trame.widgets.vuetify3.VBtn>`_. Loading @@ -36,6 +46,7 @@ class FileUpload(vuetify.VBtn): self._base_paths = base_paths else: self._base_paths = ["/"] self._return_contents = return_contents self._ref_name = f"nova__fileupload_{self._next_id}" super().__init__(label, **kwargs) Loading @@ -54,7 +65,10 @@ class FileUpload(vuetify.VBtn): ), ) self.remote_file_input = RemoteFileInput( v_model=self._v_model, base_paths=self._base_paths, input_props={"classes": "d-none"}, return_contents=True v_model=self._v_model, base_paths=self._base_paths, input_props={"classes": "d-none"}, return_contents=self._return_contents, ) with self: Loading @@ -65,7 +79,7 @@ class FileUpload(vuetify.VBtn): @self.server.controller.trigger(f"decode_blob_{self._id}") def _decode_blob(contents: bytes) -> None: self.remote_file_input.decode_file(contents) self.remote_file_input.decode_file(contents, self._return_contents) def select_file(self, value: str) -> None: """Programmatically set the RemoteFileInput path. Loading
src/nova/trame/view/components/remote_file_input.py +9 −2 Original line number Diff line number Diff line """View implementation for RemoteFileInput.""" from functools import partial from tempfile import NamedTemporaryFile from typing import Any, Optional, Union, cast from trame.app import get_server Loading Loading @@ -207,9 +208,15 @@ class RemoteFileInput: with open(file_path, mode="rb") as file: self.decode_file(file.read()) def decode_file(self, bytestream: bytes) -> None: def decode_file(self, bytestream: bytes, set_contents: bool = False) -> None: decoded_content = bytestream.decode("latin1") if set_contents: self.set_v_model(decoded_content) else: with NamedTemporaryFile(mode="w", delete=False, encoding="utf-8") as temp_file: temp_file.write(decoded_content) temp_file.flush() self.set_v_model(temp_file.name) def select_file(self, value: str) -> None: """Programmatically set the v_model value.""" Loading
src/nova/trame/view/theme/assets/core_style.scss +4 −0 Original line number Diff line number Diff line Loading @@ -149,6 +149,10 @@ html { } } .v-tabs { height: 32px !important; } .v-tab.v-btn { height: 30px !important; min-width: fit-content !important; Loading