Skip to content

Commit 77b52e4

Browse files
miss-islingtonterryjreedy
authored andcommitted
[3.6] bpo-31488: IDLE - update former extensions when options change. (GH-3612) (#3613)
When apply ConfigDialog changes, call .reload on each class with non-key options. Change ParenMatch so that updates affect current instances. (cherry picked from commit 5777ecc)
1 parent 2c1c2ca commit 77b52e4

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

Lib/idlelib/configdialog.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@
2727
from idlelib.query import SectionName, HelpSource
2828
from idlelib.tabbedpages import TabbedPageSet
2929
from idlelib.textview import view_text
30+
from idlelib.autocomplete import AutoComplete
31+
from idlelib.codecontext import CodeContext
32+
from idlelib.parenmatch import ParenMatch
33+
from idlelib.paragraph import FormatParagraph
3034

3135
changes = ConfigChanges()
36+
# Reload changed options in the following classes.
37+
reloadables = (AutoComplete, CodeContext, ParenMatch, FormatParagraph)
3238

3339

3440
class ConfigDialog(Toplevel):
@@ -220,6 +226,8 @@ def activate_config_changes(self):
220226
instance.set_notabs_indentwidth()
221227
instance.ApplyKeybindings()
222228
instance.reset_help_menu_entries()
229+
for klass in reloadables:
230+
klass.reload()
223231

224232
def create_page_extensions(self):
225233
"""Part of the config dialog used for configuring IDLE extensions.

Lib/idlelib/idle_test/test_parenmatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_paren_styles(self):
5858
('expression', ('1.10', '1.15'), ('1.10', '1.16'))):
5959
with self.subTest(style=style):
6060
text.delete('1.0', 'end')
61-
pm.set_style(style)
61+
pm.STYLE = style
6262
text.insert('insert', 'def foobar(a, b')
6363

6464
pm.flash_paren_event('event')

Lib/idlelib/parenmatch.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ def __init__(self, editwin):
4545
# and deactivate_restore (which calls event_delete).
4646
editwin.text.bind(self.RESTORE_VIRTUAL_EVENT_NAME,
4747
self.restore_event)
48-
self.bell = self.text.bell if self.BELL else lambda: None
4948
self.counter = 0
5049
self.is_restore_active = 0
51-
self.set_style(self.STYLE)
5250

5351
@classmethod
5452
def reload(cls):
@@ -75,27 +73,11 @@ def deactivate_restore(self):
7573
self.text.event_delete(self.RESTORE_VIRTUAL_EVENT_NAME, seq)
7674
self.is_restore_active = False
7775

78-
def set_style(self, style):
79-
"Set tag and timeout functions."
80-
self.STYLE = style
81-
self.create_tag = (
82-
self.create_tag_opener if style in {"opener", "default"} else
83-
self.create_tag_parens if style == "parens" else
84-
self.create_tag_expression) # "expression" or unknown
85-
86-
self.set_timeout = (self.set_timeout_last if self.FLASH_DELAY else
87-
self.set_timeout_none)
88-
8976
def flash_paren_event(self, event):
9077
"Handle editor 'show surrounding parens' event (menu or shortcut)."
9178
indices = (HyperParser(self.editwin, "insert")
9279
.get_surrounding_brackets())
93-
if indices is None:
94-
self.bell()
95-
return "break"
96-
self.activate_restore()
97-
self.create_tag(indices)
98-
self.set_timeout()
80+
self.finish_paren_event(indices)
9981
return "break"
10082

10183
def paren_closed_event(self, event):
@@ -108,13 +90,19 @@ def paren_closed_event(self, event):
10890
if not hp.is_in_code():
10991
return
11092
indices = hp.get_surrounding_brackets(_openers[closer], True)
111-
if indices is None:
112-
self.bell()
93+
self.finish_paren_event(indices)
94+
return # Allow calltips to see ')'
95+
96+
def finish_paren_event(self, indices):
97+
if indices is None and self.BELL:
98+
self.text.bell()
11399
return
114100
self.activate_restore()
115-
self.create_tag(indices)
116-
self.set_timeout()
117-
return
101+
# self.create_tag(indices)
102+
self.tagfuncs.get(self.STYLE, self.create_tag_expression)(self, indices)
103+
# self.set_timeout()
104+
(self.set_timeout_last if self.FLASH_DELAY else
105+
self.set_timeout_none)()
118106

119107
def restore_event(self, event=None):
120108
"Remove effect of doing match."
@@ -152,6 +140,13 @@ def create_tag_expression(self, indices):
152140
self.text.tag_add("paren", indices[0], rightindex)
153141
self.text.tag_config("paren", self.HILITE_CONFIG)
154142

143+
tagfuncs = {
144+
'opener': create_tag_opener,
145+
'default': create_tag_opener,
146+
'parens': create_tag_parens,
147+
'expression': create_tag_expression,
148+
}
149+
155150
# any one of the set_timeout_XXX methods can be used depending on
156151
# the style
157152

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
IDLE - Update non-key options in former extension classes. When applying
2+
configdialog changes, call .reload for each feature class. Change ParenMatch
3+
so updated options affect existing instances attached to existing editor
4+
windows.

0 commit comments

Comments
 (0)