From 39403fe4e8854a15aa000dd6734f15dd08c55eb7 Mon Sep 17 00:00:00 2001 From: Jakob Pinterits Date: Mon, 23 Sep 2024 18:03:41 +0200 Subject: [PATCH] renamed "file chooser" to "pick file" --- frontend/code/componentManagement.ts | 4 +- frontend/code/components/fileChooserArea.ts | 10 ++--- rio/app_server/abstract_app_server.py | 2 +- rio/app_server/fastapi_server.py | 2 +- rio/app_server/testing_server.py | 2 +- rio/components/__init__.py | 2 +- rio/components/file_chooser_area.py | 18 ++++---- rio/docs.py | 2 +- rio/session.py | 48 ++++++++++++++++++--- 9 files changed, 64 insertions(+), 26 deletions(-) diff --git a/frontend/code/componentManagement.ts b/frontend/code/componentManagement.ts index 3457d951..047e0640 100644 --- a/frontend/code/componentManagement.ts +++ b/frontend/code/componentManagement.ts @@ -20,7 +20,7 @@ import { DevToolsConnectorComponent } from './components/devToolsConnector'; import { DialogContainerComponent } from './components/dialog_container'; import { DrawerComponent } from './components/drawer'; import { DropdownComponent } from './components/dropdown'; -import { FileChooserAreaComponent } from './components/fileChooserArea'; +import { FilePickerAreaComponent } from './components/FilePickerArea'; import { FlowComponent as FlowContainerComponent } from './components/flowContainer'; import { FundamentalRootComponent } from './components/fundamentalRootComponent'; import { GridComponent } from './components/grid'; @@ -82,7 +82,7 @@ const COMPONENT_CLASSES = { 'DialogContainer-builtin': DialogContainerComponent, 'Drawer-builtin': DrawerComponent, 'Dropdown-builtin': DropdownComponent, - 'FileChooserArea-builtin': FileChooserAreaComponent, + 'FilePickerArea-builtin': FilePickerAreaComponent, 'FlowContainer-builtin': FlowContainerComponent, 'FundamentalRootComponent-builtin': FundamentalRootComponent, 'Grid-builtin': GridComponent, diff --git a/frontend/code/components/fileChooserArea.ts b/frontend/code/components/fileChooserArea.ts index 5b3df3ef..a942a293 100644 --- a/frontend/code/components/fileChooserArea.ts +++ b/frontend/code/components/fileChooserArea.ts @@ -79,14 +79,14 @@ const CATEGORY_TO_METADATA = { video: ['videos', 'material/movie'], }; -type FileChooserAreaState = ComponentState & { - _type_: 'FileChooserArea-builtin'; +type FilePickerAreaState = ComponentState & { + _type_: 'FilePickerArea-builtin'; content?: string | null; file_types?: string[]; }; -export class FileChooserAreaComponent extends ComponentBase { - state: Required; +export class FilePickerAreaComponent extends ComponentBase { + state: Required; private fileInput: HTMLInputElement; private iconElement: HTMLElement; @@ -211,7 +211,7 @@ export class FileChooserAreaComponent extends ComponentBase { } updateElement( - deltaState: FileChooserAreaState, + deltaState: FilePickerAreaState, latentComponents: Set ): void { super.updateElement(deltaState, latentComponents); diff --git a/rio/app_server/abstract_app_server.py b/rio/app_server/abstract_app_server.py index 6eaed53e..f09862d3 100644 --- a/rio/app_server/abstract_app_server.py +++ b/rio/app_server/abstract_app_server.py @@ -146,7 +146,7 @@ class AbstractAppServer(abc.ABC): traceback.print_exc() @abc.abstractmethod - async def file_chooser( + async def pick_file( self, session: rio.Session, *, diff --git a/rio/app_server/fastapi_server.py b/rio/app_server/fastapi_server.py index 85ec43c0..751afd20 100644 --- a/rio/app_server/fastapi_server.py +++ b/rio/app_server/fastapi_server.py @@ -843,7 +843,7 @@ Sitemap: {base_url / "/rio/sitemap"} status_code=fastapi.status.HTTP_200_OK ) - async def file_chooser( + async def pick_file( self, session: rio.Session, *, diff --git a/rio/app_server/testing_server.py b/rio/app_server/testing_server.py index d51abe45..a5f2b423 100644 --- a/rio/app_server/testing_server.py +++ b/rio/app_server/testing_server.py @@ -21,7 +21,7 @@ class TestingServer(AbstractAppServer): ) -> rio.URL: raise NotImplementedError - async def file_chooser( + async def pick_file( self, session: rio.Session, *, diff --git a/rio/components/__init__.py b/rio/components/__init__.py index 61e7fc3b..11a4c04a 100644 --- a/rio/components/__init__.py +++ b/rio/components/__init__.py @@ -16,7 +16,6 @@ from .devel_component import * from .dialog_container import * from .drawer import * from .dropdown import * -from .file_chooser_area import * from .flow_container import * from .grid import * from .html import * @@ -38,6 +37,7 @@ from .node_output import * from .number_input import * from .overlay import * from .page_view import * +from .pick_file_area import * from .plot import * from .popup import * from .progress_bar import * diff --git a/rio/components/file_chooser_area.py b/rio/components/file_chooser_area.py index c5b62dc3..4acde56f 100644 --- a/rio/components/file_chooser_area.py +++ b/rio/components/file_chooser_area.py @@ -12,20 +12,20 @@ from .. import utils from .fundamental_component import FundamentalComponent __all__ = [ - "FileChooseEvent", - "FileChooserArea", + "FilePickEvent", + "FilePickerArea", ] @final @rio.docs.mark_constructor_as_private @dataclass -class FileChooseEvent: +class FilePickEvent: """ Holds information regarding a file upload event. This is a simple dataclass that stores useful information for when the user - chooses a file using a `FileChooserArea`. You'll typically receive this as + chooses a file using a `FilePickerArea`. You'll typically receive this as argument in `on_choose_file` events. ## Attributes @@ -37,11 +37,11 @@ class FileChooseEvent: @final -class FileChooserArea(FundamentalComponent): +class FilePickerArea(FundamentalComponent): """ Drag & Drop are for files - The `FileChooserArea` component allows the user to upload files either by + The `FilePickerArea` component allows the user to upload files either by dragging and dropping them onto the component, or optionally using a regular file browser. Whenever a file has been uploaded, the `on_file_upload` event is triggered, allowing you to run code. @@ -75,7 +75,7 @@ class FileChooserArea(FundamentalComponent): _: KW_ONLY content: str | None = None file_types: list[str] | None = None - on_choose_file: rio.EventHandler[FileChooseEvent] = None + on_choose_file: rio.EventHandler[FilePickEvent] = None def _custom_serialize_(self) -> JsonDoc: if self.file_types is None: @@ -93,7 +93,7 @@ class FileChooserArea(FundamentalComponent): async def _on_file_upload_(self, files: list[rio.FileInfo]) -> None: for file in files: # TODO: Should these be called simultaneously? - event_data = FileChooseEvent(file) + event_data = FilePickEvent(file) await self.call_event_handler( self.on_choose_file, @@ -101,4 +101,4 @@ class FileChooserArea(FundamentalComponent): ) -FileChooserArea._unique_id_ = "FileChooserArea-builtin" +FilePickerArea._unique_id_ = "FilePickerArea-builtin" diff --git a/rio/docs.py b/rio/docs.py index 01605543..cdf5e3ea 100644 --- a/rio/docs.py +++ b/rio/docs.py @@ -197,7 +197,7 @@ def _find_possibly_public_objects() -> Iterable[Type | Callable]: yield rio.DropdownChangeEvent yield rio.escape_markdown yield rio.escape_markdown_code - yield rio.FileChooseEvent + yield rio.FilePickEvent yield rio.FileInfo yield rio.Font yield rio.KeyDownEvent diff --git a/rio/session.py b/rio/session.py index b098827e..66e3a613 100644 --- a/rio/session.py +++ b/rio/session.py @@ -2026,7 +2026,7 @@ window.history.{method}(null, "", {json.dumps(active_page_url.path)}) await self._remote_set_title(title) @overload - async def file_chooser( + async def pick_file( self, *, file_types: Iterable[str] | None = None, @@ -2034,7 +2034,7 @@ window.history.{method}(null, "", {json.dumps(active_page_url.path)}) ) -> utils.FileInfo: ... @overload - async def file_chooser( + async def pick_file( self, *, file_types: Iterable[str] | None = None, @@ -2046,7 +2046,7 @@ window.history.{method}(null, "", {json.dumps(active_page_url.path)}) old_name="file_extension", new_name="file_types", ) - async def file_chooser( + async def pick_file( self, *, file_types: Iterable[str] | None = None, @@ -2090,12 +2090,50 @@ window.history.{method}(null, "", {json.dumps(active_page_url.path)}) } ) - return await self._app_server.file_chooser( + return await self._app_server.pick_file( self, file_types=file_types, multiple=multiple, ) + @overload + async def file_chooser( + self, + *, + file_types: Iterable[str] | None = None, + multiple: Literal[False] = False, + ) -> utils.FileInfo: ... + + @overload + async def file_chooser( + self, + *, + file_types: Iterable[str] | None = None, + multiple: Literal[True], + ) -> list[utils.FileInfo]: ... + + @deprecations.function_kwarg_renamed( + since="0.9.3", + old_name="file_extension", + new_name="file_types", + ) + async def file_chooser( + self, + *args, + **kwargs, + ) -> utils.FileInfo | list[utils.FileInfo]: + """ + This function has been renamed. Use `pick_file` instead. + """ + # Warn + deprecations.warn( + since="0.9.3", + message="`file_chooser` has been renamed to `pick_file`. Please use the new name instead.", + ) + + # Delegate to the new function + return await self.pick_file(*args, **kwargs) + async def save_file( self, file_contents: pathlib.Path | str | bytes, @@ -2110,7 +2148,7 @@ window.history.{method}(null, "", {json.dumps(active_page_url.path)}) This function allows you to save a file to the user's device. The user will be prompted to select a location to save the file to. - See also `file_chooser` if you want to open a file instead of saving + See also `pick_file` if you want to open a file instead of saving one.