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

FilePicker just doesn't work. #1530

Closed
R0w0m opened this issue Jun 26, 2023 · 5 comments
Closed

FilePicker just doesn't work. #1530

R0w0m opened this issue Jun 26, 2023 · 5 comments

Comments

@R0w0m
Copy link

R0w0m commented Jun 26, 2023

Description

When I click on the filepicker button, nothing happens. I tried the examples from the documentation and they don't work either. Maybe some libraries need to be installed. I am running in a virtual environment.

Code example to reproduce the issue:

import flet as ft

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

    pick_files_dialog = ft.FilePicker(on_result=pick_files_result)
    selected_files = ft.Text()
    page.overlay.append(pick_files_dialog)

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

ft.app(target=main)

and also this one

import flet as ft

def main(page: ft.Page):
    page.theme_mode = "light"

    def result(e):
        page.add(ft.Text("result :)"))

    my_dialog = ft.FilePicker(on_result=result)
    page.overlay.append(my_dialog)

    page.add(
        ft.Row(
            [
                ft.ElevatedButton("Pick", icon=ft.icons.UPLOAD_FILE,
                                  on_click=lambda _: my_dialog.pick_files()),
                ft.ElevatedButton("Save", icon=ft.icons.UPLOAD_FILE,
                                  on_click=lambda _: my_dialog.save_file()),
                ft.ElevatedButton("Get Dir", icon=ft.icons.UPLOAD_FILE,
                                  on_click=lambda _: my_dialog.get_directory_path()),
            ]
        )
    )

ft.app(target=main)

Describe the results i received:

Nothing happens when I press it. It's like they're just normal buttons with no functionality. Also no message is displayed even in the terminal

Additional information:

I tried to run it in web, only pick_files works. Pick_dir and save_file don't work as well.
In windows it works correctly

Flet version (pip show flet):

Name: flet
Version: 0.7.4
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: /home/rwm/Projects/SeeSerial_python/env/lib/python3.11/site-packages
Requires: flet-core, httpx, oauthlib, packaging, watchdog, websocket-client, websockets
Required-by: 

Operating system:

Arch Linux.
kernel: 6.3.9

Additional environment details:
DE: Gnome 44.2

Please help me, I have no idea why this is happening.

@BedirT
Copy link

BedirT commented Jul 4, 2023

Seconded. I am using the examples provided, even they don't work. I am also using Linux (ubuntu).

[UPDATE] It is a permissioning issue. When I try in a root env it works.

@rkleivel
Copy link

rkleivel commented Jul 18, 2023

I can confirm. Running the examples as Ubuntu native app, none of the functions pick_files(), save_file() or get_directory_path() open the native file explorer (Nautilus on Ubuntu) unless I run the python executable with sudo privileges.

I cannot imagine this is intentional. Anyone found a solution? This is currently a showstopper for my app.

Ubuntu 22.04

Name: flet
Version: 0.8.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: /home/roald/KMM/stillOnWheels/stowImporter/env/lib/python3.10/site-packages
Requires: copier, flet-runtime, packaging, pydantic, qrcode, watchdog, websocket-client, websockets
Required-by: 

@rkleivel
Copy link

UPDATE to my previous comment:

Apparently I was a little bit too hasty... What I have discovered is that the above is true when running the script from VS Code, but not if running the script from Ubuntu terminal (x-terminal-emulator). Trying to find what's going on I came across this setting in VS Code: terminal.integrated.inheritEnv. Setting this to false makes file explorer launch as expected with all 3 above mentioned methods. (Still I have the issue if running debug in VS Code, but I assume it is related).

@R0w0m / @BedirT - any comments on this? Maybe the same is true for you?

@rkleivel
Copy link

Another UPDATE for the possible benefit of future googlers:
Comparing the environments where

  1. FilePicker launches the file explorer
    vs
  2. where FilePicker needs root-privileges to open file explorer

reveals that env var GTK_PATH=/snap/code/134/usr/lib/x86_64-linux-gnu/gtk-3.0 was set in case 2. Unseting this variable solves the problem for me.

The following links may be relevant:

@FeodorFitsner
Copy link
Contributor

Great discovery, thanks for sharing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants