`file.choose()` in `Julia`?

Not need to left that in the startup file. NativeFileDialog.jl first version is working, still test to add and documentation. Also I need to register it (reading right now how it is done).

5 Likes

Cool! When the package is registered i will assign the solution to your post, since, although the Gtk solution suggested above works fine, I think it is preferable to promote the JLL solution that is as close to the native open file dialogs as it gets.

If you can test it on you machine and give feedback I would be really grateful. :slight_smile:

So, I tested all the functions in NativeFileDialog.jl and they all work! I was not able to test the ones in the wrapper.jl, since I would need some documentation as to what kinds of arguments you expect to have. Looking forward to testing the wrapper!

1 Like

Donā€™t worry about what is inside wrapper.jl, those functions are just a thin layer above NFD for me to not worry about C interop too much. The only functions that matter are the ones exported (pick_file, pick_multi_file, save_file, pick_folder).

Just as a curiosity, what OS are you using? and what @time using NativeFileDialog says? I want to see if I can improve the time for loading, because I think it should be faster (I think the problem is that GTK3_jll is a dependency for Linux/FreeBSD for NativeFileDialog_jll, but it is not needed on Windows or MacOS, or even Linux if Gtk is installed).

Anyways, thanks for the help! :smiley:

Great! These functions are more than enough.

First time loading is very good:

julia> @time using NativeFileDialog
  0.006044 seconds (4.71 k allocations: 310.094 KiB, 26.74% compilation time)

And here is the machine info:

That time looks a bit too fast, Iā€™d expect something of the order of 0.1 seconds. Do you have the package already loaded in that session, including from your startup file?

Oh! You are right! Although I started a new session, the package had been loaded through the startup.jl file. So, I deleted the relevant line from startup.jl and when I started a new session I got the following:

julia> @time using NativeFileDialog
  0.539846 seconds (920.25 k allocations: 44.807 MiB, 9.31% gc time, 48.80% compilation time)
2 Likes

Do you also load Revise.jl in your startup file? Note that you can launch julia bypassing the startup file with

julia --startup-file=no
1 Like

No. Revise.jl is not being loaded. In general, startup.jl has only a few ā€œconvenienceā€ functions that are not relevant.
Thanks for the tip! Didnā€™t know about it.

Nice, I hadnā€™t thought about Revise slowing down the package loadingā€¦ but not having it makes the time on my machine to go from ~0.9s to ~0.2s. I guess that time is okay and i donā€™t need to worry too much about it for now. :b

On Mac it installed gtk jlls, which I thought were only needed for Linux right? Or do jlls not discriminate between platforms for their dependencies?

Pkg doesnā€™t have optional (e.g. platform-dependent) dependencies, so no, thatā€™s not possible to do.

1 Like

Interesting, for me on Linux with Julia v1.6.3 it takes

% julia -q --project=/tmp --startup-file=no
julia> @time using NativeFileDialog
  0.139741 seconds (404.16 k allocations: 24.629 MiB, 35.78% compilation time)

Some reporting from Win10 Julia 1.7.0-beta4 with empty startup.jl:

@time using NativeFileDialog    # 1.2 s (1.3 M allocations: 58 MiB, 0.87% gc time, 35% compilation time)
@time using Gtk                 # 1.7 s (1.3 M allocations: 81 MiB, 1.16% gc time)

Tested all NativeFileDialog.jl functions further below and some observations:

  • The parameter filterlist despite of its name does not seem to accept multiple filters (like Gtk does)?
  • defaultpath should probably be defined consistently in all functions as an optional keyword argument?

Code tested successfully:

using NativeFileDialog
path = raw"C:\Users\jrafa"
pick_file(defaultpath = path, filterlist = "txt")
pick_multi_file(defaultpath = path, filterlist = "txt")
pick_folder(path)
save_file(path, "txt")

Just for the sake of completeness and following what @rafael.guerra did, on mac, for using Gtk you get slightly slower loading timeā€¦although I do not consider these as notable differences, to be honest.

julia> @time using Gtk
  1.316213 seconds (2.32 M allocations: 137.445 MiB, 4.90% gc time, 23.61% compilation time)

Also, the argument name defaultpath should probably change, since from a user perspective this is the argument to use so that you simply set the file path and could be confusing to call it defaultpath. Simply, calling it path is probably enough.
@giordano And what makes me wonder apart from the time difference is why you have so much less fewer allocations in linux. But I guess these are purely due to internal os differencesā€¦

The format for multiples filters is ā€œfilter1;filter2ā€, in a single filter you can add up multiple file types as ā€œft1_filter1,ft2_filter1,ft3_filter1;ft1_filter2ā€ etc. I need to add that in the README.

Will do, I though it was already this way.

1 Like

For what I see maybe I can save a little bit of time with precompilation, need to do that later.

I guess that make sense, will change it. :slight_smile:

1 Like

Done! :partying_face: Now to wait the 3 day period till auto-merge. Any issues or commentaries are welcomed in the issues section.

9 Likes