Skip to content

[3.6] bpo-27099: IDLE - Convert built-in extensions to regular featur… #3487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions Doc/library/idle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -672,23 +672,6 @@ Extensions

IDLE contains an extension facility. Preferences for extensions can be
changed with Configure Extensions. See the beginning of config-extensions.def
in the idlelib directory for further information. The default extensions
are currently:

* FormatParagraph

* AutoExpand

* ZoomHeight

* ScriptBinding

* CallTips

* ParenMatch

* AutoComplete

* CodeContext

* RstripExtension
in the idlelib directory for further information. The only current default
extension is zoomheight. It exists as an extension primarily to be an example
and for testing purposes.
25 changes: 12 additions & 13 deletions Lib/idlelib/autocomplete.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""autocomplete.py - An IDLE extension for automatically completing names.
"""Complete either attribute names or file names.

This extension can complete either attribute names or file names. It can pop
a window with all available names, for the user to select from.
Either on demand or after a user-selected delay after a key character,
pop up a list of candidates.
"""
import os
import string
Expand All @@ -27,18 +27,9 @@

class AutoComplete:

menudefs = [
('edit', [
("Show Completions", "<<force-open-completions>>"),
])
]

popupwait = idleConf.GetOption("extensions", "AutoComplete",
"popupwait", type="int", default=0)

def __init__(self, editwin=None):
self.editwin = editwin
if editwin is not None: # not in subprocess or test
if editwin is not None: # not in subprocess or test
self.text = editwin.text
self.autocompletewindow = None
# id of delayed call, and the index of the text insert when
Expand All @@ -47,6 +38,11 @@ def __init__(self, editwin=None):
self._delayed_completion_id = None
self._delayed_completion_index = None

@classmethod
def reload(cls):
cls.popupwait = idleConf.GetOption(
"extensions", "AutoComplete", "popupwait", type="int", default=0)

def _make_autocomplete_window(self):
return autocomplete_w.AutoCompleteWindow(self.text)

Expand Down Expand Up @@ -228,6 +224,9 @@ def get_entity(self, name):
return eval(name, namespace)


AutoComplete.reload()


if __name__ == '__main__':
from unittest import main
main('idlelib.idle_test.test_autocomplete', verbosity=2)
13 changes: 2 additions & 11 deletions Lib/idlelib/autoexpand.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,13 @@
place before requesting the next selection causes AutoExpand to reset
its state.

This is an extension file and there is only one instance of AutoExpand.
There is only one instance of Autoexpand.
'''
import re
import string

###$ event <<expand-word>>
###$ win <Alt-slash>
###$ unix <Alt-slash>

class AutoExpand:

menudefs = [
('edit', [
('E_xpand Word', '<<expand-word>>'),
]),
]

wordchars = string.ascii_letters + string.digits + "_"

def __init__(self, editwin):
Expand Down Expand Up @@ -100,6 +90,7 @@ def getprevword(self):
i = i-1
return line[i:]


if __name__ == '__main__':
import unittest
unittest.main('idlelib.idle_test.test_autoexpand', verbosity=2)
12 changes: 3 additions & 9 deletions Lib/idlelib/calltips.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""calltips.py - An IDLE Extension to Jog Your Memory
"""Pop up a reminder of how to call a function.

Call Tips are floating windows which display function, class, and method
parameter and docstring information when you type an opening parenthesis, and
which disappear when you type a closing parenthesis.

"""
import inspect
import re
Expand All @@ -15,13 +14,8 @@
from idlelib.hyperparser import HyperParser
import __main__

class CallTips:

menudefs = [
('edit', [
("Show call tip", "<<force-open-calltip>>"),
])
]
class CallTips:

def __init__(self, editwin=None):
if editwin is None: # subprocess and test
Expand Down Expand Up @@ -103,6 +97,7 @@ def fetch_tip(self, expression):
else:
return get_argspec(get_entity(expression))


def get_entity(expression):
"""Return the object corresponding to expression evaluated
in a namespace spanning sys.modules and __main.dict__.
Expand All @@ -126,7 +121,6 @@ def get_entity(expression):
_invalid_method = "invalid method signature"
_argument_positional = "\n['/' marks preceding arguments as positional-only]\n"


def get_argspec(ob):
'''Return a string describing the signature of a callable object, or ''.

