mirror of
https://github.com/python/cpython.git
synced 2025-12-04 16:43:27 +00:00
1. Fix File Open: don't encode filename to UTF-8 bytes
2. Get test() code working.
This commit is contained in:
parent
23cfc9845c
commit
3a4e24b999
1 changed files with 6 additions and 8 deletions
|
|
@ -14,9 +14,9 @@ import tkFileDialog
|
||||||
import tkMessageBox
|
import tkMessageBox
|
||||||
import re
|
import re
|
||||||
from Tkinter import *
|
from Tkinter import *
|
||||||
from .SimpleDialog import SimpleDialog
|
from SimpleDialog import SimpleDialog
|
||||||
|
|
||||||
from .configHandler import idleConf
|
from idlelib.configHandler import idleConf
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from codecs import BOM_UTF8
|
from codecs import BOM_UTF8
|
||||||
|
|
@ -244,14 +244,13 @@ class IOBinding:
|
||||||
def loadfile(self, filename):
|
def loadfile(self, filename):
|
||||||
try:
|
try:
|
||||||
# open the file in binary mode so that we can handle
|
# open the file in binary mode so that we can handle
|
||||||
# end-of-line convention ourselves.
|
# end-of-line convention ourselves.
|
||||||
f = open(filename,'rb')
|
f = open(filename,'rb')
|
||||||
chars = f.read()
|
chars = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
except IOError as msg:
|
except IOError as msg:
|
||||||
tkMessageBox.showerror("I/O Error", str(msg), master=self.text)
|
tkMessageBox.showerror("I/O Error", str(msg), master=self.text)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
chars = self.decode(chars)
|
chars = self.decode(chars)
|
||||||
# We now convert all end-of-lines to '\n's
|
# We now convert all end-of-lines to '\n's
|
||||||
firsteol = self.eol_re.search(chars)
|
firsteol = self.eol_re.search(chars)
|
||||||
|
|
@ -261,7 +260,6 @@ class IOBinding:
|
||||||
# Make sure it is an ASCII string
|
# Make sure it is an ASCII string
|
||||||
self.eol_convention = self.eol_convention.encode("ascii")
|
self.eol_convention = self.eol_convention.encode("ascii")
|
||||||
chars = self.eol_re.sub(r"\n", chars)
|
chars = self.eol_re.sub(r"\n", chars)
|
||||||
|
|
||||||
self.text.delete("1.0", "end")
|
self.text.delete("1.0", "end")
|
||||||
self.set_filename(None)
|
self.set_filename(None)
|
||||||
self.text.insert("1.0", chars)
|
self.text.insert("1.0", chars)
|
||||||
|
|
@ -524,8 +522,7 @@ class IOBinding:
|
||||||
self.opendialog = tkFileDialog.Open(master=self.text,
|
self.opendialog = tkFileDialog.Open(master=self.text,
|
||||||
filetypes=self.filetypes)
|
filetypes=self.filetypes)
|
||||||
filename = self.opendialog.show(initialdir=dir, initialfile=base)
|
filename = self.opendialog.show(initialdir=dir, initialfile=base)
|
||||||
if isinstance(filename, str):
|
assert isinstance(filename, str)
|
||||||
filename = filename.encode(filesystemencoding)
|
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
def defaultfilename(self, mode="open"):
|
def defaultfilename(self, mode="open"):
|
||||||
|
|
@ -550,7 +547,8 @@ class IOBinding:
|
||||||
|
|
||||||
def updaterecentfileslist(self,filename):
|
def updaterecentfileslist(self,filename):
|
||||||
"Update recent file list on all editor windows"
|
"Update recent file list on all editor windows"
|
||||||
self.editwin.update_recent_files_list(filename)
|
if self.editwin.flist:
|
||||||
|
self.editwin.update_recent_files_list(filename)
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
root = Tk()
|
root = Tk()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue