-
Notifications
You must be signed in to change notification settings - Fork 725
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
Fix KDialog file open dialog and file filters #942
Conversation
Thank you for submitting. @philenius would you mind reviewing this? |
@miguelpruivo, sure @w1th0utnam3 thank you for your contribution. Support for KDialog was contributed by @mnipritom just 10 days ago in #932 and #935. (thank you, @mnipritom , btw 👍 ). Back then, @mnipritom mentioned that filtering by file type doesn't work:
Please note that I'm not ready to merge yet. Unfortunately, I didn't test the KDialog implementation until now and I'm not happy with it due to the following reasons:
Please give me two more days to do the refactoring. I'll get back to you and then we can merge your contribution. Regarding your second point:
If I understood you correctly, then you're asking for the same feature as in #859? Others requested to set the start/initial directory, too. I already provided an implementation for Linux, macOS, and Windows, but it wasn't merged because no one came up with an implementation for Android and iOS respectively. Is that correct? |
Hi. This is exactly the type of feedback I was looking for in here #931 and thanks for providing it @philenius !
I did not think it would be necessary to ensure strict measurements within this package over what type of files get picked, other than what is already implemented.
See these 2 screenshots as to how the kde documentation sneakily dodges this operation, indicating that it is an existing issue with the program itself. Link to segment in documentation Literally the next paragraph Link to segment in documentation I have found a similar bug listing here, which is over 7 years old and I doubt is ever going to get addressed. Since majority of KDE community effort is going towards porting majority of the codebase over to the newer version of Qt framework. Same goes of
That's just me being a noob, un-experienced, not going over project structure and general lack of familiarity with industry practices regarding software development. Apologies! That all being said, with all due respect, I think documentation could use some updates reflecting the expectations of maintainers, in the form of Contributor's guide as to how one should approach contribution to the project, as it is one of the most popular 3rd party packages on pub.dev and is set to bring a lot more indie adopters like me as Ubuntu will be developing most of it's utilities using Flutter going forward.
Since these This is just something I came across, brainstorming ideas as to how simplification of the Thank again for the amazing package! |
First of all, thanks for providing initial KDialog support. I think at the moment it is still quite useful to have this as the dialog mostly works and offers a quite nice user interface in comparison to others (looking at the barebones GTK file dialog... I really don't like programs showing this dialog even though I'm running KDE...).
While the concerns are definitely valid I don't think a default installation of Python provides a module for opening a file dialog, or does it? But in any case it would be nice to have some kind of fallback that would work on any Linux distribution. For example a very basic dialog using flutter? Not sure if this would be feasible in terms of integration with an app. But of course this opens a whole other can of worms like theming etc.. I guess at the moment the library would just error when you want to provide a dialog and don't have any of the three solutions installed?
Yeah, I saw that as well. Further down they show an example for
which has a working wildcard filter (not sure what the
Sure. Just notify me and I can update this PR.
Ok, maybe you could take this into account while refactoring and allow the different dialog providers to also do post-processing of the picked files? Though we have to be careful with the space separator as we cannot just split at every space. I guess we would have to split such that each file starts with a
Right, like @mnipritom mentioned this could be part of some contribution guidelines. I can help after refactoring if you want.
Ah yes, sorry I didn't search for this before. |
And thanks for the detailed comments from both of you! |
@w1th0utnam3 Thanks for the improvements you've done!
from tkinter import *
from tkinter import filedialog
def openFile():
filepath = filedialog.askopenfilename(initialdir="C:\\Users\\Cakow\\PycharmProjects\\Main",
title="Open file okay?",
filetypes= (("text files","*.txt"),
("all files","*.*")))
file = open(filepath,'r')
print(file.read())
file.close()
window = Tk()
button = Button(text="Open",command=openFile)
button.pack()
window.mainloop() Regarding availability of
I think themeing implementation is also possible with
This project. Although It introduces a dependency from outside of I just have some bits and pieces of the puzzle here and there, but no knowledge of actually stitching everything into a working prototype. 😅 |
Ah ok, looks good! However, "are available" does not necessarily mean installed by default. On some (older?) distributions it seems to be required to install the python package manually using the distributions package manager or pip. Though I didn't find something general. I guess this should be investigated further. |
@w1th0utnam3 I completed the refactoring using the Factory Method design pattern and pushed my changes to your fork. There is now an abstract class
@w1th0utnam3 : please let me know if are you interested to implement the missing implementations in Regarding the start/initial directory: let's first merge this MR and after that we can work on the integration of #859 . Good point, we should include a note about unit tests in our contribution guidelines! 👍 I'll get back to yours and @mnipritom 's comments later. |
Sorry, I meant more like ignoring the flag for the KDialog implementation, not removing the option in the library. But hopefully we can get it to work now.
Sure, I'll take a look! |
Ok, I implemented the missing functions and tests. While writing the tests I noticed that the separation of paths using spaces by KDialog is of course much worse than it is with pipes. This prevents you from correctly parsing paths that have spaces at the end of a directory name in any part of the path. Any idea how we should handle this? I think in the multiple file selection case we are lost with spaces as separators. For the single file selection mode however we could just skip this splitting? The design of the KDialog CLI is really questionable... |
With the KDialog option "--separate-output" each selected file is printed in a separate line. This simplifies the post-processing to splitting by "\n".
@w1th0utnam3 great job, thank you 🚀
I agree with you. The approach of zenity/qarma to use pipes as separator is a little bit better because it's a rather uncommon character. But choosing blanks/spaces as separator creates nightmares. Luckily, KDialog offers the option $ kdialog --help
...
--separate-output Return list items on separate lines (for checklist option and file open with --multiple)
... This way, we can simply split by
No need to distinguish the two cases (single file vs multiple files). Splitting by
Same for zenity and qarma. The problem is that we chose this script based approach where we execute shell commands. For our Windows implementation, we call the API of a Windows DLL via Dart
A Flutter contributor/Google employee warned us about this early on: #630 (comment). Unfortunately, we lack the skills to do it the professional way like Google did (C++ code which calls APIs of the operating system, see https://github.com/google/flutter-desktop-embedding/tree/master/plugins/file_selector). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: lib/src/file_picker_linux.dart
has been moved/renamed to lib/src/linux/file_picker_linux.dart
. Git just doesn't recognize it because this file has been renamed and some of its code has been extracted to other classes.
@miguelpruivo we are ready to merge! Are you okay with these changes? We created a sub-directory |
Really appreciate you guys iterating upon the crude initial implementation I made and coming up with something way more comprehensive. This has been a learning experience for me too and I grateful to both of you for it 👍 |
@mnipritom thank you for the kind words :) It wouldn't have been possible without your initial contribution. Thanks to you I learned about the existence of
I'm glad to hear so. You're welcome and sorry for the delayed and indirect feedback. I sometimes take a few days to respond and in the case of your pull request I was definitely too slow. Thanks again!
That's alright. Even with the changes introduced in this pull request, the user can still remove the file filter and select any kind of file. Developers have to double check the selected files either way:
Thank you for summarizing your research regarding the file filtering and KDialog in general. I'm disappointed by zenity/qarma/kdialog, too. The development of many Linux/Ubuntu tools seems to have stagnated for many years.
No problem at all and no need to apologize 😉 You did a great job!
Thank you for your valuable feedback. I pushed a first version of our contribution guidelines in Also thank you for your detailed elaboration on an alternative implementation using Python. Regarding that, I completely agree with @w1th0utnam3. I really don't want to add Python code or dependencies on Python packages into our existing code base which already uses Dart + Java + Objective-C. In my opinion, |
Ah I missed this while looking to through the commandline arguments. Technically a filename might actually contain But this is why I suggested skipping the splitting for the single file case. To at least have a correct implementation in the common case of selecting only a single file? Should this be documented as platform specific behavior? Otherwise I could imagine someone filing in issue when they try to find out why their "special" files cannot be opened. |
@w1th0utnam3 the zenity/qarma implementation splits by
Right now, I don't think that we need to document anything because file_picker always correctly returns the picked file(s) (see screen recording). If you still find a bug, you're welcome to open a new issue / pull request or document platform specific restrictions/behavior in our wiki: https://github.com/miguelpruivo/flutter_file_picker/wiki/api#methods
We already had such an issue on macOS (#890) where a user tried to pick a file with |
Currently the open file picker (i.e.
pickFile
+saveFile == false
) does not work with KDialog because it needs a--getopenfilename
argument in this case.In addition, file filters were not working. KDialog expects file filters either as explicit MIME types or in the following wildcard format:
{description} (*.ext1 *.ext2 *.ext3 ...)
where{description}
is the string that will be shown in UI.This PR tries to fix these issues. For the extension filters, I patch the supplied
fileFilter
string.Another issue that I encountered is that you have to supply a "start directory" to KDialog if you want to supply file filters. Currently I use either
fileName
for this if its not empty or otherwise default to.
. I'm not sure if.
is the best choice. For this purpose it might be sensible to add a generalstartDir
argument to all file picker functions to distinguish it from thefileName
? A library user might specify only literally a filename as the value forfileName
but for certain pickers (like KDialog) this will try to open an invalid start path (something likehttp://filename
). Let me know what you think.