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

Container doesn't dispatch ContainerTapEvent in ver 0.22.0 #3064

Closed
DoctorReid opened this issue Apr 20, 2024 · 4 comments
Closed

Container doesn't dispatch ContainerTapEvent in ver 0.22.0 #3064

DoctorReid opened this issue Apr 20, 2024 · 4 comments
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@DoctorReid
Copy link

Description

Click event of Container is not ContainerTapEvent, so I can't get position like local_x

Code example to reproduce the issue:

self.map_container = ft.Container(content=self.map_img, width=self.large_map_width, height=self.large_map_width,
                                          on_click=self.on_map_click, alignment=ft.alignment.top_left)

Describe the results you received:

<class 'flet_core.control_event.ControlEvent'>
Future exception was never retrieved
future: <Future finished exception=AttributeError("'ControlEvent' object has no attribute 'local_x'")>
Traceback (most recent call last):
File "concurrent\futures\thread.py", line 58, in run
File "F:\code\workspace\StarRailOneDragon.env\venv\Lib\site-packages\flet_core\page.py", line 528, in wrapper
handler(*args)
File "F:\code\workspace\StarRailOneDragon\src\gui\world_patrol\world_patrol_draft_route_view.py", line 400, in on_map_click
x = int(e.local_x / scale)
^^^^^^^^^

Issue doesn't happen in version 0.21.2

Describe the results you expected:

Get ContainerTapEvent

Additional information you deem important (e.g. issue happens only occasionally):

Always

Flet version (pip show flet):

0.22.0

Give your requirements.txt file (don't pip freeze, instead give direct packages):

(The requirements)

Operating system:

Windows 10

Additional environment details:

Python 3.11.3

@ndonkoHenri
Copy link
Collaborator

The functionality was moved to the new on_tap_down instead.
on_click still exists though, but no more has the position props.

Forgot to document that, sorry.

@ndonkoHenri ndonkoHenri added the documentation Improvements or additions to documentation label Apr 20, 2024
@ndonkoHenri ndonkoHenri self-assigned this Apr 20, 2024
@Soif2Sang
Copy link

I would like to add something to this issue:

on_tap_down is not triggered if there is no on_click set

import flet as ft

def main(page: ft.Page):
    page.vertical_alignment = ft.MainAxisAlignment.CENTER
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

    t = ft.Text()

    def container_click(e: ft.ContainerTapEvent):
        t.value = f"local_x: {e.local_x}\nlocal_y: {e.local_y}\nglobal_x: {e.global_x}\nglobal_y: {e.global_y}"
        t.update()

    page.add(
        ft.Column(
            [
                ft.Container(
                    content=ft.Text("Clickable inside container"),
                    alignment=ft.alignment.center,
                    bgcolor=ft.colors.GREEN_200,
                    width=200,
                    height=200,
                    border_radius=10,
                    on_tap_down=container_click,
                    #remove this on_click=lambda _: print()
                ),
                t,
            ],
            horizontal_alignment=ft.CrossAxisAlignment.CENTER,
        ),
    )

ft.app(target=main)

@ndonkoHenri
Copy link
Collaborator

on_tap_down is not triggered if there is no on_click set

Thanks for letting know.
Will be fixed in the next release.

@Sbose548
Copy link

on_tap_down is not triggered if there is no on_click set

Thanks for letting know. Will be fixed in the next release.
#3443

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
Archived in project
Development

No branches or pull requests

4 participants