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
ed1deb07
Commit
ed1deb07
authored
Feb 27, 2019
by
Cheryl Sabella
Committed by
GitHub
Feb 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-36096: IDLE: Refactor class variables in colorizer (GH-12002)
parent
32f5fdd7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
21 deletions
+58
-21
Lib/idlelib/colorizer.py
Lib/idlelib/colorizer.py
+15
-11
Lib/idlelib/idle_test/test_colorizer.py
Lib/idlelib/idle_test/test_colorizer.py
+42
-10
Misc/NEWS.d/next/IDLE/2019-02-23-17-53-53.bpo-36096.mN5Ly3.rst
...NEWS.d/next/IDLE/2019-02-23-17-53-53.bpo-36096.mN5Ly3.rst
+1
-0
No files found.
Lib/idlelib/colorizer.py
View file @
ed1deb07
...
@@ -55,26 +55,35 @@ def color_config(text):
...
@@ -55,26 +55,35 @@ def color_config(text):
class
ColorDelegator
(
Delegator
):
class
ColorDelegator
(
Delegator
):
"""Delegator for syntax highlighting (text coloring).
"""Delegator for syntax highlighting (text coloring).
Class variables:
Instance variables:
after_id: Identifier for scheduled after event.
delegate: Delegator below this one in the stack, meaning the
one this one delegates to.
Used to track state:
after_id: Identifier for scheduled after event, which is a
timer for colorizing the text.
allow_colorizing: Boolean toggle for applying colorizing.
allow_colorizing: Boolean toggle for applying colorizing.
colorizing: Boolean flag when colorizing is in process.
colorizing: Boolean flag when colorizing is in process.
stop_colorizing: Boolean flag to end an active colorizing
stop_colorizing: Boolean flag to end an active colorizing
process.
process.
close_when_done: Widget to destroy after colorizing process
close_when_done: Widget to destroy after colorizing process
completes (doesn't seem to be used by IDLE).
completes (doesn't seem to be used by IDLE).
Instance variables:
delegate: Delegator below this one in the stack, meaning the
one this one delegates to.
"""
"""
def
__init__
(
self
):
def
__init__
(
self
):
Delegator
.
__init__
(
self
)
Delegator
.
__init__
(
self
)
self
.
init_state
()
self
.
prog
=
prog
self
.
prog
=
prog
self
.
idprog
=
idprog
self
.
idprog
=
idprog
self
.
LoadTagDefs
()
self
.
LoadTagDefs
()
def
init_state
(
self
):
"Initialize variables that track colorizing state."
self
.
after_id
=
None
self
.
allow_colorizing
=
True
self
.
stop_colorizing
=
False
self
.
colorizing
=
False
def
setdelegate
(
self
,
delegate
):
def
setdelegate
(
self
,
delegate
):
"""Set the delegate for this instance.
"""Set the delegate for this instance.
...
@@ -134,11 +143,6 @@ class ColorDelegator(Delegator):
...
@@ -134,11 +143,6 @@ class ColorDelegator(Delegator):
self
.
delegate
.
delete
(
index1
,
index2
)
self
.
delegate
.
delete
(
index1
,
index2
)
self
.
notify_range
(
index1
)
self
.
notify_range
(
index1
)
after_id
=
None
allow_colorizing
=
True
stop_colorizing
=
False
colorizing
=
False
def
notify_range
(
self
,
index1
,
index2
=
None
):
def
notify_range
(
self
,
index1
,
index2
=
None
):
"Mark text changes for processing and restart colorizing, if active."
"Mark text changes for processing and restart colorizing, if active."
self
.
tag_add
(
"TODO"
,
index1
,
index2
)
self
.
tag_add
(
"TODO"
,
index1
,
index2
)
...
...
Lib/idlelib/idle_test/test_colorizer.py
View file @
ed1deb07
...
@@ -100,7 +100,7 @@ class ColorConfigTest(unittest.TestCase):
...
@@ -100,7 +100,7 @@ class ColorConfigTest(unittest.TestCase):
eq
(
text
[
'inactiveselectbackground'
],
'gray'
)
eq
(
text
[
'inactiveselectbackground'
],
'gray'
)
class
ColorDelegatorTest
(
unittest
.
TestCase
):
class
ColorDelegator
Instantiation
Test
(
unittest
.
TestCase
):
@
classmethod
@
classmethod
def
setUpClass
(
cls
):
def
setUpClass
(
cls
):
...
@@ -108,25 +108,19 @@ class ColorDelegatorTest(unittest.TestCase):
...
@@ -108,25 +108,19 @@ class ColorDelegatorTest(unittest.TestCase):
root
=
cls
.
root
=
Tk
()
root
=
cls
.
root
=
Tk
()
root
.
withdraw
()
root
.
withdraw
()
text
=
cls
.
text
=
Text
(
root
)
text
=
cls
.
text
=
Text
(
root
)
cls
.
percolator
=
Percolator
(
text
)
# Delegator stack = [Delagator(text)]
@
classmethod
@
classmethod
def
tearDownClass
(
cls
):
def
tearDownClass
(
cls
):
cls
.
percolator
.
redir
.
close
()
del
cls
.
text
del
cls
.
percolator
,
cls
.
text
cls
.
root
.
update_idletasks
()
cls
.
root
.
update_idletasks
()
cls
.
root
.
destroy
()
cls
.
root
.
destroy
()
del
cls
.
root
del
cls
.
root
def
setUp
(
self
):
def
setUp
(
self
):
self
.
color
=
colorizer
.
ColorDelegator
()
self
.
color
=
colorizer
.
ColorDelegator
()
self
.
percolator
.
insertfilter
(
self
.
color
)
# Calls color.setdelagate(Delagator(text)).
def
tearDown
(
self
):
def
tearDown
(
self
):
self
.
color
.
close
()
self
.
color
.
close
()
self
.
percolator
.
removefilter
(
self
.
color
)
self
.
text
.
delete
(
'1.0'
,
'end'
)
self
.
text
.
delete
(
'1.0'
,
'end'
)
self
.
color
.
resetcache
()
self
.
color
.
resetcache
()
del
self
.
color
del
self
.
color
...
@@ -134,12 +128,50 @@ class ColorDelegatorTest(unittest.TestCase):
...
@@ -134,12 +128,50 @@ class ColorDelegatorTest(unittest.TestCase):
def
test_init
(
self
):
def
test_init
(
self
):
color
=
self
.
color
color
=
self
.
color
self
.
assertIsInstance
(
color
,
colorizer
.
ColorDelegator
)
self
.
assertIsInstance
(
color
,
colorizer
.
ColorDelegator
)
# The following are class variables.
def
test_init_state
(
self
):
# init_state() is called during the instantiation of
# ColorDelegator in setUp().
color
=
self
.
color
self
.
assertIsNone
(
color
.
after_id
)
self
.
assertTrue
(
color
.
allow_colorizing
)
self
.
assertTrue
(
color
.
allow_colorizing
)
self
.
assertFalse
(
color
.
colorizing
)
self
.
assertFalse
(
color
.
colorizing
)
self
.
assertFalse
(
color
.
stop_colorizing
)
class
ColorDelegatorTest
(
unittest
.
TestCase
):
@
classmethod
def
setUpClass
(
cls
):
requires
(
'gui'
)
root
=
cls
.
root
=
Tk
()
root
.
withdraw
()
text
=
cls
.
text
=
Text
(
root
)
cls
.
percolator
=
Percolator
(
text
)
# Delegator stack = [Delegator(text)]
@
classmethod
def
tearDownClass
(
cls
):
cls
.
percolator
.
redir
.
close
()
del
cls
.
percolator
,
cls
.
text
cls
.
root
.
update_idletasks
()
cls
.
root
.
destroy
()
del
cls
.
root
def
setUp
(
self
):
self
.
color
=
colorizer
.
ColorDelegator
()
self
.
percolator
.
insertfilter
(
self
.
color
)
# Calls color.setdelegate(Delegator(text)).
def
tearDown
(
self
):
self
.
color
.
close
()
self
.
percolator
.
removefilter
(
self
.
color
)
self
.
text
.
delete
(
'1.0'
,
'end'
)
self
.
color
.
resetcache
()
del
self
.
color
def
test_setdelegate
(
self
):
def
test_setdelegate
(
self
):
# Called in setUp.
# Called in setUp
when filter is attached to percolator
.
color
=
self
.
color
color
=
self
.
color
self
.
assertIsInstance
(
color
.
delegate
,
colorizer
.
Delegator
)
self
.
assertIsInstance
(
color
.
delegate
,
colorizer
.
Delegator
)
# It is too late to mock notify_range, so test side effect.
# It is too late to mock notify_range, so test side effect.
...
...
Misc/NEWS.d/next/IDLE/2019-02-23-17-53-53.bpo-36096.mN5Ly3.rst
0 → 100644
View file @
ed1deb07
Refactor class variables to instance variables in colorizer.
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