Avaiga / taipy

Turns Data and AI algorithms into production-ready web applications in no time.
https://www.taipy.io
Apache License 2.0
10.94k stars 775 forks source link

[🐛 BUG] Cannot use Page Builder's dialog() in a context manager #1387

Closed FlorianJacta closed 2 months ago

FlorianJacta commented 2 months ago

What went wrong? 🤔

It is not possible to use the dialog as a block.

Traceback (most recent call last):
  File "c:\Users\jacta\OneDrive\Bureau\taipy\Code\TTT-SDM-Interview\src_complete\h.py", line 8, in <module>
    with tgb.dialog(open="{open_modal}"):
  File "C:\Users\jacta\.conda\envs\develop\lib\site-packages\taipy\gui\builder\_element.py", line 189, in __enter__
    raise RuntimeError(f"Can't use Context Manager for control type '{self._ELEMENT_NAME}'")
RuntimeError: Can't use Context Manager for control type 'dialog'

Expected Behavior

We should be able to use the syntax below because dialog() is not a Context Manager.

Steps to Reproduce Issue

from taipy import Core, Gui
import taipy.gui.builder as tgb

open_modal = False

with tgb.Page() as page:
    with tgb.dialog(open="{open_modal}"):
        tgb.text("Hello")

if __name__ == "__main__":
    gui = Gui(page=page)
    gui.run(title="Sales Prediction", port=1221)

Version of Taipy

develop - 6/10/24 (M/D/Y)

Code of Conduct

yaten2302 commented 2 months ago

Hey @FlorianJacta, I would like to work on this issue, could you please assign it to me? Also, could you please elaborate a bit on using 'dialog as a block'. I've understood this partially, but I'm not able to completely understand that what exactly is the problem? As far as I've understood according to taipy docs, the on_action property return -1, 0, 1 or for closing, validating, cancelling respectively, am I right?

FlorianJacta commented 2 months ago

@yaten2302 I have updated the issue. The problem is that you cannot use it inside the context manager. I will show you the Markdown syntax and the Python API.

Markdown syntax that works:

page = """
<|dialog|open={open_modal}|
Hello
|>
"""

Here, it is not working with a with.

with tgb.Page() as page:
    with tgb.dialog(open="{open_modal}"):
        tgb.text("Hello")

We will maybe put this issue in Staff Only.

yaten2302 commented 2 months ago

I'll try to work on some other issues, if this one is Staff Only 👍

FredLL-Avaiga commented 2 months ago

The problem here is that dialog is a control and a block