Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on_window_event isnt handled after page navigation #2081

Closed
LipmanJon opened this issue Nov 13, 2023 · 2 comments
Closed

on_window_event isnt handled after page navigation #2081

LipmanJon opened this issue Nov 13, 2023 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@LipmanJon
Copy link

Description

It seems that on_window_event doesn't trigger after navigating to a new view.
It seems to be a regression - on version 0.10.3 it works, but breaks on 0.12.0.

Code example to reproduce the issue:

import flet as ft


def main(page: ft.Page):
    page.title = "Routes Example"

    def route_change(route):
        page.views.clear()
        page.views.append(
            ft.View(
                "/",
                [
                    ft.AppBar(title=ft.Text("Flet app"), bgcolor=ft.colors.SURFACE_VARIANT),
                    ft.ElevatedButton("Visit Store", on_click=lambda _: page.go("/store")),
                ],
            )
        )
        if page.route == "/store":
            page.views.append(
                ft.View(
                    "/store",
                    [
                        ft.AppBar(title=ft.Text("Store"), bgcolor=ft.colors.SURFACE_VARIANT),
                        ft.ElevatedButton("Go Home", on_click=lambda _: page.go("/")),
                    ],
                )
            )
        page.update()

    def view_pop(view):
        page.views.pop()
        top_view = page.views[-1]
        page.go(top_view.route)

    def window_event(e):
        print(f"window event: {e}")
        if e.data == "close":
            page.window_destroy()

    page.window_prevent_close = True
    page.on_window_event = window_event

    page.on_route_change = route_change
    page.on_view_pop = view_pop
    page.go(page.route)


if __name__ == '__main__':
    ft.app(target=main)

Describe the results you received:
Original view allows to exit, but once a new view is appeneded then the window X exit button has no effect and doesnt trigger the on_window_event func.
Navigating back to the home view unblocks the exit button.

Describe the results you expected:
Exit should work regardless of view added.

Additional information you deem important (e.g. issue happens only occasionally):
Version 0.10.3 doesn't have this issue

Flet version (pip show flet):

0.12.0

Operating system:
Reproduced on macos + windows 10

Additional environment details:

@LipmanJon
Copy link
Author

@DanielShwartz1 @Mache-Hoffman
Follow if interested

@FeodorFitsner FeodorFitsner added the bug Something isn't working label Nov 13, 2023
@FeodorFitsner
Copy link
Contributor

Related to #2082. Working on a fix.

@FeodorFitsner FeodorFitsner added this to the Flet v0.12.1 milestone Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants