From 6a91bc3e34b071ab41698664292b405bb34e0f77 Mon Sep 17 00:00:00 2001 From: trgiangdo Date: Tue, 24 Dec 2024 16:09:11 +0700 Subject: [PATCH 1/2] feature: convert templates from markdown to tgb --- .../default/hooks/post_gen_project.py | 18 +++++++--------- .../pages/page_example/page_example.md | 1 - .../pages/page_example/page_example.py | 9 ++++---- .../pages/root.md | 3 --- .../pages/root.py | 9 ++++---- .../pages/job_page/job_page.md | 1 - .../pages/job_page/job_page.py | 5 +++-- .../pages/root.md | 21 ------------------- .../pages/root.py | 17 +++++++++++++-- .../pages/scenario_page/scenario_page.md | 12 ----------- .../pages/scenario_page/scenario_page.py | 17 +++++++++++++-- 11 files changed, 50 insertions(+), 63 deletions(-) delete mode 100644 taipy/templates/default/{{cookiecutter.__root_folder}}/pages/page_example/page_example.md delete mode 100644 taipy/templates/default/{{cookiecutter.__root_folder}}/pages/root.md delete mode 100644 taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/job_page/job_page.md delete mode 100644 taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/root.md delete mode 100644 taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/scenario_page/scenario_page.md diff --git a/taipy/templates/default/hooks/post_gen_project.py b/taipy/templates/default/hooks/post_gen_project.py index b0d4b7452b..8a15f418b3 100644 --- a/taipy/templates/default/hooks/post_gen_project.py +++ b/taipy/templates/default/hooks/post_gen_project.py @@ -77,33 +77,29 @@ def handle_single_page_app(): main_file.write("\n") main_file.write(" gui = Gui(page=page)\n") + with open(os.path.join(os.getcwd(), "sections", "import.txt"), "a") as import_file: + import_file.write("import taipy.gui.builder as tgb\n") + handle_run_service() with open(os.path.join(os.getcwd(), "sections", "page_content.txt"), "a") as page_content_file: page_content_file.write( - ''' -page = """ -
-<|navbar|lov={[("home", "Homepage")]}|> -
+ """ +with tgb.Page() as page: + tgb.navbar(lov="{[('home', 'Homepage')]}") """ -''' ) def handle_multi_page_app(pages): for page_name in pages: os.mkdir(os.path.join(os.getcwd(), "pages", page_name)) - with open(os.path.join(os.getcwd(), "pages", "page_example", "page_example.md"), "r") as page_md_file: - page_md_content = page_md_file.read() - page_md_content = page_md_content.replace("Page example", page_name.replace("_", " ").title()) - with open(os.path.join(os.getcwd(), "pages", page_name, page_name + ".md"), "w") as page_md_file: - page_md_file.write(page_md_content) with open(os.path.join(os.getcwd(), "pages", "page_example", "page_example.py"), "r") as page_content_file: page_py_content = page_content_file.read() page_py_content = page_py_content.replace("page_example", page_name) + page_py_content = page_py_content.replace("Page example", page_name.replace("_", " ").title()) with open(os.path.join(os.getcwd(), "pages", page_name, page_name + ".py"), "w") as page_content_file: page_content_file.write(page_py_content) diff --git a/taipy/templates/default/{{cookiecutter.__root_folder}}/pages/page_example/page_example.md b/taipy/templates/default/{{cookiecutter.__root_folder}}/pages/page_example/page_example.md deleted file mode 100644 index dc0bea2fd6..0000000000 --- a/taipy/templates/default/{{cookiecutter.__root_folder}}/pages/page_example/page_example.md +++ /dev/null @@ -1 +0,0 @@ -# Page example diff --git a/taipy/templates/default/{{cookiecutter.__root_folder}}/pages/page_example/page_example.py b/taipy/templates/default/{{cookiecutter.__root_folder}}/pages/page_example/page_example.py index ef4753a531..815ce14f05 100644 --- a/taipy/templates/default/{{cookiecutter.__root_folder}}/pages/page_example/page_example.py +++ b/taipy/templates/default/{{cookiecutter.__root_folder}}/pages/page_example/page_example.py @@ -11,11 +11,12 @@ """ A page of the application. -Page content is imported from the page_example.md file. +Page content is built using the Page builder API. -Please refer to https://docs.taipy.io/en/latest/manuals/userman/gui/pages for more details. +Please refer to https://docs.taipy.io/en/latest/userman/gui/pages/builder/ for more details. """ -from taipy.gui import Markdown +import taipy.gui.builder as tgb -page_example = Markdown("pages/page_example/page_example.md") +with tgb.Page() as page_example: + tgb.text("# Page example", mode="md") diff --git a/taipy/templates/default/{{cookiecutter.__root_folder}}/pages/root.md b/taipy/templates/default/{{cookiecutter.__root_folder}}/pages/root.md deleted file mode 100644 index 0216ecc457..0000000000 --- a/taipy/templates/default/{{cookiecutter.__root_folder}}/pages/root.md +++ /dev/null @@ -1,3 +0,0 @@ -
-<|navbar|> -
diff --git a/taipy/templates/default/{{cookiecutter.__root_folder}}/pages/root.py b/taipy/templates/default/{{cookiecutter.__root_folder}}/pages/root.py index 315af8fef9..e06d6ae197 100644 --- a/taipy/templates/default/{{cookiecutter.__root_folder}}/pages/root.py +++ b/taipy/templates/default/{{cookiecutter.__root_folder}}/pages/root.py @@ -11,11 +11,12 @@ """ The root page of the application. -Page content is imported from the root.md file. +Page content is built using the Page builder API. -Please refer to https://docs.taipy.io/en/latest/manuals/userman/gui/pages for more details. +Please refer to https://docs.taipy.io/en/latest/userman/gui/pages/builder/ for more details. """ -from taipy.gui import Markdown +import taipy.gui.builder as tgb -root_page = Markdown("pages/root.md") +with tgb.Page() as root_page: + tgb.navbar() diff --git a/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/job_page/job_page.md b/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/job_page/job_page.md deleted file mode 100644 index b498167e96..0000000000 --- a/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/job_page/job_page.md +++ /dev/null @@ -1 +0,0 @@ -<|job_selector|> diff --git a/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/job_page/job_page.py b/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/job_page/job_page.py index ec441907f2..3e474ee45b 100644 --- a/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/job_page/job_page.py +++ b/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/job_page/job_page.py @@ -9,6 +9,7 @@ # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -from taipy.gui import Markdown +import taipy.gui.builder as tgb -job_page = Markdown("pages/job_page/job_page.md") +with tgb.Page() as job_page: + tgb.job_selector() diff --git a/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/root.md b/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/root.md deleted file mode 100644 index 994124b8fd..0000000000 --- a/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/root.md +++ /dev/null @@ -1,21 +0,0 @@ -<|layout|columns=1 5| - -<|sidebar| - -<|{selected_scenario}|scenario_selector|> - -<|part|render={selected_scenario}| -<|{selected_data_node}|data_node_selector|not display_cycles|> -|> -|> - -<|part|class_name=main| - -<|navbar|> - -<|part|class_name=main| -<|content|> -|> - -|> -|> diff --git a/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/root.py b/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/root.py index decba81cc1..f36e200a83 100644 --- a/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/root.py +++ b/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/root.py @@ -9,10 +9,23 @@ # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -from taipy.gui import Markdown +import taipy.gui.builder as tgb selected_scenario = None selected_data_node = None content = "" -root = Markdown("pages/root.md") + +with tgb.Page() as root: + with tgb.layout(columns="1, 5"): + with tgb.part(class_name="sidebar"): + tgb.scenario_selector("{selected_scenario}") + + with tgb.part(render="{selected_scenario}"): + tgb.data_node_selector("{selected_data_node}", display_cycles=False) + + with tgb.part(class_name="main"): + tgb.navbar() + + with tgb.part(class_name="main"): + tgb.text("{content}") diff --git a/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/scenario_page/scenario_page.md b/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/scenario_page/scenario_page.md deleted file mode 100644 index 6c26000f84..0000000000 --- a/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/scenario_page/scenario_page.md +++ /dev/null @@ -1,12 +0,0 @@ -<|layout|columns=1 1| - -<|part|render={selected_scenario}| - -<|{selected_scenario}|scenario|not expandable|expanded|on_submission_change=notify_on_submission|> - -<|{selected_scenario}|scenario_dag|> -|> - -<|part|partial={data_node_partial}|render={selected_data_node}|> - -|> diff --git a/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/scenario_page/scenario_page.py b/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/scenario_page/scenario_page.py index 1970a5cc36..12666cfcd3 100644 --- a/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/scenario_page/scenario_page.py +++ b/taipy/templates/sdm/{{cookiecutter.__root_folder}}/pages/scenario_page/scenario_page.py @@ -9,7 +9,8 @@ # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. -from taipy.gui import Markdown, notify +import taipy.gui.builder as tgb +from taipy.gui import notify from .data_node_management import manage_partial @@ -27,4 +28,16 @@ def manage_data_node_partial(state): manage_partial(state) -scenario_page = Markdown("pages/scenario_page/scenario_page.md") +with tgb.Page() as scenario_page: + with tgb.layout(columns="1, 1"): + with tgb.part(render="{selected_scenario}"): + tgb.scenario( + "{selected_scenario}", + expandable=False, + expanded=True, + on_submission_change=notify_on_submission, + ) + + tgb.scenario_dag("{selected_scenario}") + + tgb.part(partial="{data_node_partial}", render="{selected_data_node}") From 6b65e0115ff6d4e562ff90c3b919a81760e3ead4 Mon Sep 17 00:00:00 2001 From: trgiangdo Date: Wed, 25 Dec 2024 10:09:03 +0700 Subject: [PATCH 2/2] fix: remove checking for markdown file in template test --- tests/templates/test_default_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/templates/test_default_template.py b/tests/templates/test_default_template.py index 4ea044cc75..c6d85b8f92 100644 --- a/tests/templates/test_default_template.py +++ b/tests/templates/test_default_template.py @@ -145,7 +145,7 @@ def test_multipage_gui_template(tmpdir): assert sorted(os.listdir(os.path.join(tmpdir, "foo_app"))) == sorted(["requirements.txt", "main.py", "pages"]) assert sorted(os.listdir(os.path.join(tmpdir, "foo_app", "pages"))) == sorted( - ["name_1", "name_2", "name_3", "root.md", "root.py", "__init__.py"] + ["name_1", "name_2", "name_3", "root.py", "__init__.py"] ) taipy_path = os.getcwd()