Clemapfel / Mousetrap.jl

Finally, a GUI Engine made for Julia

Home Page:https://clemens-cords.com/mousetrap

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Potential bug with FileChooser

ma-seefelder opened this issue · comments

I'm relatively new to GUI programming, and I'm encountering what might be an issue of my own code, or it could be a bug. I'm working on an application where I need to implement a FileChooser that enables users to select a folder. Currently, I'm using Julia 1.9.1 and Mousetrap.jl version 0.3.0. To create the FileChooser, I'm using the following code snippet:

image_selector = FileChooser(FILE_CHOOSER_ACTION_SELECT_FOLDER, "Select")
present!(image_selector)

When I try to execute this function either in the Julia REPL or from the command line, I get a really long error message (see below). When I use the FileChooser to select an individual, file I don't get any error messages and all works well:

image_selector = FileChooser(FILE_CHOOSER_ACTION_SELECT_FOLDER, "Select")
present!(image_selector)
(process:1684): GLib-GIO-CRITICAL **: 20:08:45.900: g_settings_schema_source_lookup: assertion 'source != NULL' failed

(process:1684): GLib-GIO-CRITICAL **: 20:08:45.900: g_settings_schema_source_lookup: assertion 'source != NULL' failed

(julia.exe:1684): GLib-GIO-WARNING **: 20:08:48.966: C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\gdbus.exe dbus binary failed to launch bus, maybe incompatible version

(julia.exe:1684): GLib-GIO-ERROR **: 20:08:49.162: No GSettings schemas are installed on the system

