Skip to content

bpo-27099: IDLE - Convert built-in extensions to regular features #2494

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 56 commits into from
Sep 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
5c57faf
parenmatch highlighting options
wohlganger Jun 29, 2017
d49170f
fixed whitespace issue
wohlganger Jun 29, 2017
8c3a966
only select from highlighting options
wohlganger Jun 30, 2017
757bb38
fixed whitespace
wohlganger Jun 30, 2017
d7e136c
whitespace
wohlganger Jun 30, 2017
b178af5
Merge remote-tracking branch 'upstream/master'
wohlganger Jul 10, 2017
2adebb9
#27099 - turn builtin extensions to reg modules
wohlganger Jul 10, 2017
86c3d4c
whitespace + fix I thought I already committed.
wohlganger Jul 10, 2017
1c246fc
warning fixes, removed old config entries
wohlganger Jul 11, 2017
0418ad0
calltip append doc fix, default paren-fore fix, help update
wohlganger Jul 11, 2017
097a0d8
fix calltips
wohlganger Jul 12, 2017
4232e77
removed circular import
wohlganger Jul 12, 2017
a7b29f5
fix warnings due to missing default config options in idlelib.config-…
wohlganger Jul 12, 2017
e30b7b4
Merge branch 'master' into master
wohlganger Jul 17, 2017
252672b
added format_pmaxw to config-main
wohlganger Jul 19, 2017
999b573
Merge remote-tracking branch 'upstream/master'
wohlganger Jul 19, 2017
1a74591
replaced help.html edit with idle.rst edit
wohlganger Jul 20, 2017
3501c45
Merge branch 'master' into master
wohlganger Jul 24, 2017
232f711
Merge remote-tracking branch 'upstream/master'
wohlganger Aug 4, 2017
f095c53
added conflict resolved var descriptions to docstring in create_page_…
wohlganger Aug 4, 2017
a661bfa
strip trailing whitespace
wohlganger Aug 4, 2017
5c90a8f
Merge branch 'master' into master
wohlganger Aug 24, 2017
5a6a007
re-introduced highlight options.
wohlganger Aug 24, 2017
709b434
News blurb.
terryjreedy Aug 24, 2017
b9b1f9a
Reinstated zoomheight as an extension. Replaced autoexpand with zoomh…
wohlganger Aug 24, 2017
8b76ccb
fixed configdialog test (wrong cases), fixed whitespace
wohlganger Aug 24, 2017
b986c12
update idle.rst: zoomheight is an extension.
wohlganger Aug 24, 2017
f86acaa
more fixes for zoomheight - trying to minimize changes from master
wohlganger Aug 24, 2017
5805462
zoomheight config fix, zoomheight should be fully back to the way it …
wohlganger Aug 24, 2017
165b548
whitespace
wohlganger Aug 24, 2017
aee5d02
fixed force-open completions missing from config-keys and config. Fix…
wohlganger Aug 24, 2017
cb161bd
Changes made per terryjreedy request.
wohlganger Aug 25, 2017
dc09a2b
re-added autocomplete wait and format paragraph max width options to …
wohlganger Aug 25, 2017
100463e
Merge branch 'master' into master
wohlganger Aug 28, 2017
3fbaa90
Merge branch 'master' into master
wohlganger Aug 30, 2017
60ff82f
changes per terryjreedy
wohlganger Aug 30, 2017
e3f6f16
fix warnings, errors, bugs
wohlganger Aug 30, 2017
a253f0c
whitespace
wohlganger Aug 30, 2017
fe8eb7a
bugfix
wohlganger Aug 30, 2017
caa7774
Make changes need to get IDLE to run
terryjreedy Aug 31, 2017
c29184e
Edit extension/feature files, making existing tests pass.
terryjreedy Aug 31, 2017
c62f726
Redo feature bindings.
terryjreedy Aug 31, 2017
d0e009f
First draft of dummy extension.
terryjreedy Aug 31, 2017
9e889c2
Fix that eliminate startup error and all but 2 test_idle errors.
terryjreedy Aug 31, 2017
6afdea3
Move widgets, load widgets, add tests, make previous tests pass.
terryjreedy Sep 2, 2017
7de27db
Add format-paragraph to core keys.
terryjreedy Sep 5, 2017
a2e76a7
Merge remote-tracking branch 'origin/master' into pr_2494
terryjreedy Sep 5, 2017
2265b53
Fix autocomplete and long lines.
terryjreedy Sep 5, 2017
03eed24
Put fixed-key event-adds in EditorWindow.__init__ for now.
terryjreedy Sep 9, 2017
207b0ca
Don't warn if new core keys not in user key config.
terryjreedy Sep 9, 2017
00acd22
Make code context inoperative in outwin, shell.
terryjreedy Sep 9, 2017
2d2bfbd
Change new bindings for MacOsx.
terryjreedy Sep 9, 2017
fe76cd3
Disable test dependent on extension Alt keys.
terryjreedy Sep 9, 2017
d2966e0
Minor edits.
terryjreedy Sep 9, 2017
6845bb0
File out news blurb explaining effect for users.
terryjreedy Sep 10, 2017
b7afebb
Don't compute ('') during integer input in entry box.
terryjreedy Sep 10, 2017
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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you move this? Although another issue, really, I can see moving within init to have changes take effect sooner, why make it conditional?

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave 'There is only one instance of AutoExpand'.
This docstring actually belongs with the class, and will have to be moved when files are consolidated -- in another issue.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said and explained on the issue, I want to leave non-key options in config-extensions. So the 4 non-trivial [Xtension] sections should stay. For former extensions, I would like to drop the requirement for an enable option when the entry is read in the editor. Then we can delete the enable items. I believe that this will be back-compatible with existing custom enable settings, but must verify. (Ditto for not requiring some binding section.)

As I said yesterday, I now think the [Xtension_cfgBindings] should go, to be replaced by new entries in keysets. This will require some change in IdleConf to deal better with missing entries in custom keysets. But this was already needed, and perhaps should be a separate preliminary patch.

I think putting non-configurable key bindings in configuration files was a bit of a mistake. In any case, these binding should be hard coded in the appropriate place. At minimum, 'x_keys = idleConf(...)' should be replaced by 'x_keys = (current-idleconf-return).

[AutoComplete_cfgBindings]
force-open-completions=<Control-Key-space>
[AutoComplete_bindings]
autocomplete=<Key-Tab>
Copy link
Member

@terryjreedy terryjreedy Sep 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The '_bindings' entries had two effects:

  1. event_add a virtual event associated with the event sequences.
  2. bind the virtual event to an event handler (named after the event).
    This new line in EditorWindow did the second:
    text.bind("<<autocomplete>>", autocomplete.autocomplete_event)
    The lack of a replacement for 1. disabled the use of tab to open and tab tab to close a completion box. Adding
    self.text.event_add('<<autocomplete>>', '<Key-Tab>')
    in AutoComplete.init fixed the problem. I am thinking that both parts should be in the same file. Either the event_add should be in EditorWindow or the binding should be in AutoComplete. I am leaning toward the latter, but will decide tomorrow.

I decided to put all event_adds in EditorWindow for now. I believe they only need to be called once in the process, not once for every window, but must check and then decide where to put them.

try-open-completions=<KeyRelease-period> <KeyRelease-slash> <KeyRelease-backslash>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you accomplished effect 1 above, event_add(...), by adding the event-sequences pair to core bindings. But this has the bug of adding then to the configure Keys tab. Core bindings are configurable bindings. I will add event_add elsewhere when I decide where.


[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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

refresh-calltip=<KeyRelease-parenright> <KeyRelease-0>
Copy link
Member

@terryjreedy terryjreedy Sep 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs event_add.
The presence of was a bug that caused calltip to flash off and on. I removed it.


[CodeContext]
enable=True
enable_shell=False
numlines=3
visible=False
bgcolor=LightGray
fgcolor=Black
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep

[CodeContext_bindings]
toggle-code-context=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The is a dummy line as there is not key to associate with a virtual event.


[FormatParagraph]
enable=True
max-width=72
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep

[FormatParagraph_cfgBindings]
format-paragraph=<Alt-Key-q>

[ParenMatch]
enable=True
style= expression
flash-delay= 500
bell=True
[ParenMatch_cfgBindings]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep.

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