Commit dea14d03 authored by Duggan, John's avatar Duggan, John
Browse files

Add a parameter to control the refresh rate

parent ce2ff06c
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -20,14 +20,13 @@ vuetify.enable_lab()
class DataSelector(datagrid.VGrid):
    """Allows the user to select datafiles from the server."""

    REFRESH_RATE = 30

    def __init__(
        self,
        v_model: str,
        directory: str,
        extensions: Optional[List[str]] = None,
        prefix: str = "",
        refresh_rate: int = 30,
        select_strategy: str = "all",
        **kwargs: Any,
    ) -> None:
@@ -46,6 +45,9 @@ class DataSelector(datagrid.VGrid):
        prefix : str, optional
            A subdirectory within the selected top-level folder to show files. If not specified, the user will be shown
            a folder browser and will be able to see all files in the selected top-level folder.
        refresh_rate : int, optional
            The number of seconds between attempts to automatically refresh the file list. Set to zero to disable this
            feature. Defaults to 30 seconds.
        select_strategy : str, optional
            The selection strategy to pass to the `VDataTable component <https://trame.readthedocs.io/en/latest/trame.widgets.vuetify3.html#trame.widgets.vuetify3.VDataTable>`__.
            If unset, the `all` strategy will be used.
@@ -76,6 +78,7 @@ class DataSelector(datagrid.VGrid):
        self._directory = directory
        self._extensions = extensions if extensions is not None else []
        self._prefix = prefix
        self._refresh_rate = refresh_rate
        self._select_strategy = select_strategy

        self._revogrid_id = f"nova__dataselector_{self._next_id}_rv"
@@ -210,8 +213,9 @@ class DataSelector(datagrid.VGrid):
        )

    async def _refresh_loop(self) -> None:
        if self._refresh_rate > 0:
            while True:
            await sleep(self.REFRESH_RATE)
                await sleep(self._refresh_rate)

                self.refresh_contents()
                self.state.dirty(self._datafiles_name)
+5 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ class NeutronDataSelector(DataSelector):
        instrument: str = "",
        extensions: Optional[List[str]] = None,
        prefix: str = "",
        refresh_rate: int = 30,
        select_strategy: str = "all",
        **kwargs: Any,
    ) -> None:
@@ -54,6 +55,9 @@ class NeutronDataSelector(DataSelector):
        prefix : str, optional
            A subdirectory within the user's chosen experiment to show files. If not specified, the user will be shown a
            folder browser and will be able to see all files in the experiment that they have access to.
        refresh_rate : int, optional
            The number of seconds between attempts to automatically refresh the file list. Set to zero to disable this
            feature. Defaults to 30 seconds.
        select_strategy : str, optional
            The selection strategy to pass to the `VDataTable component <https://trame.readthedocs.io/en/latest/trame.widgets.vuetify3.html#trame.widgets.vuetify3.VDataTable>`__.
            If unset, the `all` strategy will be used.
@@ -76,7 +80,7 @@ class NeutronDataSelector(DataSelector):
        self._instruments_name = f"nova__neutrondataselector_{self._next_id}_instruments"
        self._experiments_name = f"nova__neutrondataselector_{self._next_id}_experiments"

        super().__init__(v_model, "", extensions, prefix, select_strategy, **kwargs)
        super().__init__(v_model, "", extensions, prefix, refresh_rate, select_strategy, **kwargs)

    def create_ui(self, **kwargs: Any) -> None:
        super().create_ui(**kwargs)
+1 −1
Original line number Diff line number Diff line
@@ -350,7 +350,7 @@ class App(ThemedApp):

                    vuetify.VCardTitle("Data Selection Widgets")
                    with html.Div(classes="border-md text-left", style="height: 650px; width: 600px;"):
                        DataSelector(v_model="data_selector.selected_files", chips=True, directory="/")
                        DataSelector(v_model="data_selector.selected_files", chips=True, directory="/", refresh_rate=0)
                    with html.Div(classes="border-md text-left", style="height: 650px; width: 600px;"):
                        NeutronDataSelector(
                            v_model="data_selector.selected_neutron_files", allow_custom_directories=True, chips=True