Skip to content

Commit

Permalink
#1518 change type of GenericEventArguments.args to Any
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Aug 29, 2023
1 parent 33702b3 commit 3b3aed2
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions nicegui/elements/color_picker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Callable, cast
from typing import Any, Callable

from ..element import Element
from ..events import ColorPickEventArguments, GenericEventArguments, handle_event
Expand All @@ -16,7 +16,7 @@ def __init__(self, *, on_pick: Callable[..., Any], value: bool = False) -> None:
super().__init__(value=value)
with self:
def handle_change(e: GenericEventArguments):
handle_event(on_pick, ColorPickEventArguments(sender=self, client=self.client, color=cast(str, e.args)))
handle_event(on_pick, ColorPickEventArguments(sender=self, client=self.client, color=e.args))
self.q_color = Element('q-color').on('change', handle_change)

def set_color(self, color: str) -> None:
Expand Down
23 changes: 12 additions & 11 deletions nicegui/elements/interactive_image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from pathlib import Path
from typing import Any, Callable, List, Optional, Union
from typing import Any, Callable, List, Optional, Union, cast

from ..events import GenericEventArguments, MouseEventArguments, handle_event
from .mixins.content_element import ContentElement
Expand All @@ -27,7 +27,7 @@ def __init__(self,
See `OpenCV Webcam <https://github.com/zauberzeug/nicegui/tree/main/examples/opencv_webcam/main.py>`_ for an example.
:param source: the source of the image; can be an URL, local file path or a base64 string
:param content: SVG content which should be overlayed; viewport has the same dimensions as the image
:param content: SVG content which should be overlaid; viewport has the same dimensions as the image
:param on_mouse: callback for mouse events (yields `type`, `image_x` and `image_y`)
:param events: list of JavaScript events to subscribe to (default: `['click']`)
:param cross: whether to show crosshairs (default: `False`)
Expand All @@ -39,18 +39,19 @@ def __init__(self,
def handle_mouse(e: GenericEventArguments) -> None:
if on_mouse is None:
return
args = cast(dict, e.args)
arguments = MouseEventArguments(
sender=self,
client=self.client,
type=e.args.get('mouse_event_type', ''),
image_x=e.args.get('image_x', 0.0),
image_y=e.args.get('image_y', 0.0),
button=e.args.get('button', 0),
buttons=e.args.get('buttons', 0),
alt=e.args.get('alt', False),
ctrl=e.args.get('ctrl', False),
meta=e.args.get('meta', False),
shift=e.args.get('shift', False),
type=args.get('mouse_event_type', ''),
image_x=args.get('image_x', 0.0),
image_y=args.get('image_y', 0.0),
button=args.get('button', 0),
buttons=args.get('buttons', 0),
alt=args.get('alt', False),
ctrl=args.get('ctrl', False),
meta=args.get('meta', False),
shift=args.get('shift', False),
)
handle_event(on_mouse, arguments)
self.on('mouse', handle_mouse)
1 change: 0 additions & 1 deletion nicegui/elements/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def sanitize(self) -> None:
def _event_args_to_value(self, e: GenericEventArguments) -> Any:
if not e.args:
return None
assert isinstance(e.args, str)
return float(e.args)

def _value_to_model_value(self, value: Any) -> Any:
Expand Down
1 change: 0 additions & 1 deletion nicegui/elements/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def __init__(self,
super().__init__(tag='q-option-group', options=options, value=value, on_change=on_change)

def _event_args_to_value(self, e: GenericEventArguments) -> Any:
assert isinstance(e.args, int)
return self._values[e.args]

def _value_to_model_value(self, value: Any) -> Any:
Expand Down
2 changes: 0 additions & 2 deletions nicegui/elements/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def __init__(self,
self._props['clearable'] = clearable

def on_filter(self, e: GenericEventArguments) -> None:
assert isinstance(e.args, str)
self.options = [
option
for option in self.original_options
Expand All @@ -62,7 +61,6 @@ def _event_args_to_value(self, e: GenericEventArguments) -> Any:
if self.multiple:
if e.args is None:
return []
assert isinstance(e.args, list)
return [self._values[arg['value']] for arg in e.args]
else:
if e.args is None:
Expand Down
1 change: 0 additions & 1 deletion nicegui/elements/toggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def __init__(self,
super().__init__(tag='q-btn-toggle', options=options, value=value, on_change=on_change)

def _event_args_to_value(self, e: GenericEventArguments) -> Any:
assert isinstance(e.args, int)
return self._values[e.args]

def _value_to_model_value(self, value: Any) -> Any:
Expand Down
2 changes: 1 addition & 1 deletion nicegui/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class UiEventArguments(EventArguments):

@dataclass(**KWONLY_SLOTS)
class GenericEventArguments(UiEventArguments):
args: Dict[str, Any]
args: Any

def __getitem__(self, key: str) -> Any:
if key == 'args':
Expand Down

0 comments on commit 3b3aed2

Please sign in to comment.