|
@@ -4,7 +4,7 @@ from typing import Awaitable, Callable, Union
|
|
import justpy as jp
|
|
import justpy as jp
|
|
|
|
|
|
from .element import Element
|
|
from .element import Element
|
|
-from ..utils import handle_exceptions, provide_arguments, EventArguments
|
|
|
|
|
|
+from ..utils import handle_exceptions, provide_arguments, async_provide_arguments
|
|
|
|
|
|
class Button(Element):
|
|
class Button(Element):
|
|
|
|
|
|
@@ -20,29 +20,14 @@ class Button(Element):
|
|
"""
|
|
"""
|
|
|
|
|
|
view = jp.QButton(label=text, color='primary')
|
|
view = jp.QButton(label=text, color='primary')
|
|
|
|
+ super().__init__(view)
|
|
|
|
|
|
if on_click is not None:
|
|
if on_click is not None:
|
|
if asyncio.iscoroutinefunction(on_click):
|
|
if asyncio.iscoroutinefunction(on_click):
|
|
-
|
|
|
|
- def async_provide_arguments(func, *keys):
|
|
|
|
- def inner_function(sender, event):
|
|
|
|
- async def execute_function():
|
|
|
|
- try:
|
|
|
|
- await func()
|
|
|
|
- except TypeError:
|
|
|
|
- await func(EventArguments(sender, **{key: event[key] for key in keys}))
|
|
|
|
-
|
|
|
|
- await self.parent_view.update()
|
|
|
|
-
|
|
|
|
- asyncio.get_event_loop().create_task(execute_function())
|
|
|
|
- return inner_function
|
|
|
|
-
|
|
|
|
- view.on('click', handle_exceptions(async_provide_arguments(on_click)))
|
|
|
|
|
|
+ view.on('click', handle_exceptions(async_provide_arguments(func=on_click, update_function=view.update)))
|
|
else:
|
|
else:
|
|
view.on('click', handle_exceptions(provide_arguments(on_click)))
|
|
view.on('click', handle_exceptions(provide_arguments(on_click)))
|
|
|
|
|
|
- super().__init__(view)
|
|
|
|
-
|
|
|
|
@property
|
|
@property
|
|
def text(self):
|
|
def text(self):
|
|
return self.view.label
|
|
return self.view.label
|