mirror of
https://github.com/python/cpython.git
synced 2025-09-27 18:59:43 +00:00
Corrected some bugs in AutoComplete. Also, Page Up/Down in ACW implemented;
mouse and cursor selection in ACWindow implemented; double Tab inserts current selection and closes ACW (similar to double-click and Return); scroll wheel now works in ACW. Added AutoComplete instructions to IDLE Help.
This commit is contained in:
parent
4c11a92625
commit
209de1f6ca
3 changed files with 103 additions and 21 deletions
|
@ -10,13 +10,14 @@ HIDE_SEQUENCES = ("<FocusOut>", "<ButtonPress>")
|
||||||
KEYPRESS_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keypress>>"
|
KEYPRESS_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keypress>>"
|
||||||
# We need to bind event beyond <Key> so that the function will be called
|
# We need to bind event beyond <Key> so that the function will be called
|
||||||
# before the default specific IDLE function
|
# before the default specific IDLE function
|
||||||
KEYPRESS_SEQUENCES = ("<Key>", "<Key-BackSpace>", "<Key-Return>",
|
KEYPRESS_SEQUENCES = ("<Key>", "<Key-BackSpace>", "<Key-Return>", "<Key-Tab>",
|
||||||
"<Key-Up>", "<Key-Down>", "<Key-Home>", "<Key-End>")
|
"<Key-Up>", "<Key-Down>", "<Key-Home>", "<Key-End>",
|
||||||
|
"<Key-Prior>", "<Key-Next>")
|
||||||
KEYRELEASE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keyrelease>>"
|
KEYRELEASE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keyrelease>>"
|
||||||
KEYRELEASE_SEQUENCE = "<KeyRelease>"
|
KEYRELEASE_SEQUENCE = "<KeyRelease>"
|
||||||
LISTUPDATE_SEQUENCE = "<ButtonRelease>"
|
LISTUPDATE_SEQUENCE = "<B1-ButtonRelease>"
|
||||||
WINCONFIG_SEQUENCE = "<Configure>"
|
WINCONFIG_SEQUENCE = "<Configure>"
|
||||||
DOUBLECLICK_SEQUENCE = "<Double-ButtonRelease>"
|
DOUBLECLICK_SEQUENCE = "<B1-Double-ButtonRelease>"
|
||||||
|
|
||||||
class AutoCompleteWindow:
|
class AutoCompleteWindow:
|
||||||
|
|
||||||
|
@ -49,6 +50,8 @@ class AutoCompleteWindow:
|
||||||
# event ids
|
# event ids
|
||||||
self.hideid = self.keypressid = self.listupdateid = self.winconfigid \
|
self.hideid = self.keypressid = self.listupdateid = self.winconfigid \
|
||||||
= self.keyreleaseid = self.doubleclickid = None
|
= self.keyreleaseid = self.doubleclickid = None
|
||||||
|
# Flag set if last keypress was a tab
|
||||||
|
self.lastkey_was_tab = False
|
||||||
|
|
||||||
def _change_start(self, newstart):
|
def _change_start(self, newstart):
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -118,11 +121,6 @@ class AutoCompleteWindow:
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(lts) and i < len(selstart) and lts[i] == selstart[i]:
|
while i < len(lts) and i < len(selstart) and lts[i] == selstart[i]:
|
||||||
i += 1
|
i += 1
|
||||||
previous_completion = self.completions[cursel - 1]
|
|
||||||
while cursel > 0 and selstart[:i] <= previous_completion:
|
|
||||||
i += 1
|
|
||||||
if selstart == previous_completion:
|
|
||||||
break # maybe we have a duplicate?
|
|
||||||
newstart = selstart[:i]
|
newstart = selstart[:i]
|
||||||
self._change_start(newstart)
|
self._change_start(newstart)
|
||||||
|
|
||||||
|
@ -206,7 +204,7 @@ class AutoCompleteWindow:
|
||||||
self.keyrelease_event)
|
self.keyrelease_event)
|
||||||
self.widget.event_add(KEYRELEASE_VIRTUAL_EVENT_NAME,KEYRELEASE_SEQUENCE)
|
self.widget.event_add(KEYRELEASE_VIRTUAL_EVENT_NAME,KEYRELEASE_SEQUENCE)
|
||||||
self.listupdateid = listbox.bind(LISTUPDATE_SEQUENCE,
|
self.listupdateid = listbox.bind(LISTUPDATE_SEQUENCE,
|
||||||
self.listupdate_event)
|
self.listselect_event)
|
||||||
self.winconfigid = acw.bind(WINCONFIG_SEQUENCE, self.winconfig_event)
|
self.winconfigid = acw.bind(WINCONFIG_SEQUENCE, self.winconfig_event)
|
||||||
self.doubleclickid = listbox.bind(DOUBLECLICK_SEQUENCE,
|
self.doubleclickid = listbox.bind(DOUBLECLICK_SEQUENCE,
|
||||||
self.doubleclick_event)
|
self.doubleclick_event)
|
||||||
|
@ -237,11 +235,12 @@ class AutoCompleteWindow:
|
||||||
return
|
return
|
||||||
self.hide_window()
|
self.hide_window()
|
||||||
|
|
||||||
def listupdate_event(self, event):
|
def listselect_event(self, event):
|
||||||
if not self.is_active():
|
if not self.is_active():
|
||||||
return
|
return
|
||||||
self.userwantswindow = True
|
self.userwantswindow = True
|
||||||
self._selection_changed()
|
cursel = int(self.listbox.curselection()[0])
|
||||||
|
self._change_start(self.completions[cursel])
|
||||||
|
|
||||||
def doubleclick_event(self, event):
|
def doubleclick_event(self, event):
|
||||||
# Put the selected completion in the text, and close the list
|
# Put the selected completion in the text, and close the list
|
||||||
|
@ -257,7 +256,8 @@ class AutoCompleteWindow:
|
||||||
state = event.mc_state
|
state = event.mc_state
|
||||||
else:
|
else:
|
||||||
state = 0
|
state = 0
|
||||||
|
if keysym != "Tab":
|
||||||
|
self.lastkey_was_tab = False
|
||||||
if (len(keysym) == 1 or keysym in ("underscore", "BackSpace")
|
if (len(keysym) == 1 or keysym in ("underscore", "BackSpace")
|
||||||
or (self.mode==AutoComplete.COMPLETE_FILES and keysym in
|
or (self.mode==AutoComplete.COMPLETE_FILES and keysym in
|
||||||
("period", "minus"))) \
|
("period", "minus"))) \
|
||||||
|
@ -339,12 +339,20 @@ class AutoCompleteWindow:
|
||||||
self.listbox.select_clear(cursel)
|
self.listbox.select_clear(cursel)
|
||||||
self.listbox.select_set(newsel)
|
self.listbox.select_set(newsel)
|
||||||
self._selection_changed()
|
self._selection_changed()
|
||||||
|
self._change_start(self.completions[newsel])
|
||||||
return "break"
|
return "break"
|
||||||
|
|
||||||
elif (keysym == "Tab" and not state):
|
elif (keysym == "Tab" and not state):
|
||||||
# The user wants a completion, but it is handled by AutoComplete
|
if self.lastkey_was_tab:
|
||||||
# (not AutoCompleteWindow), so ignore.
|
# two tabs in a row; insert current selection and close acw
|
||||||
|
cursel = int(self.listbox.curselection()[0])
|
||||||
|
self._change_start(self.completions[cursel])
|
||||||
|
self.hide_window()
|
||||||
|
return "break"
|
||||||
|
else:
|
||||||
|
# first tab; let AutoComplete handle the completion
|
||||||
self.userwantswindow = True
|
self.userwantswindow = True
|
||||||
|
self.lastkey_was_tab = True
|
||||||
return
|
return
|
||||||
|
|
||||||
elif reduce(lambda x, y: x or y,
|
elif reduce(lambda x, y: x or y,
|
||||||
|
|
|
@ -3,6 +3,11 @@ What's New in IDLE 2.6a1?
|
||||||
|
|
||||||
*Release date: XX-XXX-200X*
|
*Release date: XX-XXX-200X*
|
||||||
|
|
||||||
|
- Corrected some bugs in AutoComplete. Also, Page Up/Down in ACW implemented;
|
||||||
|
mouse and cursor selection in ACWindow implemented; double Tab inserts
|
||||||
|
current selection and closes ACW (similar to double-click and Return); scroll
|
||||||
|
wheel now works in ACW. Added AutoComplete instructions to IDLE Help.
|
||||||
|
|
||||||
- AutoCompleteWindow moved below input line, will move above if there
|
- AutoCompleteWindow moved below input line, will move above if there
|
||||||
isn't enough space. Patch 1621265 Tal Einat
|
isn't enough space. Patch 1621265 Tal Einat
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,10 @@ Edit Menu:
|
||||||
Find in Files... -- Open a search dialog box for searching files
|
Find in Files... -- Open a search dialog box for searching files
|
||||||
Replace... -- Open a search-and-replace dialog box
|
Replace... -- Open a search-and-replace dialog box
|
||||||
Go to Line -- Ask for a line number and show that line
|
Go to Line -- Ask for a line number and show that line
|
||||||
|
Show Calltip -- Open a small window with function param hints
|
||||||
|
Show Completions -- Open a scroll window allowing selection keywords
|
||||||
|
and attributes. (see '*TIPS*', below)
|
||||||
|
Show Parens -- Highlight the surrounding parenthesis
|
||||||
Expand Word -- Expand the word you have typed to match another
|
Expand Word -- Expand the word you have typed to match another
|
||||||
word in the same buffer; repeat to get a
|
word in the same buffer; repeat to get a
|
||||||
different expansion
|
different expansion
|
||||||
|
@ -91,6 +95,7 @@ Options Menu:
|
||||||
Code Context -- Open a pane at the top of the edit window which
|
Code Context -- Open a pane at the top of the edit window which
|
||||||
shows the block context of the section of code
|
shows the block context of the section of code
|
||||||
which is scrolling off the top or the window.
|
which is scrolling off the top or the window.
|
||||||
|
(Not present in Shell window.)
|
||||||
|
|
||||||
Windows Menu:
|
Windows Menu:
|
||||||
|
|
||||||
|
@ -138,8 +143,11 @@ Basic editing and navigation:
|
||||||
Control-left/right Arrow moves by words in a strange but useful way.
|
Control-left/right Arrow moves by words in a strange but useful way.
|
||||||
Home/End go to begin/end of line.
|
Home/End go to begin/end of line.
|
||||||
Control-Home/End go to begin/end of file.
|
Control-Home/End go to begin/end of file.
|
||||||
Some useful Emacs bindings (Control-a, Control-e, Control-k, etc.)
|
Some useful Emacs bindings are inherited from Tcl/Tk:
|
||||||
are inherited from Tcl/Tk.
|
Control-a beginning of line
|
||||||
|
Control-e end of line
|
||||||
|
Control-k kill line (but doesn't put it in clipboard)
|
||||||
|
Control-l center window around the insertion point
|
||||||
Standard Windows bindings may work on that platform.
|
Standard Windows bindings may work on that platform.
|
||||||
Keybindings are selected in the Settings Dialog, look there.
|
Keybindings are selected in the Settings Dialog, look there.
|
||||||
|
|
||||||
|
@ -155,6 +163,52 @@ Automatic indentation:
|
||||||
|
|
||||||
See also the indent/dedent region commands in the edit menu.
|
See also the indent/dedent region commands in the edit menu.
|
||||||
|
|
||||||
|
Completions:
|
||||||
|
|
||||||
|
Completions are supplied for functions, classes, and attributes of
|
||||||
|
classes, both built-in and user-defined. Completions are also provided
|
||||||
|
for filenames.
|
||||||
|
|
||||||
|
The AutoCompleteWindow (ACW) will open after a predefined delay
|
||||||
|
(default is two seconds) after a '.' or (in a string) an os.sep is
|
||||||
|
typed. If after one of those characters (plus zero or more other
|
||||||
|
characters) you type a Tab the ACW will open immediately if a possible
|
||||||
|
continuation is found.
|
||||||
|
|
||||||
|
If there is only one possible completion for the characters entered, a
|
||||||
|
Tab will supply that completion without opening the ACW.
|
||||||
|
|
||||||
|
'Show Completions' will force open a completions window. In an empty
|
||||||
|
string, this will contain the files in the current directory. On a
|
||||||
|
blank line, it will contain the built-in and user-defined functions and
|
||||||
|
classes in the current name spaces, plus any modules imported. If some
|
||||||
|
characters have been entered, the ACW will attempt to be more specific.
|
||||||
|
|
||||||
|
If string of characters is typed, the ACW selection will jump to the
|
||||||
|
entry most closely matching those characters. Entering a Tab will cause
|
||||||
|
the longest non-ambiguous match to be entered in the Edit window or
|
||||||
|
Shell. Two Tabs in a row will supply the current ACW selection, as
|
||||||
|
will Return or a double click. Cursor keys, Page Up/Down, mouse
|
||||||
|
selection, and the scrollwheel all operate on the ACW.
|
||||||
|
|
||||||
|
'Hidden' attributes can be accessed by typing the beginning of hidden
|
||||||
|
name after a '.'. e.g. '_'. This allows access to modules with
|
||||||
|
'__all__' set, or to class-private attributes.
|
||||||
|
|
||||||
|
Completions and the 'Expand Word' facility can save a lot of typing!
|
||||||
|
|
||||||
|
Completions are currently limited to those in the namespaces. Names in
|
||||||
|
an Edit window which are not via __main__ or sys.modules will not be
|
||||||
|
found. Run the module once with your imports to correct this
|
||||||
|
situation. Note that IDLE itself places quite a few modules in
|
||||||
|
sys.modules, so much can be found by default, e.g. the re module.
|
||||||
|
|
||||||
|
If you don't like the ACW popping up unbidden, simply make the delay
|
||||||
|
longer or disable the extension. OTOH, you could make the delay zero.
|
||||||
|
|
||||||
|
You could also switch off the CallTips extension. (We will be adding
|
||||||
|
a delay to the call tip window.)
|
||||||
|
|
||||||
Python Shell window:
|
Python Shell window:
|
||||||
|
|
||||||
Control-c interrupts executing command.
|
Control-c interrupts executing command.
|
||||||
|
@ -211,3 +265,18 @@ Running without a subprocess:
|
||||||
re-import any specific items (e.g. from foo import baz) if the changes
|
re-import any specific items (e.g. from foo import baz) if the changes
|
||||||
are to take effect. For these reasons, it is preferable to run IDLE
|
are to take effect. For these reasons, it is preferable to run IDLE
|
||||||
with the default subprocess if at all possible.
|
with the default subprocess if at all possible.
|
||||||
|
|
||||||
|
Extensions:
|
||||||
|
|
||||||
|
IDLE contains an extension facility. 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue