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

File Picker dialog is not focused when it opens #1074

Open
xylix opened this issue Feb 22, 2023 · 4 comments
Open

File Picker dialog is not focused when it opens #1074

xylix opened this issue Feb 22, 2023 · 4 comments
Labels
enhancement Improvement/Optimization platform: mac Specific to macOS

Comments

@xylix
Copy link

xylix commented Feb 22, 2023

Description

File picker doesn't get focus on macOS when it opens

Code example to reproduce the issue:

Shortened version of https://github.com/flet-dev/examples/blob/main/python/controls/file-picker/file-picker-all-modes.py reproduces the issue:

import flet
from flet import (
    ElevatedButton,
    FilePicker,
    FilePickerResultEvent,
    Page,
    Row,
    Text,
    icons,
)


def main(page: Page):
    # Pick files dialog
    def pick_files_result(e: FilePickerResultEvent):
        selected_files.value = (
            ", ".join(map(lambda f: f.name, e.files)) if e.files else "Cancelled!"
        )
        selected_files.update()

    pick_files_dialog = FilePicker(on_result=pick_files_result)
    selected_files = Text()


    # hide all dialogs in overlay
    page.overlay.extend([pick_files_dialog])

    page.add(
        Row(
            [
                ElevatedButton(
                    "Pick files",
                    icon=icons.UPLOAD_FILE,
                    on_click=lambda _: pick_files_dialog.pick_files(
                        allow_multiple=True
                    ),
                ),
                selected_files,
            ]
        ),
    )


flet.app(target=main)

Describe the results you received:

When the file picker open's it is out of focus. This means that an extra click is required to select files in macOS. (So 3 clicks if you want to double click a file, first to focus and then 2 to select, instead of the 2 clicks expected.)

Describe the results you expected:

The file picker gets focus when it opens.

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

Something like this could work as a workaround if .focus() method was added to the file_picker:

def on_click(event: ControlEvent):
    pick_files_dialog.pick_files(
        allow_multiple=True
    )
    pick_files_dialog.focus()

Flet version (pip show flet):

Name: flet
Version: 0.4.2
Summary: Flet for Python - easily build interactive multi-platform apps in Python
Home-page: 
Author: Appveyor Systems Inc.
Author-email: hello@flet.dev
License: Apache-2.0
Location: /Users/kerkko/Code/tmp/flet-filepicker-focus-test-22-02-2023/venv/lib/python3.11/site-packages
Requires: flet-core, httpx, oauthlib, packaging, watchdog, websocket-client, websockets
Required-by: 

Operating system:

macOS monterey 12.6 (21G115)

Did not test if this also happens in other operating systems.

Additional environment details:

@iron3oxide
Copy link
Contributor

Just tested your code sample on Fedora 37 with GNOME 43.3, it works just fine here. Might be macOS-specific then.

@ndonkoHenri
Copy link
Contributor

Works as expected on Windows. Maybe macOS specific as @iron3oxide said.
Can you make a little recording?

@xylix
Copy link
Author

xylix commented Mar 2, 2023

Basically the operating system's file dialogs "left bar" stays gray when the app opens, so it is basically unfocused. And I try to show in the video how when trying to double click the "unfocused" file dialogs files they don't get selected. Instead a click to select the dialog and then double click to select file is required. (Or one click to select the dialog, then one to select file, and then submit.)
https://user-images.githubusercontent.com/13387304/222429747-a8d0adad-bf6f-4567-9cbe-4db69b3c86bf.mov

@ndonkoHenri
Copy link
Contributor

The flutter package we use has an opened issue for this: miguelpruivo/flutter_file_picker#1445

@ndonkoHenri ndonkoHenri added enhancement Improvement/Optimization platform: mac Specific to macOS labels Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement/Optimization platform: mac Specific to macOS
Projects
None yet
Development

No branches or pull requests

3 participants