summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/editor.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/idlelib/editor.py')
-rw-r--r--Lib/idlelib/editor.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py
index 35027da..793ed3a 100644
--- a/Lib/idlelib/editor.py
+++ b/Lib/idlelib/editor.py
@@ -10,6 +10,7 @@ import traceback
import webbrowser
from tkinter import *
+from tkinter.font import Font
from tkinter.ttk import Scrollbar
import tkinter.simpledialog as tkSimpleDialog
import tkinter.messagebox as tkMessageBox
@@ -120,14 +121,13 @@ class EditorWindow(object):
self.prompt_last_line = '' # Override in PyShell
self.text_frame = text_frame = Frame(top)
self.vbar = vbar = Scrollbar(text_frame, name='vbar')
- self.width = idleConf.GetOption('main', 'EditorWindow',
- 'width', type='int')
+ width = idleConf.GetOption('main', 'EditorWindow', 'width', type='int')
text_options = {
'name': 'text',
'padx': 5,
'wrap': 'none',
'highlightthickness': 0,
- 'width': self.width,
+ 'width': width,
'tabstyle': 'wordprocessor', # new in 8.5
'height': idleConf.GetOption(
'main', 'EditorWindow', 'height', type='int'),
@@ -154,6 +154,7 @@ class EditorWindow(object):
text.bind('<MouseWheel>', self.mousescroll)
text.bind('<Button-4>', self.mousescroll)
text.bind('<Button-5>', self.mousescroll)
+ text.bind('<Configure>', self.handle_winconfig)
text.bind("<<cut>>", self.cut)
text.bind("<<copy>>", self.copy)
text.bind("<<paste>>", self.paste)
@@ -211,6 +212,7 @@ class EditorWindow(object):
text['font'] = idleConf.GetFont(self.root, 'main', 'EditorWindow')
text.grid(row=1, column=1, sticky=NSEW)
text.focus_set()
+ self.set_width()
# usetabs true -> literal tab characters are used by indent and
# dedent cmds, possibly mixed with spaces if
@@ -338,6 +340,22 @@ class EditorWindow(object):
else:
self.update_menu_state('options', '*Line Numbers', 'disabled')
+ def handle_winconfig(self, event=None):
+ self.set_width()
+
+ def set_width(self):
+ text = self.text
+ inner_padding = sum(map(text.tk.getint, [text.cget('border'),
+ text.cget('padx')]))
+ pixel_width = text.winfo_width() - 2 * inner_padding
+
+ # Divide the width of the Text widget by the font width,
+ # which is taken to be the width of '0' (zero).
+ # http://www.tcl.tk/man/tcl8.6/TkCmd/text.htm#M21
+ zero_char_width = \
+ Font(text, font=text.cget('font')).measure('0')
+ self.width = pixel_width // zero_char_width
+
def _filename_to_unicode(self, filename):
"""Return filename as BMP unicode so displayable in Tk."""
# Decode bytes to unicode.
@@ -830,6 +848,7 @@ class EditorWindow(object):
# Finally, update the main text widget.
new_font = idleConf.GetFont(self.root, 'main', 'EditorWindow')
self.text['font'] = new_font
+ self.set_width()
def RemoveKeybindings(self):
"Remove the keybindings before they are changed."