diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2002-04-08 14:51:31 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2002-04-08 14:51:31 (GMT) |
commit | 8509ebc8f7f5ba7a5691e890179225ba5457a688 (patch) | |
tree | 2810d4347249c19ee6d7abaa63350303c9732b73 | |
parent | 95de5c16310e0ace7dc2de17fd610daf19b9cdea (diff) | |
download | cpython-8509ebc8f7f5ba7a5691e890179225ba5457a688.zip cpython-8509ebc8f7f5ba7a5691e890179225ba5457a688.tar.gz cpython-8509ebc8f7f5ba7a5691e890179225ba5457a688.tar.bz2 |
Patch #539392: Invoke setlocale, try opening the file in demo mode.
-rw-r--r-- | Lib/lib-tk/tkFileDialog.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/Lib/lib-tk/tkFileDialog.py b/Lib/lib-tk/tkFileDialog.py index 6a3a464..93cb277 100644 --- a/Lib/lib-tk/tkFileDialog.py +++ b/Lib/lib-tk/tkFileDialog.py @@ -130,14 +130,30 @@ if __name__ == "__main__": # Start off with UTF-8 enc = "utf-8" + import sys # See whether CODESET is defined try: import locale + locale.setlocale(locale.LC_ALL,'') enc = locale.nl_langinfo(locale.CODESET) except (ImportError, AttributeError): pass - print "open", askopenfilename(filetypes=[("all files", "*")]).encode(enc) - print "saveas", asksaveasfilename().encode(enc) + # dialog for openening files + + openfilename=askopenfilename(filetypes=[("all files", "*")]) + try: + fp=open(openfilename,"r") + fp.close() + except: + print "Could not open File: " + print sys.exc_info()[1] + + print "open", openfilename.encode(enc) + + # dialog for saving files + + saveasfilename=asksaveasfilename() + print "saveas", saveasfilename.encode(enc) |