Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4864b2bc
Commit
4864b2bc
authored
Feb 06, 2007
by
Kurt B. Kaiser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated patch (CodeContext.061217.patch) to
[ 1362975 ] CodeContext - Improved text indentation Tal Einat 16Dec06
parent
3f8aca11
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
53 deletions
+19
-53
Lib/idlelib/CodeContext.py
Lib/idlelib/CodeContext.py
+19
-53
No files found.
Lib/idlelib/CodeContext.py
View file @
4864b2bc
...
...
@@ -10,6 +10,7 @@ not open blocks are not shown in the context hints pane.
"""
import
Tkinter
from
Tkconstants
import
TOP
,
LEFT
,
X
,
W
,
SUNKEN
from
configHandler
import
idleConf
import
re
from
sys
import
maxint
as
INFINITY
...
...
@@ -24,7 +25,6 @@ getspacesfirstword =\
class
CodeContext
:
menudefs
=
[(
'options'
,
[(
'!Code Conte_xt'
,
'<<toggle-code-context>>'
)])]
context_depth
=
idleConf
.
GetOption
(
"extensions"
,
"CodeContext"
,
"numlines"
,
type
=
"int"
,
default
=
3
)
bgcolor
=
idleConf
.
GetOption
(
"extensions"
,
"CodeContext"
,
...
...
@@ -54,66 +54,33 @@ class CodeContext:
def
toggle_code_context_event
(
self
,
event
=
None
):
if
not
self
.
label
:
# 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.
# Calculate the border width and horizontal padding required to
# align the context with the text in the main Text widget.
#
# 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
# values may be pixel objects, which can't simply be added to ints.
widgets
=
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
for
widget
in
widgets
:
padx
+=
int
(
str
(
widget
.
pack_info
()[
'padx'
]
))
padx
+=
int
(
str
(
widget
.
cget
(
'padx'
)
))
# Calculate the required border width
border
=
0
for
widget
in
widgets
:
border
+=
int
(
str
(
widget
.
cget
(
'border'
)
))
self
.
label
=
Tkinter
.
Label
(
self
.
editwin
.
top
,
text
=
"
\
n
"
*
(
self
.
context_depth
-
1
),
anchor
=
"w"
,
justify
=
"left"
,
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
,
padx
=
padx
,
border
=
border
,
relief
=
SUNKEN
)
# Pack the label widget before and above the text_frame widget,
# thus ensuring that it will appear directly above text_frame
self
.
label
.
pack
(
side
=
TOP
,
fill
=
X
,
expand
=
False
,
before
=
self
.
editwin
.
text_frame
)
else
:
self
.
label
.
destroy
()
self
.
label
=
None
...
...
@@ -190,7 +157,6 @@ class CodeContext:
stopindent
)
self
.
info
.
extend
(
lines
)
self
.
topvisible
=
new_topvisible
# empty lines in context pane:
context_strings
=
[
""
]
*
max
(
0
,
self
.
context_depth
-
len
(
self
.
info
))
# followed by the context hint lines:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment