summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/idlelib')
-rw-r--r--Lib/idlelib/CodeContext.py77
-rw-r--r--Lib/idlelib/EditorWindow.py2
-rw-r--r--Lib/idlelib/NEWS.txt7
-rw-r--r--Lib/idlelib/PyShell.py4
-rw-r--r--Lib/idlelib/ScriptBinding.py10
5 files changed, 76 insertions, 24 deletions
diff --git a/Lib/idlelib/CodeContext.py b/Lib/idlelib/CodeContext.py
index 74d5b70..436206f 100644
--- a/Lib/idlelib/CodeContext.py
+++ b/Lib/idlelib/CodeContext.py
@@ -54,25 +54,68 @@ class CodeContext:
def toggle_code_context_event(self, event=None):
if not self.label:
- self.pad_frame = Tkinter.Frame(self.editwin.top,
- bg=self.bgcolor, border=2,
- relief="sunken")
- self.label = Tkinter.Label(self.pad_frame,
- text="\n" * (self.context_depth - 1),
- anchor="w", justify="left",
- font=self.textfont,
- bg=self.bgcolor, fg=self.fgcolor,
- border=0,
- width=1, # Don't request more than we get
- )
- self.label.pack(side="top", fill="x", expand=True,
- padx=4, pady=0)
- self.pad_frame.pack(side="top", fill="x", expand=False,
- padx=0, pady=0,
- after=self.editwin.status_bar)
+ # The following code attempts to figure out the required border
+ # width and vertical padding required for the CodeContext widget
+ # to be perfectly aligned with the text in the main Text widget.
+ # This is done by retrieving the appropriate attributes from the
+ # editwin.text and editwin.text_frame widgets.
+ #
+ # All values are passed through int(str(<value>)), since some
+ # values may be pixel objects, which can't simply be added added
+ # to ints.
+ #
+ # This code is considered somewhat unstable since it relies on
+ # some of Tk's inner workings. However its effect is merely
+ # cosmetic; failure will only cause the CodeContext text to be
+ # somewhat misaligned with the text in the main Text widget.
+ #
+ # To avoid possible errors, all references to the inner workings
+ # of Tk are executed inside try/except blocks.
+
+ widgets_for_width_calc = self.editwin.text, self.editwin.text_frame
+
+ # calculate the required vertical padding
+ padx = 0
+ for widget in widgets_for_width_calc:
+ try:
+ # retrieve the "padx" attribte from widget's pack info
+ padx += int(str( widget.pack_info()['padx'] ))
+ except:
+ pass
+ try:
+ # retrieve the widget's "padx" attribte
+ padx += int(str( widget.cget('padx') ))
+ except:
+ pass
+
+ # calculate the required border width
+ border_width = 0
+ for widget in widgets_for_width_calc:
+ try:
+ # retrieve the widget's "border" attribte
+ border_width += int(str( widget.cget('border') ))
+ except:
+ pass
+
+ self.label = Tkinter.Label(self.editwin.top,
+ text="\n" * (self.context_depth - 1),
+ anchor="w", justify="left",
+ font=self.textfont,
+ bg=self.bgcolor, fg=self.fgcolor,
+ width=1, #don't request more than we get
+ padx=padx, #line up with text widget
+ border=border_width, #match border width
+ relief="sunken",
+ )
+
+ # CodeContext's label widget is packed before and above the
+ # text_frame widget, thus ensuring that it will appear directly
+ # above it.
+ self.label.pack(side="top", fill="x", expand=False,
+ before=self.editwin.text_frame)
+
else:
self.label.destroy()
- self.pad_frame.destroy()
self.label = None
idleConf.SetOption("extensions", "CodeContext", "visible",
str(self.label is not None))
diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py
index bc61afb..1841b1c 100644
--- a/Lib/idlelib/EditorWindow.py
+++ b/Lib/idlelib/EditorWindow.py
@@ -102,8 +102,8 @@ class EditorWindow(object):
self.top.instance_dict = {}
self.recent_files_path = os.path.join(idleConf.GetUserCfgDir(),
'recent-files.lst')
- self.vbar = vbar = Scrollbar(top, name='vbar')
self.text_frame = text_frame = Frame(top)
+ self.vbar = vbar = Scrollbar(text_frame, name='vbar')
self.width = idleConf.GetOption('main','EditorWindow','width')
self.text = text = MultiCallCreator(Text)(
text_frame, name='text', padx=5, wrap='none',
diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index 3b3d79a..43e5b45 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -3,6 +3,13 @@ What's New in IDLE 2.6a1?
*Release date: XX-XXX-200X*
+- Patch #1362975: Rework CodeContext indentation algorithm to
+ avoid hard-coding pixel widths.
+
+- Some syntax errors were being caught by tokenize during the tabnanny
+ check, resulting in obscure error messages. Do the syntax check
+ first. Bug 1562716, 1562719
+
- IDLE's version number takes a big jump to match the version number of
the Python release of which it's a part.
diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py
index 709b3a7..20d00be 100644
--- a/Lib/idlelib/PyShell.py
+++ b/Lib/idlelib/PyShell.py
@@ -351,6 +351,8 @@ class ModifiedInterpreter(InteractiveInterpreter):
def build_subprocess_arglist(self):
w = ['-W' + s for s in sys.warnoptions]
+ if 1/2 > 0: # account for new division
+ w.append('-Qnew')
# Maybe IDLE is installed and is being accessed via sys.path,
# or maybe it's not installed and the idle.py script is being
# run from the IDLE source directory.
@@ -726,6 +728,8 @@ class ModifiedInterpreter(InteractiveInterpreter):
raise
except:
if use_subprocess:
+ # When run w/o subprocess, both user and IDLE errors
+ # are printed here; skip message in that case.
print >> self.tkconsole.stderr, \
"IDLE internal error in runcode()"
self.showtraceback()
diff --git a/Lib/idlelib/ScriptBinding.py b/Lib/idlelib/ScriptBinding.py
index f325ad1..3746eb8 100644
--- a/Lib/idlelib/ScriptBinding.py
+++ b/Lib/idlelib/ScriptBinding.py
@@ -57,9 +57,10 @@ class ScriptBinding:
filename = self.getfilename()
if not filename:
return
+ if not self.checksyntax(filename):
+ return
if not self.tabnanny(filename):
return
- self.checksyntax(filename)
def tabnanny(self, filename):
f = open(filename, 'r')
@@ -76,9 +77,6 @@ class ScriptBinding:
self.editwin.gotoline(nag.get_lineno())
self.errorbox("Tab/space error", indent_message)
return False
- except IndentationError:
- # From tokenize(), let compile() in checksyntax find it again.
- pass
return True
def checksyntax(self, filename):
@@ -139,11 +137,11 @@ class ScriptBinding:
filename = self.getfilename()
if not filename:
return
- if not self.tabnanny(filename):
- return
code = self.checksyntax(filename)
if not code:
return
+ if not self.tabnanny(filename):
+ return
shell = self.shell
interp = shell.interp
if PyShell.use_subprocess: