tkinter file dialog pattern matching
Somebody on the tutor mailing list wants to match "all files and direcories in this directory that do not start with a ." The filetypes option seems only to want patterns to match, not patterns to exclude. Is my pattern matching magic just off, or is there no way to exclude things in a tkFileDialog? puzzled, Laura
Hi, I've found this little gem in the Tk docs https://www.tcl.tk/man/tcl8.4/TkCmd/getOpenFile.htm#M13 From what I see "file patterns" in the file dialog are not "regex patterns" and do not support special characters. Only things that work are: 1) * - any extension 2) "" - files without extension 3) literal extension without wildcard chars Unfortunately it looks like there is no simple way to filter out hidden files. Check out this answer https://mail.python.org/pipermail//tutor/2011-November/086483.html Regards, Pawel Mosakowski On Sat, 22 Aug 2015 13:03:46 +0200 Laura Creighton <lac@openend.se> wrote:
Somebody on the tutor mailing list wants to match "all files and direcories in this directory that do not start with a ."
The filetypes option seems only to want patterns to match, not patterns to exclude. Is my pattern matching magic just off, or is there no way to exclude things in a tkFileDialog?
puzzled, Laura _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss
In a message of Sat, 22 Aug 2015 21:04:24 +0100, Pawel Mosakowski writes:
Hi,
From what I see "file patterns" in the file dialog are not "regex
I've found this little gem in the Tk docs https://www.tcl.tk/man/tcl8.4/TkCmd/getOpenFile.htm#M13 patterns" and do not support special characters. Only things that work are: 1) * - any extension 2) "" - files without extension 3) literal extension without wildcard chars Unfortunately it looks like there is no simple way to filter out hidden files. Check out this answer https://mail.python.org/pipermail//tutor/2011-November/086483.html
Regards, Pawel Mosakowski
Thank you. Looks like it will be necessary to construct a new widget. I'm surprised ... Laura
In a message of Sat, 22 Aug 2015 21:04:24 +0100, Pawel Mosakowski writes:
Hi,
From what I see "file patterns" in the file dialog are not "regex
I've found this little gem in the Tk docs https://www.tcl.tk/man/tcl8.4/TkCmd/getOpenFile.htm#M13 patterns" and do not support special characters. Only things that work are: 1) * - any extension 2) "" - files without extension 3) literal extension without wildcard chars Unfortunately it looks like there is no simple way to filter out hidden files. Check out this answer https://mail.python.org/pipermail//tutor/2011-November/086483.html
Regards, Pawel Mosakowski
Thank you. Looks like it will be necessary to construct a new widget. I'm surprised ... . . . More than I. I can understand your disappointment that file-dialogue "file patterns" have such a rudimentary syntax; I speculate with considerable confidence that
On Sat, Aug 22, 2015 at 10:17:11PM +0200, Laura Creighton wrote: the authors acted with sh as the model most in their mind. You're quite right, Laura, that the elements are at hand to allow you to construct your own variant. If the history of getOpenFile truly interests you, act quickly: while we can get to the authors now, it won't be many cycles more before their memories and records senesce irretrievably.
Hi, On Sat, 22 Aug 2015 22:17:11 +0200 Laura Creighton <lac@openend.se> wrote:
In a message of Sat, 22 Aug 2015 21:04:24 +0100, Pawel Mosakowski writes:
Hi,
From what I see "file patterns" in the file dialog are not "regex
I've found this little gem in the Tk docs https://www.tcl.tk/man/tcl8.4/TkCmd/getOpenFile.htm#M13 patterns" and do not support special characters. Only things that work are: 1) * - any extension 2) "" - files without extension 3) literal extension without wildcard chars Unfortunately it looks like there is no simple way to filter out hidden files.
if you only need to hide hidden files, please see my other post. If you need a more versatile file dialog widget, you might want to consider wrapping an existing tcl widget for tkinter, this is usually rather easy once you understand how it is done (all you need is mostly the man page and a little time) and might save you a lot of headaches. One example that might be interisting is here: http://chiselapp.com/user/schelte/repository/fsdialog/index You might also want to try the Tix.ExFileSelectDialog, it is rather dated, but actually has a switch to toggle hidden files on/off and wildcard filtering capabilities. Unfortunately here with debian jessie I can only test it with Tcl, with python for some reason I get a segfault :-( Best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. I realize that command does have its fascination, even under circumstances such as these, but I neither enjoy the idea of command nor am I frightened of it. It simply exists, and I will do whatever logically needs to be done. -- Spock, "The Galileo Seven", stardate 2812.7
Hi, On Sat, 22 Aug 2015 21:04:24 +0100 Pawel Mosakowski <pawel@mosakowski.net> wrote:
Hi,
I've found this little gem in the Tk docs https://www.tcl.tk/man/tcl8.4/TkCmd/getOpenFile.htm#M13 From what I see "file patterns" in the file dialog are not "regex patterns" and do not support special characters. Only things that work are: 1) * - any extension 2) "" - files without extension 3) literal extension without wildcard chars Unfortunately it looks like there is no simple way to filter out hidden files.
actually the unix tk file dialog has an an (however undocumented) feature to hide hidden elements and display even a button that allows to toggle between hidden elements on/off, however we need to do a little tcl to get to this. Since the feature is not documented anywhere it might also be a good idea to wrap this into a try...except. See this little code snippet: ############################################# from Tkinter import * import tkFileDialog as tkfd root = Tk() try: # call a dummy dialog with an impossible option to initialize the file # dialog without really getting a dialog window; this will throw a # TclError, so we need a try...except : try: root.tk.call('tk_getOpenFile', '-foobarbaz') except TclError: pass # now set the magic variables accordingly root.tk.call('set', '::tk::dialog::file::showHiddenBtn', '1') root.tk.call('set', '::tk::dialog::file::showHiddenVar', '0') except: pass # a simple callback for testing: def openfile(event): fname = tkfd.askopenfilename() print(fname) root.bind('<Control-o>', openfile) root.mainloop() ############################################# Best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. This cultural mystique surrounding the biological function -- you realize humans are overly preoccupied with the subject. -- Kelinda the Kelvan, "By Any Other Name", stardate 4658.9
participants (4)
-
Cameron Laird -
Laura Creighton -
Michael Lange -
Pawel Mosakowski