0 votes

Hi,

i have a FileDialog. After a file is selected, i check if the file is good, if not i want to open the FileDialog again with popup_centered. But it is not showing up. If i inspect it in the Editor while running it, i can see that it is not visible.

EDIT:

Some more info...:

var Dialog : FileDialog = FileDialog.new()


func _ready() -> void:
    make_load_dialog()


func make_load_dialog() -> void:
    add_child(Dialog)
    Dialog.access = FileDialog.ACCESS_FILESYSTEM
    Dialog.mode = FileDialog.MODE_OPEN_FILE
    Dialog.resizable = true
    Dialog.popup_exclusive = true
    Dialog.connect("file_selected", self, "path_selected")
    Dialog.get_cancel().connect("pressed", get_tree(), "quit")
    Dialog.get_close_button().connect("pressed", get_tree(), "quit")


[...]
    print("popup") # to see when it should pop up
    Dialog.call_deferred("popup")
[...]
in Engine by (1,012 points)
edited by

1 Answer

+1 vote
Best answer

I suppose it's not working because Godot closes the popup after having fired the file_selected signal. So calling popup_centered from within the function handling that signal won't have any effect.
Perhaps you could use call_deferred("popup_centered") instead?

by (27,170 points)
selected by

Sounds very logical, but does unfortunatly not work.

Well, that works for me. I reproduced your issue without call_deferred, and adding it fixed it: it gets closed but because it reopens right away it looks like it remains open. Maybe your code sample is missing a detail?

extends Node

var Dialog : FileDialog = FileDialog.new()


func _ready() -> void:
    make_load_dialog()


func make_load_dialog() -> void:
    add_child(Dialog)
    Dialog.access = FileDialog.ACCESS_FILESYSTEM
    Dialog.mode = FileDialog.MODE_OPEN_FILE
    Dialog.resizable = true
    Dialog.popup_exclusive = true
    Dialog.connect("file_selected", self, "path_selected")
    Dialog.get_cancel().connect("pressed", get_tree(), "quit")
    Dialog.get_close_button().connect("pressed", get_tree(), "quit")
    Dialog.popup()


func path_selected(path: String):
    print("popup") # to see when it should pop up
    Dialog.call_deferred("popup")

Ok, on a normal node it works as intended.
I have the FileDialog in a script, that is autoloaded.
Can you please try, if you can get in working on an autoloaded script?

Tried on an autoload (which is just another node in the tree), using the same script, works perfectly the same.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories