summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/EditorWindow.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2005-11-27 16:59:04 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2005-11-27 16:59:04 (GMT)
commit307021f40b227d2bf114b536c37cc41e03fc2aff (patch)
tree5a45b1fd79d1ea12c2822045fc58cacf77416b89 /Lib/idlelib/EditorWindow.py
parent1f663574ee154dfc95b883747137040f51ea7ef6 (diff)
downloadcpython-307021f40b227d2bf114b536c37cc41e03fc2aff.zip
cpython-307021f40b227d2bf114b536c37cc41e03fc2aff.tar.gz
cpython-307021f40b227d2bf114b536c37cc41e03fc2aff.tar.bz2
Patch #1162825: Support non-ASCII characters in IDLE window titles.
Diffstat (limited to 'Lib/idlelib/EditorWindow.py')
-rw-r--r--Lib/idlelib/EditorWindow.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py
index 1c04d76..59440f0 100644
--- a/Lib/idlelib/EditorWindow.py
+++ b/Lib/idlelib/EditorWindow.py
@@ -42,7 +42,7 @@ class EditorWindow(object):
from Percolator import Percolator
from ColorDelegator import ColorDelegator
from UndoDelegator import UndoDelegator
- from IOBinding import IOBinding
+ from IOBinding import IOBinding, filesystemencoding, encoding
import Bindings
from Tkinter import Toplevel
from MultiStatusBar import MultiStatusBar
@@ -256,6 +256,21 @@ class EditorWindow(object):
self.askinteger = tkSimpleDialog.askinteger
self.showerror = tkMessageBox.showerror
+ def _filename_to_unicode(self, filename):
+ """convert filename to unicode in order to display it in Tk"""
+ if isinstance(filename, unicode) or not filename:
+ return filename
+ else:
+ try:
+ return filename.decode(self.filesystemencoding)
+ except UnicodeDecodeError:
+ # XXX
+ try:
+ return filename.decode(self.encoding)
+ except UnicodeDecodeError:
+ # byte-to-byte conversion
+ return filename.decode('iso8859-1')
+
def new_callback(self, event):
dirname, basename = self.io.defaultfilename()
self.flist.new(dirname)
@@ -675,8 +690,10 @@ class EditorWindow(object):
menu.delete(1, END) # clear, and rebuild:
for i, file in zip(count(), rf_list):
file_name = file[0:-1] # zap \n
+ # make unicode string to display non-ASCII chars correctly
+ ufile_name = self._filename_to_unicode(file_name)
callback = instance.__recent_file_callback(file_name)
- menu.add_command(label=ulchars[i] + " " + file_name,
+ menu.add_command(label=ulchars[i] + " " + ufile_name,
command=callback,
underline=0)
@@ -716,10 +733,12 @@ class EditorWindow(object):
filename = self.io.filename
if filename:
filename = os.path.basename(filename)
- return filename
+ # return unicode string to display non-ASCII chars correctly
+ return self._filename_to_unicode(filename)
def long_title(self):
- return self.io.filename or ""
+ # return unicode string to display non-ASCII chars correctly
+ return self._filename_to_unicode(self.io.filename or "")
def center_insert_event(self, event):
self.center()