[1684] signal (22): SIGABRT
in expression starting at C:\Users\manue\Documents\GitHub\ProteinCoLoc\src\gui.jl:9
crt_sig_handler at C:/workdir/src\signals-win.c:95
raise at C:\WINDOWS\System32\msvcrt.dll (unknown line)
abort at C:\WINDOWS\System32\msvcrt.dll (unknown line)
g_abort at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libglib-2.0-0.dll (unknown line)
g_log_structured_array.part.4 at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libglib-2.0-0.dll (unknown line)
g_log_default_handler at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libglib-2.0-0.dll (unknown line)
g_logv at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libglib-2.0-0.dll (unknown line)
g_log at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libglib-2.0-0.dll (unknown line)
g_settings_set_property at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgio-2.0-0.dll (unknown line)
g_object_new_internal at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgobject-2.0-0.dll (unknown line)
g_object_new_valist at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgobject-2.0-0.dll (unknown line)
g_object_new at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgobject-2.0-0.dll (unknown line)
_gtk_file_chooser_get_settings_for_widget at C:\Users\manue\.julia\artifacts\748abfff8fcf7cdfa703fab4dfd56b52ec2e6451\bin\libgtk-4-1.dll (unknown line)   
settings_load at C:\Users\manue\.julia\artifacts\748abfff8fcf7cdfa703fab4dfd56b52ec2e6451\bin\libgtk-4-1.dll (unknown line)
g_object_set_property at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgobject-2.0-0.dll (unknown line)
g_object_set_property at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgobject-2.0-0.dll (unknown line)
g_object_new_internal at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgobject-2.0-0.dll (unknown line)
g_object_new_valist at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgobject-2.0-0.dll (unknown line)
g_object_new at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgobject-2.0-0.dll (unknown line)
gtk_file_chooser_native_new at C:\Users\manue\.julia\artifacts\748abfff8fcf7cdfa703fab4dfd56b52ec2e6451\bin\libgtk-4-1.dll (unknown line)
create_file_chooser at C:\Users\manue\.julia\artifacts\748abfff8fcf7cdfa703fab4dfd56b52ec2e6451\bin\libgtk-4-1.dll (unknown line)
gtk_file_dialog_select_folder at C:\Users\manue\.julia\artifacts\748abfff8fcf7cdfa703fab4dfd56b52ec2e6451\bin\libgtk-4-1.dll (unknown line)
present at /workspace/srcdir/mousetrap/build\../src\file_chooser.cpp:258     
operator() at /opt/x86_64-w64-mingw32/bin/../x86_64-w64-mingw32/sys-root/usr/local/include/jlcxx\module.hpp:1009
__invoke_impl<void, jlcxx::TypeWrapper<mousetrap::FileChooser>::method<void, mousetrap::FileChooser>(const std::string&, void (mousetrap::FileChooser::*)())::<lambda(mousetrap::FileChooser&)>&, mousetrap::FileChooser&> at /opt/x86_64-w64-mingw32/x86_64-w64-mingw32/include/c++/12.1.0/bits\invoke.h:61        
__invoke_r<void, jlcxx::TypeWrapper<mousetrap::FileChooser>::method<void, mousetrap::FileChooser>(const std::string&, void (mousetrap::FileChooser::*)())::<lambda(mousetrap::FileChooser&)>&, mousetrap::FileChooser&> at /opt/x86_64-w64-mingw32/x86_64-w64-mingw32/include/c++/12.1.0/bits\invoke.h:111
_M_invoke at /opt/x86_64-w64-mingw32/x86_64-w64-mingw32/include/c++/12.1.0/bits\std_function.h:290
operator() at /opt/x86_64-w64-mingw32/x86_64-w64-mingw32/include/c++/12.1.0/bits\std_function.h:591
operator() at /opt/x86_64-w64-mingw32/bin/../x86_64-w64-mingw32/sys-root/usr/local/include/jlcxx\module.hpp:58
apply at /opt/x86_64-w64-mingw32/bin/../x86_64-w64-mingw32/sys-root/usr/local/include/jlcxx\module.hpp:72
present! at C:\Users\manue\.julia\packages\CxxWrap\5IZvn\src\CxxWrap.jl:624  
unknown function (ip: 000002ab00008b16)
present! at C:\Users\manue\.julia\packages\Mousetrap\C5TUg\src\Mousetrap.jl:193
#3 at C:\Users\manue\Documents\GitHub\ProteinCoLoc\src\gui.jl:90
unknown function (ip: 000002ab00006ed6)
jl_apply at C:/workdir/src\julia.h:1879 [inlined]
do_apply at C:/workdir/src\builtins.c:730
TypedFunction at C:\Users\manue\.julia\packages\Mousetrap\C5TUg\src\Mousetrap.jl:79
#14 at C:\Users\manue\.julia\packages\Mousetrap\C5TUg\src\Mousetrap.jl:1530  
unknown function (ip: 000002ab00007846)
jl_apply at C:/workdir/src\julia.h:1879 [inlined]
do_apply at C:/workdir/src\builtins.c:730
TypedFunction at C:\Users\manue\.julia\packages\Mousetrap\C5TUg\src\Mousetrap.jl:79
#6 at C:\Users\manue\.julia\packages\Mousetrap\C5TUg\src\Mousetrap.jl:645    
unknown function (ip: 000002ab00007f06)
safe_call at C:\Users\manue\.julia\packages\Mousetrap\C5TUg\src\Mousetrap.jl:178
unknown function (ip: 000002ab00007dc2)
jl_apply at C:/workdir/src\julia.h:1879 [inlined]
ijl_call at C:/workdir/src\jlapi.c:187
jl_safe_call<_jl_value_t*> at /workspace/srcdir/mousetrap_julia_binding/build\../cpp/..\mousetrap_julia_binding.hpp:39
operator() at /workspace/srcdir/mousetrap_julia_binding/build\../cpp/..\mousetrap_julia_binding.hpp:305
operator() at /workspace/x86_64-w64-mingw32-libgfortran5-cxx11/destdir/include/mousetrap\signal_component.hpp:254
__invoke_impl<void, mousetrap::has_signal_activate<mousetrap::Application>::connect_signal_activate<add_signal_activate<mousetrap::Application, jlcxx::TypeWrapper<mousetrap::Application> >(jlcxx::TypeWrapper<mousetrap::Application>, const std::string&)::<lambda(mousetrap::Application&, jl_function_t*)>::<lambda(mousetrap::Application&, jl_function_t*)>, _jl_value_t*>(add_signal_activate<mousetrap::Application, jlcxx::TypeWrapper<mousetrap::Application> >(jlcxx::TypeWrapper<mousetrap::Application>, const std::string&)::<lambda(mousetrap::Application&, jl_function_t*)>::<lambda(mousetrap::Application&, jl_function_t*)>, _jl_value_t*)::<lambda(void*)>&, void*> at /opt/x86_64-w64-mingw32/x86_64-w64-mingw32/include/c++/12.1.0/bits\invoke.h:61
__invoke_r<void, mousetrap::has_signal_activate<mousetrap::Application>::connect_signal_activate<add_signal_activate<mousetrap::Application, jlcxx::TypeWrapper<mousetrap::Application> >(jlcxx::TypeWrapper<mousetrap::Application>, const std::string&)::<lambda(mousetrap::Application&, jl_function_t*)>::<lambda(mousetrap::Application&, jl_function_t*)>, _jl_value_t*>(add_signal_activate<mousetrap::Application, jlcxx::TypeWrapper<mousetrap::Application> >(jlcxx::TypeWrapper<mousetrap::Application>, const std::string&)::<lambda(mousetrap::Application&, jl_function_t*)>::<lambda(mousetrap::Application&, jl_function_t*)>, _jl_value_t*)::<lambda(void*)>&, void*> at /opt/x86_64-w64-mingw32/x86_64-w64-mingw32/include/c++/12.1.0/bits\invoke.h:111
_M_invoke at /opt/x86_64-w64-mingw32/x86_64-w64-mingw32/include/c++/12.1.0/bits\std_function.h:290
operator() at /opt/x86_64-w64-mingw32/x86_64-w64-mingw32/include/c++/12.1.0/bits\std_function.h:591
wrapper at /workspace/x86_64-w64-mingw32-libgfortran5-cxx11/destdir/include/mousetrap\signal_component.hpp:254
g_closure_invoke at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgobject-2.0-0.dll (unknown line)
signal_emit_unlocked_R at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgobject-2.0-0.dll (unknown line)
g_signal_emit_valist at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgobject-2.0-0.dll (unknown line)
g_signal_emit at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgobject-2.0-0.dll (unknown line)
g_application_real_local_command_line at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgio-2.0-0.dll (unknown line)     
g_application_run at C:\Users\manue\.julia\artifacts\13606487e48c4dea9d20813adf4f03a3edea59fd\bin\libgio-2.0-0.dll (unknown line)
run at /workspace/srcdir/mousetrap/build\../src\application.cpp:132
operator() at /opt/x86_64-w64-mingw32/bin/../x86_64-w64-mingw32/sys-root/usr/local/include/jlcxx\module.hpp:1009
__invoke_impl<int, jlcxx::TypeWrapper<mousetrap::Application>::method<int, mousetrap::Application>(const std::string&, int (mousetrap::Application::*)())::<lambda(mousetrap::Application&)>&, mousetrap::Application&> at /opt/x86_64-w64-mingw32/x86_64-w64-mingw32/include/c++/12.1.0/bits\invoke.h:61
__invoke_r<int, jlcxx::TypeWrapper<mousetrap::Application>::method<int, mousetrap::Application>(const std::string&, int (mousetrap::Application::*)())::<lambda(mousetrap::Application&)>&, mousetrap::Application&> at /opt/x86_64-w64-mingw32/x86_64-w64-mingw32/include/c++/12.1.0/bits\invoke.h:114
_M_invoke at /opt/x86_64-w64-mingw32/x86_64-w64-mingw32/include/c++/12.1.0/bits\std_function.h:290
operator() at /opt/x86_64-w64-mingw32/x86_64-w64-mingw32/include/c++/12.1.0/bits\std_function.h:591
operator() at /opt/x86_64-w64-mingw32/bin/../x86_64-w64-mingw32/sys-root/usr/local/include/jlcxx\module.hpp:47
apply at /opt/x86_64-w64-mingw32/bin/../x86_64-w64-mingw32/sys-root/usr/local/include/jlcxx\module.hpp:72
run! at C:\Users\manue\.julia\packages\CxxWrap\5IZvn\src\CxxWrap.jl:624      
unknown function (ip: 000002ab00007986)
run! at C:\Users\manue\.julia\packages\Mousetrap\C5TUg\src\Mousetrap.jl:1499 
main at C:\Users\manue\.julia\packages\Mousetrap\C5TUg\src\Mousetrap.jl:1540 [inlined]
main at C:\Users\manue\.julia\packages\Mousetrap\C5TUg\src\Mousetrap.jl:1526 
unknown function (ip: 000002ab00003646)
jl_apply at C:/workdir/src\julia.h:1879 [inlined]
do_call at C:/workdir/src\interpreter.c:126
eval_value at C:/workdir/src\interpreter.c:226
eval_stmt_value at C:/workdir/src\interpreter.c:177 [inlined]
eval_body at C:/workdir/src\interpreter.c:624
jl_interpret_toplevel_thunk at C:/workdir/src\interpreter.c:762
jl_toplevel_eval_flex at C:/workdir/src\toplevel.c:912
jl_toplevel_eval_flex at C:/workdir/src\toplevel.c:856
ijl_toplevel_eval at C:/workdir/src\toplevel.c:921 [inlined]
ijl_toplevel_eval_in at C:/workdir/src\toplevel.c:971
eval at .\boot.jl:370 [inlined]
include_string at .\loading.jl:1899
_include at .\loading.jl:1959
9.1\lib\julia\sys.dll (unknown line)
exec_options at .\client.jl:307
_start at .\client.jl:522
jfptr__start_33001.clone_1 at C:\Users\manue\AppData\Local\Programs\Julia-1.9.1\lib\julia\sys.dll (unknown line)
jl_apply at C:/workdir/src\julia.h:1879 [inlined]
true_main at C:/workdir/src\jlapi.c:573
jl_repl_entrypoint at C:/workdir/src\jlapi.c:717
mainCRTStartup at C:/workdir/cli\loader_exe.c:59
BaseThreadInitThunk at C:\WINDOWS\System32\KERNEL32.DLL (unknown line)
RtlUserThreadStart at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
Allocations: 2287451 (Pool: 2286548; Big: 903); GC: 3