Expand Down
26 changes: 16 additions & 10 deletions Lib/idlelib/codecontext.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""codecontext - Extension to display the block context above the edit window
"""codecontext - display the block context above the edit window

Once code has scrolled off the top of a window, it can be difficult to
determine which block you are in. This extension implements a pane at the top
Expand All @@ -25,10 +25,8 @@
getspacesfirstword =\
lambda s, c=re.compile(r"^(\s*)(\w*)"): c.match(s).groups()


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",
"bgcolor", type="str", default="LightGray")
fgcolor = idleConf.GetOption("extensions", "CodeContext",
Expand All @@ -45,15 +43,20 @@ def __init__(self, editwin):
# starts the toplevel 'block' of the module.
self.info = [(0, -1, "", False)]
self.topvisible = 1
visible = idleConf.GetOption("extensions", "CodeContext",
"visible", type="bool", default=False)
if visible:
self.toggle_code_context_event()
self.editwin.setvar('<<toggle-code-context>>', True)
self.reload()
# Start two update cycles, one for context lines, one for font changes.
self.text.after(UPDATEINTERVAL, self.timer_event)
self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)

@classmethod
def reload(cls):
cls.context_depth = idleConf.GetOption("extensions", "CodeContext",
"numlines", type="int", default=3)
cls.bgcolor = idleConf.GetOption("extensions", "CodeContext",
"bgcolor", type="str", default="LightGray")
cls.fgcolor = idleConf.GetOption("extensions", "CodeContext",
"fgcolor", type="str", default="Black")

def toggle_code_context_event(self, event=None):
if not self.label:
# Calculate the border width and horizontal padding required to
Expand Down Expand Up @@ -86,7 +89,7 @@ def toggle_code_context_event(self, event=None):
else:
self.label.destroy()
self.label = None
idleConf.SetOption("extensions", "CodeContext", "visible",
idleConf.SetOption("main", "Theme", "contexton",
str(self.label is not None))
idleConf.SaveUserCfgFiles()
return "break"
Expand Down Expand Up @@ -177,3 +180,6 @@ def font_timer_event(self):
self.textfont = newtextfont
self.label["font"] = self.textfont
self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)


CodeContext.reload()
98 changes: 32 additions & 66 deletions Lib/idlelib/config-extensions.def
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# config-extensions.def
#
# The following sections are for features that are no longer extensions.
# Their options values are left here for back-compatibility.

[AutoComplete]
popupwait= 2000

[CodeContext]
numlines= 3
visible= False
bgcolor= LightGray
fgcolor= Black

[FormatParagraph]
max-width= 72

[ParenMatch]
style= expression
flash-delay= 500
bell= True

# IDLE reads several config files to determine user preferences. This
# file is the default configuration file for IDLE extensions settings.
#
Expand All @@ -19,7 +39,7 @@
# extension that may be sensibly re-configured.
#
# If there are no keybindings for a menus' virtual events, include lines
# like <<toggle-code-context>>= (See [CodeContext], below.)
# like <<toggle-code-context>>=.
#
# Currently it is necessary to manually modify this file to change
# extension key bindings and default values. To customize, create
Expand All @@ -32,68 +52,14 @@
# See config-keys.def for notes on specifying keys and extend.txt for
# information on creating IDLE extensions.

[AutoComplete]
enable=True
popupwait=2000
[AutoComplete_cfgBindings]
force-open-completions=<Control-Key-space>
[AutoComplete_bindings]
autocomplete=<Key-Tab>
try-open-completions=<KeyRelease-period> <KeyRelease-slash> <KeyRelease-backslash>

[AutoExpand]
enable=True
[AutoExpand_cfgBindings]
expand-word=<Alt-Key-slash>

[CallTips]
enable=True
[CallTips_cfgBindings]
force-open-calltip=<Control-Key-backslash>
[CallTips_bindings]
try-open-calltip=<KeyRelease-parenleft>
refresh-calltip=<KeyRelease-parenright> <KeyRelease-0>

[CodeContext]
enable=True
enable_shell=False
numlines=3
visible=False
bgcolor=LightGray
fgcolor=Black
[CodeContext_bindings]
toggle-code-context=

[FormatParagraph]
enable=True
max-width=72
[FormatParagraph_cfgBindings]
format-paragraph=<Alt-Key-q>

[ParenMatch]
enable=True
style= expression
flash-delay= 500
bell=True
[ParenMatch_cfgBindings]
flash-paren=<Control-Key-0>
[ParenMatch_bindings]
paren-closed=<KeyRelease-parenright> <KeyRelease-bracketright> <KeyRelease-braceright>

[RstripExtension]
enable=True
enable_shell=False
enable_editor=True

[ScriptBinding]
enable=True
enable_shell=False
enable_editor=True
[ScriptBinding_cfgBindings]
run-module=<Key-F5>
check-module=<Alt-Key-x>

[ZoomHeight]
enable=True
[ZoomHeight_cfgBindings]
zoom-height=<Alt-Key-2>
# A fake extension for testing and example purposes. When enabled and
# invoked, inserts or deletes z-text at beginning of every line.
[ZzDummy]
enable= True
enable_shell = False
enable_editor = True
z-text= Z
[ZzDummy_cfgBindings]
z-in= <Control-Shift-KeyRelease-Insert>
[ZzDummy_bindings]
z-out= <Control-Shift-KeyRelease-Delete>
Loading