Skip to content

Commit

Permalink
remove and update deprecated APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Aug 30, 2024
1 parent 542dae8 commit 223c9df
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 132 deletions.
19 changes: 1 addition & 18 deletions nicegui/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,7 @@ async def disconnected(self, check_interval: float = 0.1) -> None:
await asyncio.sleep(check_interval)
self.is_waiting_for_disconnect = False

def run_javascript(self, code: str, *,
respond: Optional[bool] = None, # DEPRECATED
timeout: float = 1.0,
check_interval: float = 0.01, # DEPRECATED
) -> AwaitableResponse:
def run_javascript(self, code: str, *, timeout: float = 1.0) -> AwaitableResponse:
"""Execute JavaScript on the client.
The client connection must be established before this method is called.
Expand All @@ -199,19 +195,6 @@ def run_javascript(self, code: str, *,
:return: AwaitableResponse that can be awaited to get the result of the JavaScript code
"""
if respond is True:
helpers.warn_once('The "respond" argument of run_javascript() has been removed. '
'Now the method always returns an AwaitableResponse that can be awaited. '
'Please remove the "respond=True" argument.')
if respond is False:
raise ValueError('The "respond" argument of run_javascript() has been removed. '
'Now the method always returns an AwaitableResponse that can be awaited. '
'Please remove the "respond=False" argument and call the method without awaiting.')
if check_interval != 0.01:
helpers.warn_once('The "check_interval" argument of run_javascript() and similar methods has been removed. '
'Now the method automatically returns when receiving a response without checking regularly in an interval. '
'Please remove the "check_interval" argument.')

request_id = str(uuid.uuid4())
target_id = self._temporary_socket_id or self.id

Expand Down
16 changes: 0 additions & 16 deletions nicegui/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from typing import TYPE_CHECKING, List

from . import helpers
from .slot import Slot

if TYPE_CHECKING:
Expand All @@ -11,21 +10,6 @@

class Context:

def get_slot_stack(self) -> List[Slot]:
"""Return the slot stack of the current asyncio task. (DEPRECATED, use context.slot_stack instead)"""
helpers.warn_once('context.get_slot_stack() is deprecated, use context.slot_stack instead')
return self.slot_stack

def get_slot(self) -> Slot:
"""Return the current slot. (DEPRECATED, use context.slot instead)"""
helpers.warn_once('context.get_slot() is deprecated, use context.slot instead')
return self.slot

def get_client(self) -> Client:
"""Return the current client. (DEPRECATED, use context.client instead)"""
helpers.warn_once('context.get_client() is deprecated, use context.client instead')
return self.client

@property
def slot_stack(self) -> List[Slot]:
"""Return the slot stack of the current asyncio task."""
Expand Down
8 changes: 5 additions & 3 deletions nicegui/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,15 @@ def glob_absolute_paths(file: Union[str, Path]) -> List[Path]:

if libraries:
helpers.warn_once(f'The `libraries` parameter for subclassing "{cls.__name__}" is deprecated. '
'It will be removed in NiceGUI 3.0. '
'Use `dependencies` instead.')
if exposed_libraries:
helpers.warn_once(f'The `exposed_libraries` parameter for subclassing "{cls.__name__}" is deprecated. '
'It will be removed in NiceGUI 3.0. '
'Use `dependencies` instead.')
if extra_libraries:
helpers.warn_once(f'The `extra_libraries` parameter for subclassing "{cls.__name__}" is deprecated. '
'It will be removed in NiceGUI 3.0. '
'Use `dependencies` instead.')

cls.component = copy(cls.component)
Expand Down Expand Up @@ -391,7 +394,7 @@ def update(self) -> None:
return
self.client.outbox.enqueue_update(self)

def run_method(self, name: str, *args: Any, timeout: float = 1, check_interval: float = 0.01) -> AwaitableResponse:
def run_method(self, name: str, *args: Any, timeout: float = 1) -> AwaitableResponse:
"""Run a method on the client side.
If the function is awaited, the result of the method call is returned.
Expand All @@ -403,8 +406,7 @@ def run_method(self, name: str, *args: Any, timeout: float = 1, check_interval:
"""
if not core.loop:
return NullResponse()
return self.client.run_javascript(f'return runMethod({self.id}, "{name}", {json.dumps(args)})',
timeout=timeout, check_interval=check_interval)
return self.client.run_javascript(f'return runMethod({self.id}, "{name}", {json.dumps(args)})', timeout=timeout)

def get_computed_prop(self, prop_name: str, *, timeout: float = 1) -> AwaitableResponse:
"""Return a computed property.
Expand Down
26 changes: 7 additions & 19 deletions nicegui/elements/aggrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ def update(self) -> None:
super().update()
self.run_method('update_grid')

def call_api_method(self, name: str, *args, timeout: float = 1, check_interval: float = 0.01) -> AwaitableResponse:
"""DEPRECATED: Use `run_grid_method` instead."""
return self.run_grid_method(name, *args, timeout=timeout, check_interval=check_interval)

def run_grid_method(self, name: str, *args, timeout: float = 1, check_interval: float = 0.01) -> AwaitableResponse:
def run_grid_method(self, name: str, *args, timeout: float = 1) -> AwaitableResponse:
"""Run an AG Grid API method.
See `AG Grid API <https://www.ag-grid.com/javascript-data-grid/grid-api/>`_ for a list of methods.
Expand All @@ -110,14 +106,9 @@ def run_grid_method(self, name: str, *args, timeout: float = 1, check_interval:
:return: AwaitableResponse that can be awaited to get the result of the method call
"""
return self.run_method('run_grid_method', name, *args, timeout=timeout, check_interval=check_interval)

def call_column_method(self, name: str, *args, timeout: float = 1, check_interval: float = 0.01) -> AwaitableResponse:
"""DEPRECATED: Use `run_column_method` instead."""
return self.run_column_method(name, *args, timeout=timeout, check_interval=check_interval)
return self.run_method('run_grid_method', name, *args, timeout=timeout)

def run_column_method(self, name: str, *args,
timeout: float = 1, check_interval: float = 0.01) -> AwaitableResponse:
def run_column_method(self, name: str, *args, timeout: float = 1) -> AwaitableResponse:
"""Run an AG Grid Column API method.
See `AG Grid Column API <https://www.ag-grid.com/javascript-data-grid/column-api/>`_ for a list of methods.
Expand All @@ -131,10 +122,9 @@ def run_column_method(self, name: str, *args,
:return: AwaitableResponse that can be awaited to get the result of the method call
"""
return self.run_method('run_column_method', name, *args, timeout=timeout, check_interval=check_interval)
return self.run_method('run_column_method', name, *args, timeout=timeout)

def run_row_method(self, row_id: str, name: str, *args,
timeout: float = 1, check_interval: float = 0.01) -> AwaitableResponse:
def run_row_method(self, row_id: str, name: str, *args, timeout: float = 1) -> AwaitableResponse:
"""Run an AG Grid API method on a specific row.
See `AG Grid Row Reference <https://www.ag-grid.com/javascript-data-grid/row-object/>`_ for a list of methods.
Expand All @@ -149,7 +139,7 @@ def run_row_method(self, row_id: str, name: str, *args,
:return: AwaitableResponse that can be awaited to get the result of the method call
"""
return self.run_method('run_row_method', row_id, name, *args, timeout=timeout, check_interval=check_interval)
return self.run_method('run_row_method', row_id, name, *args, timeout=timeout)

async def get_selected_rows(self) -> List[Dict]:
"""Get the currently selected rows.
Expand Down Expand Up @@ -177,7 +167,6 @@ async def get_client_data(
self,
*,
timeout: float = 1,
check_interval: float = 0.01,
method: Literal['all_unsorted', 'filtered_unsorted', 'filtered_sorted', 'leaf'] = 'all_unsorted'
) -> List[Dict]:
"""Get the data from the client including any edits made by the client.
Expand All @@ -190,7 +179,6 @@ async def get_client_data(
This does not happen when the cell loses focus, unless ``stopEditingWhenCellsLoseFocus: True`` is set.
:param timeout: timeout in seconds (default: 1 second)
:param check_interval: interval in seconds to check for the result (default: 0.01 seconds)
:param method: method to access the data, "all_unsorted" (default), "filtered_unsorted", "filtered_sorted", "leaf"
:return: list of row data
Expand All @@ -205,7 +193,7 @@ async def get_client_data(
const rowData = [];
getElement({self.id}).gridOptions.api.{API_METHODS[method]}(node => rowData.push(node.data));
return rowData;
''', timeout=timeout, check_interval=check_interval)
''', timeout=timeout)
return cast(List[Dict], result)

async def load_client_data(self) -> None:
Expand Down
5 changes: 0 additions & 5 deletions nicegui/elements/chart.py

This file was deleted.

5 changes: 2 additions & 3 deletions nicegui/elements/echart.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ def update(self) -> None:
super().update()
self.run_method('update_chart')

def run_chart_method(self, name: str, *args, timeout: float = 1,
check_interval: float = 0.01) -> AwaitableResponse:
def run_chart_method(self, name: str, *args, timeout: float = 1) -> AwaitableResponse:
"""Run a method of the JSONEditor instance.
See the `ECharts documentation <https://echarts.apache.org/en/api.html#echartsInstance>`_ for a list of methods.
Expand All @@ -114,4 +113,4 @@ def run_chart_method(self, name: str, *args, timeout: float = 1,
:return: AwaitableResponse that can be awaited to get the result of the method call
"""
return self.run_method('run_chart_method', name, *args, timeout=timeout, check_interval=check_interval)
return self.run_method('run_chart_method', name, *args, timeout=timeout)
5 changes: 2 additions & 3 deletions nicegui/elements/json_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ def update(self) -> None:
super().update()
self.run_method('update_editor')

def run_editor_method(self, name: str, *args, timeout: float = 1,
check_interval: float = 0.01) -> AwaitableResponse:
def run_editor_method(self, name: str, *args, timeout: float = 1) -> AwaitableResponse:
"""Run a method of the JSONEditor instance.
See the `JSONEditor README <https://github.com/josdejong/svelte-jsoneditor/>`_ for a list of methods.
Expand All @@ -71,4 +70,4 @@ def run_editor_method(self, name: str, *args, timeout: float = 1,
:return: AwaitableResponse that can be awaited to get the result of the method call
"""
return self.run_method('run_editor_method', name, *args, timeout=timeout, check_interval=check_interval)
return self.run_method('run_editor_method', name, *args, timeout=timeout)
12 changes: 6 additions & 6 deletions nicegui/elements/leaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ async def _handle_zoomend(self, e: GenericEventArguments) -> None:
await asyncio.sleep(0.02) # NOTE: wait for center to be updated as well
self.zoom = e.args['zoom']

def run_method(self, name: str, *args: Any, timeout: float = 1, check_interval: float = 0.01) -> AwaitableResponse:
def run_method(self, name: str, *args: Any, timeout: float = 1) -> AwaitableResponse:
if not self.is_initialized:
return NullResponse()
return super().run_method(name, *args, timeout=timeout, check_interval=check_interval)
return super().run_method(name, *args, timeout=timeout)

def set_center(self, center: Tuple[float, float]) -> None:
"""Set the center location of the map."""
Expand All @@ -122,7 +122,7 @@ def clear_layers(self) -> None:
self.layers.clear()
self.run_method('clear_layers')

def run_map_method(self, name: str, *args, timeout: float = 1, check_interval: float = 0.01) -> AwaitableResponse:
def run_map_method(self, name: str, *args, timeout: float = 1) -> AwaitableResponse:
"""Run a method of the Leaflet map instance.
Refer to the `Leaflet documentation <https://leafletjs.com/reference.html#map-methods-for-modifying-map-state>`_ for a list of methods.
Expand All @@ -136,9 +136,9 @@ def run_map_method(self, name: str, *args, timeout: float = 1, check_interval: f
:return: AwaitableResponse that can be awaited to get the result of the method call
"""
return self.run_method('run_map_method', name, *args, timeout=timeout, check_interval=check_interval)
return self.run_method('run_map_method', name, *args, timeout=timeout)

def run_layer_method(self, layer_id: str, name: str, *args, timeout: float = 1, check_interval: float = 0.01) -> AwaitableResponse:
def run_layer_method(self, layer_id: str, name: str, *args, timeout: float = 1) -> AwaitableResponse:
"""Run a method of a Leaflet layer.
If the function is awaited, the result of the method call is returned.
Expand All @@ -151,7 +151,7 @@ def run_layer_method(self, layer_id: str, name: str, *args, timeout: float = 1,
:return: AwaitableResponse that can be awaited to get the result of the method call
"""
return self.run_method('run_layer_method', layer_id, name, *args, timeout=timeout, check_interval=check_interval)
return self.run_method('run_layer_method', layer_id, name, *args, timeout=timeout)

def _handle_delete(self) -> None:
binding.remove(self.layers)
Expand Down
4 changes: 2 additions & 2 deletions nicegui/elements/leaflet_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __post_init__(self) -> None:
def to_dict(self) -> dict:
"""Return a dictionary representation of the layer."""

def run_method(self, name: str, *args: Any, timeout: float = 1, check_interval: float = 0.01) -> AwaitableResponse:
def run_method(self, name: str, *args: Any, timeout: float = 1) -> AwaitableResponse:
"""Run a method of the Leaflet layer.
If the function is awaited, the result of the method call is returned.
Expand All @@ -41,4 +41,4 @@ def run_method(self, name: str, *args: Any, timeout: float = 1, check_interval:
:return: AwaitableResponse that can be awaited to get the result of the method call
"""
return self.leaflet.run_method('run_layer_method', self.id, name, *args, timeout=timeout, check_interval=check_interval)
return self.leaflet.run_method('run_layer_method', self.id, name, *args, timeout=timeout)
2 changes: 2 additions & 0 deletions nicegui/elements/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def add_rows(self, rows: List[Dict], *args: Any) -> None:
"""Add rows to the table."""
if isinstance(rows, dict): # DEPRECATED
warn_once('Calling add_rows() with variable-length arguments is deprecated. '
'This option will be removed in NiceGUI 3.0. '
'Pass a list instead or use add_row() for a single row.')
rows = [rows, *args]
self.rows.extend(rows)
Expand All @@ -285,6 +286,7 @@ def remove_rows(self, rows: List[Dict], *args: Any) -> None:
"""Remove rows from the table."""
if isinstance(rows, dict): # DEPRECATED
warn_once('Calling remove_rows() with variable-length arguments is deprecated. '
'This option will be removed in NiceGUI 3.0. '
'Pass a list instead or use remove_row() for a single row.')
rows = [rows, *args]
keys = [row[self.row_key] for row in rows]
Expand Down
8 changes: 2 additions & 6 deletions nicegui/functions/javascript.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from typing import Optional

from ..awaitable_response import AwaitableResponse
from ..context import context


def run_javascript(code: str, *,
respond: Optional[bool] = None,
timeout: float = 1.0, check_interval: float = 0.01) -> AwaitableResponse:
def run_javascript(code: str, *, timeout: float = 1.0) -> AwaitableResponse:
"""Run JavaScript
This function runs arbitrary JavaScript code on a page that is executed in the browser.
Expand All @@ -23,4 +19,4 @@ def run_javascript(code: str, *,
:return: AwaitableResponse that can be awaited to get the result of the JavaScript code
"""
return context.client.run_javascript(code, respond=respond, timeout=timeout, check_interval=check_interval)
return context.client.run_javascript(code, timeout=timeout)
9 changes: 0 additions & 9 deletions nicegui/functions/open.py

This file was deleted.

16 changes: 0 additions & 16 deletions nicegui/functions/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,6 @@
from .html import add_head_html


def add_style(content: Union[str, Path], indented: bool = False) -> None: # DEPRECATED
"""Add style definitions to the page. [DEPRECATED]
Note:
This function is deprecated, because it can't reliably detect the style language.
Use `add_css`, `add_scss` or `add_sass` instead.
"""
if helpers.is_file(content):
content = Path(content).read_text()
if optional_features.has('sass'):
content = sass.compile(string=str(content).strip(), indented=indented)
helpers.warn_once("`ui.add_style` is deprecated, because it can't reliably detect the style language. "
'Use `ui.add_css`, `ui.add_scss` or `ui.add_sass` instead.')
add_head_html(f'<style>{content}</style>')


def add_css(content: Union[str, Path]) -> None:
"""Add CSS style definitions to the page.
Expand Down
Loading

0 comments on commit 223c9df

Please sign in to comment.