I can reproduce this on windows only

The following causes the same behavior on my machine, it would be nice if you can confirm this, though I'm pretty sure it will have the same behavior on yours too:

using GTK4_jll
@ccall GTK4_jll.libgtk4.gtk_init()::Cvoid
dialog = @ccall GTK4_jll.libgtk4.gtk_file_dialog_new()::Ptr{Cvoid}
@ccall GTK4_jll.libgtk4.gtk_file_dialog_select_folder(dialog::Ptr{Cvoid}, C_NULL::Ptr{Cvoid}, C_NULL::Ptr{Cvoid}, C_NULL::Ptr{Cvoid}, C_NULL::Ptr{Cvoid})::Cvoid

You may need to install GTK4_jll using import Pkg; Pkg.add("GTK4_jll")

This means this is not a bug with mousetrap, but most likely with the Julia BinaryBuilder jlls, which aren't maintained by me. I will open an issue with the relevant people and report back, this is a pretty huge bug but sadly this isn't only up to me, so the time frame is also out of my control.

I'm getting

(process:5976): GLib-GIO-ERROR **: 17:50:09.776: No GSettings schemas are installed on the system

For the GTK4-only MWE, which makes me think this is related to #5

Thanks for your answer. I can confirm that executing the GTK4_jll code on my Windows machine also leads to a long error message and an immediate crash of my Julia session. So it seems not to be a bug with mousetrap.

Thank you, I will try to find a workaround to the best of my abilities, as this is a pretty serious bug.

You're welcome. Thanks for your work and effort. Mousetrap.jl is really nice for creating GUIs and the documentation is easily understandable. For my purposes, I will simply generate a text field with Entry() in which the folder path should be copied.

I had similar issues when running something like

file_saver = FileChooser(FILE_CHOOSER_ACTION_SAVE, "Save")
present!(file_saver)

@ma-seefelder You may want to look into https://github.com/JuliaGraphics/NativeFileDialog.jl.

Hi, please add the following before the first using Mousetrap, where you may need to install GTK4_jll with import Pkg; Pkg.add("GTK4_jll"):

import GTK4_jll; ENV["GSETTINGS_SCHEMA_DIR"] = normpath(joinpath(GTK4_jll.libgtk4, "../../share/glib-2.0/schemas"))

Does the FileChooser still crash? A full main.jl to check would be:

import GTK4_jll 
ENV["GSETTINGS_SCHEMA_DIR"] = normpath(joinpath(GTK4_jll.libgtk4, "../../share/glib-2.0/schemas"))

using Mousetrap
main() do app
    chooser = FileChooser(FILE_CHOOSER_ACTION_SELECT_FOLDER)
    present!(chooser)
end

No, that seems to solve the issue. It also solves the problem when using the FILE_CHOOSER_ACTION_SAVE action.

Okay nice, see #5 (comment) for how to make that fix permanent. The fix will be part of v0.3.1, I'll keep this issue open until then