Replies: 7 comments
-
So, is there a better way to scroll the page? |
Beta Was this translation helpful? Give feedback.
-
It's not issue |
Beta Was this translation helpful? Give feedback.
-
Although this is not a issue, it was functioning properly in versions before 2.20. Currently, I want that when I open a dialog box, clicking the button inside the dialog will pop up a second dialog box and close the first one. Now it shows a message that the element has been deleted. |
Beta Was this translation helpful? Give feedback.
-
from nicegui import ui
def replace(dialog1,title,btn1,btn2):
try:
dialog1.clear()
except:
pass
with dialog1, ui.card().classes('absolute-center items-center'):
ui.label(title)
with ui.row():
ui.button(btn1, on_click=lambda: dialog1.submit('Yes')).props('style="text-transform: none;"')
ui.button(btn2, on_click=lambda: dialog1.submit('No')).props('style="text-transform: none;"')
dialog1.open()
def Func_Menu():
with ui.dialog() as dialog1, ui.card().classes('w-32 h-32 absolute-center items-center'):
ui.label("")
dialog1.clear()
async def operateLog():
replace(dialog1,"test","yes","no")
result = await dialog1
if result == "Yes" :
print("test")
async def tant():
replace(dialog1,"One","yes", "no")
result = await dialog1
if result == "Yes" :
ui.notify(f"Test1! ")
elif result == "No":
ui.notify(f"Test2! ")
with dialog1, ui.card().classes(''):
ui.label("")
navigation = ui.grid(columns=3).classes('w-full gap-2 text-sm')
with navigation:
ui.button("logs", on_click=operateLog)
ui.button("tant", on_click=tant)
dialog1.open()
@ui.page('/')
def main_page():
ui.button("Open_Dialog", on_click=Func_Menu)
if __name__ in {"__main__", "__mp_main__"}:
ui.run()
|
Beta Was this translation helpful? Give feedback.
-
I'm having difficulty reading the code on mobile right now. I'll give high-level comments. NiceGUI 2.21.0, #4938, we got rid of the circular references and the reference counting mechanism will remove the element immediately once nobody reference it. It is the number-1 cause for code breaking on 2.21+ while works on 2.20 and below. It is not technically NiceGUI problem since your code could still break on 2.20 if the garbage collector runs in just the right moment. You can argue NiceGUI got more strict, though. Code which breaks 1% of the time in 2.20 may break 100% of the time in 2.21+. I think it's the right thing to do, still. The course of action is to properly manage the references to the element. Large language models may help you with that. Feed it #4938 for additional context. |
Beta Was this translation helpful? Give feedback.
-
Hello @sonicno1. I got time to read your code. Reading #5134 (comment), the issue, as it turns out, is not in the scroll-to-bottom (in fact scroll-to-bottom is not in that snippet at all). Rather, it has to do with how you are using I still can't debug why your code, the parent slot is deleted. I'm not that good at reference counter to be honest. I can offer a fix though: the from nicegui import ui
from nicegui.events import ClickEventArguments
def replace(dialog1, title, btn1, btn2):
try:
dialog1.clear()
except:
pass
with dialog1, ui.card().classes('absolute-center items-center'):
ui.label(title)
with ui.row():
ui.button(btn1, on_click=lambda: dialog1.submit('Yes')).props('style="text-transform: none;"')
ui.button(btn2, on_click=lambda: dialog1.submit('No')).props('style="text-transform: none;"')
dialog1.open()
def Func_Menu():
with ui.dialog() as dialog1, ui.card().classes('w-32 h-32 absolute-center items-center'):
ui.label('')
dialog1.clear()
async def operateLog():
replace(dialog1, 'test', 'yes', 'no')
result = await dialog1
if result == 'Yes':
print('test')
async def tant(e: ClickEventArguments): # PATCH HERE
replace(dialog1, 'One', 'yes', 'no')
result = await dialog1
if result == 'Yes':
with e.client: # PATCH HERE
ui.notify(f'Test1! ')
elif result == 'No':
with e.client: # PATCH HERE
ui.notify(f'Test2! ')
with dialog1, ui.card().classes(''):
ui.label('')
navigation = ui.grid(columns=3).classes('w-full gap-2 text-sm')
with navigation:
ui.button('logs', on_click=operateLog)
ui.button('tant', on_click=tant)
dialog1.open()
@ui.page('/')
def main_page():
ui.button('Open_Dialog', on_click=Func_Menu)
if __name__ in {'__main__', '__mp_main__'}:
ui.run() |
Beta Was this translation helpful? Give feedback.
-
Hello @evnchn , thank you very much for the patch you provided, it works great. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Example Code
Description
When I use the dialog popup, it errors when scrolling to the bottom.
NiceGUI Version
2.24.0
Python Version
3.9
Browser
Chrome
Operating System
Windows
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions