mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-31488: IDLE - update former extensions when options change. (#3612)
When apply changes, call .reload on each class with non-key options. Change ParenMatch so that updates affect current instances.
This commit is contained in:
parent
3f9eee6eb4
commit
5777ecc438
4 changed files with 32 additions and 25 deletions
|
@ -27,8 +27,14 @@ from idlelib import macosx
|
||||||
from idlelib.query import SectionName, HelpSource
|
from idlelib.query import SectionName, HelpSource
|
||||||
from idlelib.tabbedpages import TabbedPageSet
|
from idlelib.tabbedpages import TabbedPageSet
|
||||||
from idlelib.textview import view_text
|
from idlelib.textview import view_text
|
||||||
|
from idlelib.autocomplete import AutoComplete
|
||||||
|
from idlelib.codecontext import CodeContext
|
||||||
|
from idlelib.parenmatch import ParenMatch
|
||||||
|
from idlelib.paragraph import FormatParagraph
|
||||||
|
|
||||||
changes = ConfigChanges()
|
changes = ConfigChanges()
|
||||||
|
# Reload changed options in the following classes.
|
||||||
|
reloadables = (AutoComplete, CodeContext, ParenMatch, FormatParagraph)
|
||||||
|
|
||||||
|
|
||||||
class ConfigDialog(Toplevel):
|
class ConfigDialog(Toplevel):
|
||||||
|
@ -220,6 +226,8 @@ class ConfigDialog(Toplevel):
|
||||||
instance.set_notabs_indentwidth()
|
instance.set_notabs_indentwidth()
|
||||||
instance.ApplyKeybindings()
|
instance.ApplyKeybindings()
|
||||||
instance.reset_help_menu_entries()
|
instance.reset_help_menu_entries()
|
||||||
|
for klass in reloadables:
|
||||||
|
klass.reload()
|
||||||
|
|
||||||
def create_page_extensions(self):
|
def create_page_extensions(self):
|
||||||
"""Part of the config dialog used for configuring IDLE extensions.
|
"""Part of the config dialog used for configuring IDLE extensions.
|
||||||
|
|
|
@ -58,7 +58,7 @@ class ParenMatchTest(unittest.TestCase):
|
||||||
('expression', ('1.10', '1.15'), ('1.10', '1.16'))):
|
('expression', ('1.10', '1.15'), ('1.10', '1.16'))):
|
||||||
with self.subTest(style=style):
|
with self.subTest(style=style):
|
||||||
text.delete('1.0', 'end')
|
text.delete('1.0', 'end')
|
||||||
pm.set_style(style)
|
pm.STYLE = style
|
||||||
text.insert('insert', 'def foobar(a, b')
|
text.insert('insert', 'def foobar(a, b')
|
||||||
|
|
||||||
pm.flash_paren_event('event')
|
pm.flash_paren_event('event')
|
||||||
|
|
|
@ -45,10 +45,8 @@ class ParenMatch:
|
||||||
# and deactivate_restore (which calls event_delete).
|
# and deactivate_restore (which calls event_delete).
|
||||||
editwin.text.bind(self.RESTORE_VIRTUAL_EVENT_NAME,
|
editwin.text.bind(self.RESTORE_VIRTUAL_EVENT_NAME,
|
||||||
self.restore_event)
|
self.restore_event)
|
||||||
self.bell = self.text.bell if self.BELL else lambda: None
|
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
self.is_restore_active = 0
|
self.is_restore_active = 0
|
||||||
self.set_style(self.STYLE)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def reload(cls):
|
def reload(cls):
|
||||||
|
@ -75,27 +73,11 @@ class ParenMatch:
|
||||||
self.text.event_delete(self.RESTORE_VIRTUAL_EVENT_NAME, seq)
|
self.text.event_delete(self.RESTORE_VIRTUAL_EVENT_NAME, seq)
|
||||||
self.is_restore_active = False
|
self.is_restore_active = False
|
||||||
|
|
||||||
def set_style(self, style):
|
|
||||||
"Set tag and timeout functions."
|
|
||||||
self.STYLE = style
|
|
||||||
self.create_tag = (
|
|
||||||
self.create_tag_opener if style in {"opener", "default"} else
|
|
||||||
self.create_tag_parens if style == "parens" else
|
|
||||||
self.create_tag_expression) # "expression" or unknown
|
|
||||||
|
|
||||||
self.set_timeout = (self.set_timeout_last if self.FLASH_DELAY else
|
|
||||||
self.set_timeout_none)
|
|
||||||
|
|
||||||
def flash_paren_event(self, event):
|
def flash_paren_event(self, event):
|
||||||
"Handle editor 'show surrounding parens' event (menu or shortcut)."
|
"Handle editor 'show surrounding parens' event (menu or shortcut)."
|
||||||
indices = (HyperParser(self.editwin, "insert")
|
indices = (HyperParser(self.editwin, "insert")
|
||||||
.get_surrounding_brackets())
|
.get_surrounding_brackets())
|
||||||
if indices is None:
|
self.finish_paren_event(indices)
|
||||||
self.bell()
|
|
||||||
return "break"
|
|
||||||
self.activate_restore()
|
|
||||||
self.create_tag(indices)
|
|
||||||
self.set_timeout()
|
|
||||||
return "break"
|
return "break"
|
||||||
|
|
||||||
def paren_closed_event(self, event):
|
def paren_closed_event(self, event):
|
||||||
|
@ -108,13 +90,19 @@ class ParenMatch:
|
||||||
if not hp.is_in_code():
|
if not hp.is_in_code():
|
||||||
return
|
return
|
||||||
indices = hp.get_surrounding_brackets(_openers[closer], True)
|
indices = hp.get_surrounding_brackets(_openers[closer], True)
|
||||||
if indices is None:
|
self.finish_paren_event(indices)
|
||||||
self.bell()
|
return # Allow calltips to see ')'
|
||||||
|
|
||||||
|
def finish_paren_event(self, indices):
|
||||||
|
if indices is None and self.BELL:
|
||||||
|
self.text.bell()
|
||||||
return
|
return
|
||||||
self.activate_restore()
|
self.activate_restore()
|
||||||
self.create_tag(indices)
|
# self.create_tag(indices)
|
||||||
self.set_timeout()
|
self.tagfuncs.get(self.STYLE, self.create_tag_expression)(self, indices)
|
||||||
return
|
# self.set_timeout()
|
||||||
|
(self.set_timeout_last if self.FLASH_DELAY else
|
||||||
|
self.set_timeout_none)()
|
||||||
|
|
||||||
def restore_event(self, event=None):
|
def restore_event(self, event=None):
|
||||||
"Remove effect of doing match."
|
"Remove effect of doing match."
|
||||||
|
@ -152,6 +140,13 @@ class ParenMatch:
|
||||||
self.text.tag_add("paren", indices[0], rightindex)
|
self.text.tag_add("paren", indices[0], rightindex)
|
||||||
self.text.tag_config("paren", self.HILITE_CONFIG)
|
self.text.tag_config("paren", self.HILITE_CONFIG)
|
||||||
|
|
||||||
|
tagfuncs = {
|
||||||
|
'opener': create_tag_opener,
|
||||||
|
'default': create_tag_opener,
|
||||||
|
'parens': create_tag_parens,
|
||||||
|
'expression': create_tag_expression,
|
||||||
|
}
|
||||||
|
|
||||||
# any one of the set_timeout_XXX methods can be used depending on
|
# any one of the set_timeout_XXX methods can be used depending on
|
||||||
# the style
|
# the style
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
IDLE - Update non-key options in former extension classes. When applying
|
||||||
|
configdialog changes, call .reload for each feature class. Change ParenMatch
|
||||||
|
so updated options affect existing instances attached to existing editor
|
||||||
|
windows.
|
Loading…
Add table
Add a link
Reference in a new issue