Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9c28449

Browse files
ZackerySpytzterryjreedy
authored andcommittedNov 13, 2019
bpo-4630: Add cursor no-blink option for IDLE (pythonGH-16960)
This immediately toggles shell, editor, and output windows, but does not affect other input widgets.
1 parent 2d56af7 commit 9c28449

File tree

7 files changed

+48
-1
lines changed

7 files changed

+48
-1
lines changed
 

‎Lib/idlelib/NEWS.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ Released on 2020-10-05?
33
======================================
44

55

6-
bop-26353: Stop adding newline when saving an IDLE shell window.
6+
bpo-4360: Add an option to toggle IDLE's cursor blink for shell,
7+
editor, and output windows. See Settings, General, Window Preferences,
8+
Cursor Blink. Patch by Zachary Spytz.
9+
10+
bpo-26353: Stop adding newline when saving an IDLE shell window.
711

812
bpo-38598: Do not try to compile IDLE shell or output windows.
913

‎Lib/idlelib/config-main.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ delete-exitfunc= 1
5959
[EditorWindow]
6060
width= 80
6161
height= 40
62+
cursor-blink= 1
6263
font= TkFixedFont
6364
# For TkFixedFont, the actual size and boldness are obtained from tk
6465
# and override 10 and 0. See idlelib.config.IdleConf.GetFont

‎Lib/idlelib/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ def __init__(self, _utest=False):
158158
self.defaultCfg = {}
159159
self.userCfg = {}
160160
self.cfg = {} # TODO use to select userCfg vs defaultCfg
161+
# self.blink_off_time = <first editor text>['insertofftime']
162+
# See https:/bugs.python.org/issue4630, msg356516.
161163

162164
if not _utest:
163165
self.CreateConfigHandlers()

‎Lib/idlelib/configdialog.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ def activate_config_changes(self):
236236
instance.set_notabs_indentwidth()
237237
instance.ApplyKeybindings()
238238
instance.reset_help_menu_entries()
239+
instance.update_cursor_blink()
239240
for klass in reloadables:
240241
klass.reload()
241242

@@ -1820,6 +1821,9 @@ def create_page_general(self):
18201821
(*)win_width_int: Entry - win_width
18211822
win_height_title: Label
18221823
(*)win_height_int: Entry - win_height
1824+
frame_cursor_blink: Frame
1825+
cursor_blink_title: Label
1826+
(*)cursor_blink_bool: Checkbutton - cursor_blink
18231827
frame_autocomplete: Frame
18241828
auto_wait_title: Label
18251829
(*)auto_wait_int: Entry - autocomplete_wait
@@ -1864,6 +1868,8 @@ def create_page_general(self):
18641868
StringVar(self), ('main', 'EditorWindow', 'width'))
18651869
self.win_height = tracers.add(
18661870
StringVar(self), ('main', 'EditorWindow', 'height'))
1871+
self.cursor_blink = tracers.add(
1872+
BooleanVar(self), ('main', 'EditorWindow', 'cursor-blink'))
18671873
self.autocomplete_wait = tracers.add(
18681874
StringVar(self), ('extensions', 'AutoComplete', 'popupwait'))
18691875
self.paren_style = tracers.add(
@@ -1920,6 +1926,11 @@ def create_page_general(self):
19201926
validatecommand=self.digits_only, validate='key',
19211927
)
19221928

1929+
frame_cursor_blink = Frame(frame_window, borderwidth=0)
1930+
cursor_blink_title = Label(frame_cursor_blink, text='Cursor Blink')
1931+
self.cursor_blink_bool = Checkbutton(frame_cursor_blink,
1932+
variable=self.cursor_blink, width=1)
1933+
19231934
frame_autocomplete = Frame(frame_window, borderwidth=0,)
19241935
auto_wait_title = Label(frame_autocomplete,
19251936
text='Completions Popup Wait (milliseconds)')
@@ -2024,6 +2035,10 @@ def create_page_general(self):
20242035
win_height_title.pack(side=RIGHT, anchor=E, pady=5)
20252036
self.win_width_int.pack(side=RIGHT, anchor=E, padx=10, pady=5)
20262037
win_width_title.pack(side=RIGHT, anchor=E, pady=5)
2038+
# frame_cursor_blink.
2039+
frame_cursor_blink.pack(side=TOP, padx=5, pady=0, fill=X)
2040+
cursor_blink_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
2041+
self.cursor_blink_bool.pack(side=LEFT, padx=5, pady=5)
20272042
# frame_autocomplete.
20282043
frame_autocomplete.pack(side=TOP, padx=5, pady=0, fill=X)
20292044
auto_wait_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
@@ -2078,6 +2093,8 @@ def load_general_cfg(self):
20782093
'main', 'EditorWindow', 'width', type='int'))
20792094
self.win_height.set(idleConf.GetOption(
20802095
'main', 'EditorWindow', 'height', type='int'))
2096+
self.cursor_blink.set(idleConf.GetOption(
2097+
'main', 'EditorWindow', 'cursor-blink', type='bool'))
20812098
self.autocomplete_wait.set(idleConf.GetOption(
20822099
'extensions', 'AutoComplete', 'popupwait', type='int'))
20832100
self.paren_style.set(idleConf.GetOption(

‎Lib/idlelib/editor.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
241241
self.indentwidth = self.tabwidth
242242
self.set_notabs_indentwidth()
243243

244+
# Store the current value of the insertofftime now so we can restore
245+
# it if needed.
246+
if not hasattr(idleConf, 'blink_off_time'):
247+
idleConf.blink_off_time = self.text['insertofftime']
248+
self.update_cursor_blink()
249+
244250
# When searching backwards for a reliable place to begin parsing,
245251
# first start num_context_lines[0] lines back, then
246252
# num_context_lines[1] lines back if that didn't work, and so on.
@@ -803,6 +809,16 @@ def colorize_syntax_error(self, text, pos):
803809
text.mark_set("insert", pos + "+1c")
804810
text.see(pos)
805811

812+
def update_cursor_blink(self):
813+
"Update the cursor blink configuration."
814+
cursorblink = idleConf.GetOption(
815+
'main', 'EditorWindow', 'cursor-blink', type='bool')
816+
if not cursorblink:
817+
self.text['insertofftime'] = 0
818+
else:
819+
# Restore the original value
820+
self.text['insertofftime'] = idleConf.blink_off_time
821+
806822
def ResetFont(self):
807823
"Update the text widgets' font if it is changed"
808824
# Called from configdialog.py

‎Lib/idlelib/idle_test/test_configdialog.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,10 @@ def test_editor_size(self):
11351135
d.win_width_int.insert(0, '11')
11361136
self.assertEqual(mainpage, {'EditorWindow': {'width': '11'}})
11371137

1138+
def test_cursor_blink(self):
1139+
self.page.cursor_blink_bool.invoke()
1140+
self.assertEqual(mainpage, {'EditorWindow': {'cursor-blink': 'False'}})
1141+
11381142
def test_autocomplete_wait(self):
11391143
self.page.auto_wait_int.delete(0, 'end')
11401144
self.page.auto_wait_int.insert(0, '11')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add an option to toggle IDLE's cursor blink for shell, editor, and output
2+
windows. See Settings, General, Window Preferences, Cursor Blink.
3+
Patch by Zachary Spytz.

0 commit comments

Comments
 (0)
Please sign in to comment.