mirror of
https://github.com/rio-labs/rio.git
synced 2026-01-23 22:11:45 -06:00
renamed "file chooser" to "pick file"
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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<FileChooserAreaState>;
|
||||
export class FilePickerAreaComponent extends ComponentBase {
|
||||
state: Required<FilePickerAreaState>;
|
||||
|
||||
private fileInput: HTMLInputElement;
|
||||
private iconElement: HTMLElement;
|
||||
@@ -211,7 +211,7 @@ export class FileChooserAreaComponent extends ComponentBase {
|
||||
}
|
||||
|
||||
updateElement(
|
||||
deltaState: FileChooserAreaState,
|
||||
deltaState: FilePickerAreaState,
|
||||
latentComponents: Set<ComponentBase>
|
||||
): void {
|
||||
super.updateElement(deltaState, latentComponents);
|
||||
|
||||
@@ -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,
|
||||
*,
|
||||
|
||||
@@ -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,
|
||||
*,
|
||||
|
||||
@@ -21,7 +21,7 @@ class TestingServer(AbstractAppServer):
|
||||
) -> rio.URL:
|
||||
raise NotImplementedError
|
||||
|
||||
async def file_chooser(
|
||||
async def pick_file(
|
||||
self,
|
||||
session: rio.Session,
|
||||
*,
|
||||
|
||||
@@ -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 *
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user