dialog with property

This commit is contained in:
2025-09-23 05:26:18 +02:00
parent 1012cf3d73
commit 02d7513b77
4 changed files with 116 additions and 51 deletions

View File

@@ -10,6 +10,9 @@ class ConfirmDialog(AsyncColumn):
async def build(self, message: str, title: str = "Confirm"):
"""Build the dialog content"""
# Set dialog size using the property
self.dialog_size = 'w-96'
ui.label(title).classes('text-h6')
ui.label(message)
ui.space()
@@ -24,6 +27,10 @@ class FormDialog(AsyncColumn):
async def build(self, title: str = "Enter Information"):
"""Build the form dialog"""
# Set a wider dialog size for the form
if hasattr(self, '_dialog'):
self.dialog_size = 'w-1/2'
ui.label(title).classes('text-h6')
# Create input fields
@@ -93,6 +100,9 @@ async def main():
async def show_inline_dialog():
class QuickDialog(AsyncColumn):
async def build(self):
# Smaller dialog size for simple questions
self.dialog_size = 'w-72'
ui.label('Quick Question').classes('text-h6')
ui.label('Do you like this feature?')
@@ -106,6 +116,30 @@ async def main():
ui.button('Show Quick Dialog', on_click=show_inline_dialog)
# Example with dynamic sizing based on content
async def show_dynamic_dialog():
class DynamicDialog(AsyncColumn):
async def build(self, items_count: int = 3):
# Adjust size based on content
if items_count <= 3:
self.dialog_size = 'w-96'
else:
self.dialog_size = 'w-1/2'
ui.label(f'Dynamic Dialog with {items_count} items').classes('text-h6')
for i in range(items_count):
ui.label(f'Item {i + 1}: This is some content for item {i + 1}')
ui.space()
ui.button('Close', on_click=lambda: self._dialog.submit(f'Closed with {items_count} items'))
for count in [2, 5]:
result = await DynamicDialog.as_dialog(items_count=count)
ui.notify(f'Result: {result}')
ui.button('Show Dynamic Dialogs', on_click=show_dynamic_dialog)
if __name__ in {"__main__", "__mp_main__"}:
ui.run(title='Async Dialog Example', port=8085)