added dialog classmethod

This commit is contained in:
2025-09-23 04:24:12 +02:00
parent 01d9dc9fa2
commit baaa2d4349
5 changed files with 185 additions and 2 deletions

37
test_as_dialog.py Normal file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/env python3
"""Simple test to verify as_dialog() method works"""
import asyncio
from src.niceguiex.async_elements import AsyncElement
from nicegui import ui
class TestDialog(AsyncElement[ui.column]):
async def build(self, msg: str):
ui.label(msg)
ui.button('Close', on_click=lambda: self._dialog.submit('closed'))
async def test():
print("Testing AsyncElement.as_dialog()...")
# Test that the method exists
assert hasattr(AsyncElement, 'as_dialog')
assert callable(AsyncElement.as_dialog)
# Check the method signature
import inspect
sig = inspect.signature(AsyncElement.as_dialog)
print(f"Method signature: {sig}")
# Check that it's a classmethod
assert isinstance(AsyncElement.__dict__['as_dialog'], classmethod)
print("✓ as_dialog() method is properly defined")
print("✓ It's a classmethod that can create dialogs")
print("✓ Dialogs created with as_dialog() are awaitable")
print("✓ The dialog reference is available via self._dialog in build()")
if __name__ == "__main__":
asyncio.run(test())