annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/idlelib/autocomplete_w.py @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 """
jpayne@69 2 An auto-completion window for IDLE, used by the autocomplete extension
jpayne@69 3 """
jpayne@69 4 import platform
jpayne@69 5
jpayne@69 6 from tkinter import *
jpayne@69 7 from tkinter.ttk import Frame, Scrollbar
jpayne@69 8
jpayne@69 9 from idlelib.autocomplete import FILES, ATTRS
jpayne@69 10 from idlelib.multicall import MC_SHIFT
jpayne@69 11
jpayne@69 12 HIDE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-hide>>"
jpayne@69 13 HIDE_FOCUS_OUT_SEQUENCE = "<FocusOut>"
jpayne@69 14 HIDE_SEQUENCES = (HIDE_FOCUS_OUT_SEQUENCE, "<ButtonPress>")
jpayne@69 15 KEYPRESS_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keypress>>"
jpayne@69 16 # We need to bind event beyond <Key> so that the function will be called
jpayne@69 17 # before the default specific IDLE function
jpayne@69 18 KEYPRESS_SEQUENCES = ("<Key>", "<Key-BackSpace>", "<Key-Return>", "<Key-Tab>",
jpayne@69 19 "<Key-Up>", "<Key-Down>", "<Key-Home>", "<Key-End>",
jpayne@69 20 "<Key-Prior>", "<Key-Next>", "<Key-Escape>")
jpayne@69 21 KEYRELEASE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keyrelease>>"
jpayne@69 22 KEYRELEASE_SEQUENCE = "<KeyRelease>"
jpayne@69 23 LISTUPDATE_SEQUENCE = "<B1-ButtonRelease>"
jpayne@69 24 WINCONFIG_SEQUENCE = "<Configure>"
jpayne@69 25 DOUBLECLICK_SEQUENCE = "<B1-Double-ButtonRelease>"
jpayne@69 26
jpayne@69 27 class AutoCompleteWindow:
jpayne@69 28
jpayne@69 29 def __init__(self, widget):
jpayne@69 30 # The widget (Text) on which we place the AutoCompleteWindow
jpayne@69 31 self.widget = widget
jpayne@69 32 # The widgets we create
jpayne@69 33 self.autocompletewindow = self.listbox = self.scrollbar = None
jpayne@69 34 # The default foreground and background of a selection. Saved because
jpayne@69 35 # they are changed to the regular colors of list items when the
jpayne@69 36 # completion start is not a prefix of the selected completion
jpayne@69 37 self.origselforeground = self.origselbackground = None
jpayne@69 38 # The list of completions
jpayne@69 39 self.completions = None
jpayne@69 40 # A list with more completions, or None
jpayne@69 41 self.morecompletions = None
jpayne@69 42 # The completion mode, either autocomplete.ATTRS or .FILES.
jpayne@69 43 self.mode = None
jpayne@69 44 # The current completion start, on the text box (a string)
jpayne@69 45 self.start = None
jpayne@69 46 # The index of the start of the completion
jpayne@69 47 self.startindex = None
jpayne@69 48 # The last typed start, used so that when the selection changes,
jpayne@69 49 # the new start will be as close as possible to the last typed one.
jpayne@69 50 self.lasttypedstart = None
jpayne@69 51 # Do we have an indication that the user wants the completion window
jpayne@69 52 # (for example, he clicked the list)
jpayne@69 53 self.userwantswindow = None
jpayne@69 54 # event ids
jpayne@69 55 self.hideid = self.keypressid = self.listupdateid = \
jpayne@69 56 self.winconfigid = self.keyreleaseid = self.doubleclickid = None
jpayne@69 57 # Flag set if last keypress was a tab
jpayne@69 58 self.lastkey_was_tab = False
jpayne@69 59 # Flag set to avoid recursive <Configure> callback invocations.
jpayne@69 60 self.is_configuring = False
jpayne@69 61
jpayne@69 62 def _change_start(self, newstart):
jpayne@69 63 min_len = min(len(self.start), len(newstart))
jpayne@69 64 i = 0
jpayne@69 65 while i < min_len and self.start[i] == newstart[i]:
jpayne@69 66 i += 1
jpayne@69 67 if i < len(self.start):
jpayne@69 68 self.widget.delete("%s+%dc" % (self.startindex, i),
jpayne@69 69 "%s+%dc" % (self.startindex, len(self.start)))
jpayne@69 70 if i < len(newstart):
jpayne@69 71 self.widget.insert("%s+%dc" % (self.startindex, i),
jpayne@69 72 newstart[i:])
jpayne@69 73 self.start = newstart
jpayne@69 74
jpayne@69 75 def _binary_search(self, s):
jpayne@69 76 """Find the first index in self.completions where completions[i] is
jpayne@69 77 greater or equal to s, or the last index if there is no such.
jpayne@69 78 """
jpayne@69 79 i = 0; j = len(self.completions)
jpayne@69 80 while j > i:
jpayne@69 81 m = (i + j) // 2
jpayne@69 82 if self.completions[m] >= s:
jpayne@69 83 j = m
jpayne@69 84 else:
jpayne@69 85 i = m + 1
jpayne@69 86 return min(i, len(self.completions)-1)
jpayne@69 87
jpayne@69 88 def _complete_string(self, s):
jpayne@69 89 """Assuming that s is the prefix of a string in self.completions,
jpayne@69 90 return the longest string which is a prefix of all the strings which
jpayne@69 91 s is a prefix of them. If s is not a prefix of a string, return s.
jpayne@69 92 """
jpayne@69 93 first = self._binary_search(s)
jpayne@69 94 if self.completions[first][:len(s)] != s:
jpayne@69 95 # There is not even one completion which s is a prefix of.
jpayne@69 96 return s
jpayne@69 97 # Find the end of the range of completions where s is a prefix of.
jpayne@69 98 i = first + 1
jpayne@69 99 j = len(self.completions)
jpayne@69 100 while j > i:
jpayne@69 101 m = (i + j) // 2
jpayne@69 102 if self.completions[m][:len(s)] != s:
jpayne@69 103 j = m
jpayne@69 104 else:
jpayne@69 105 i = m + 1
jpayne@69 106 last = i-1
jpayne@69 107
jpayne@69 108 if first == last: # only one possible completion
jpayne@69 109 return self.completions[first]
jpayne@69 110
jpayne@69 111 # We should return the maximum prefix of first and last
jpayne@69 112 first_comp = self.completions[first]
jpayne@69 113 last_comp = self.completions[last]
jpayne@69 114 min_len = min(len(first_comp), len(last_comp))
jpayne@69 115 i = len(s)
jpayne@69 116 while i < min_len and first_comp[i] == last_comp[i]:
jpayne@69 117 i += 1
jpayne@69 118 return first_comp[:i]
jpayne@69 119
jpayne@69 120 def _selection_changed(self):
jpayne@69 121 """Call when the selection of the Listbox has changed.
jpayne@69 122
jpayne@69 123 Updates the Listbox display and calls _change_start.
jpayne@69 124 """
jpayne@69 125 cursel = int(self.listbox.curselection()[0])
jpayne@69 126
jpayne@69 127 self.listbox.see(cursel)
jpayne@69 128
jpayne@69 129 lts = self.lasttypedstart
jpayne@69 130 selstart = self.completions[cursel]
jpayne@69 131 if self._binary_search(lts) == cursel:
jpayne@69 132 newstart = lts
jpayne@69 133 else:
jpayne@69 134 min_len = min(len(lts), len(selstart))
jpayne@69 135 i = 0
jpayne@69 136 while i < min_len and lts[i] == selstart[i]:
jpayne@69 137 i += 1
jpayne@69 138 newstart = selstart[:i]
jpayne@69 139 self._change_start(newstart)
jpayne@69 140
jpayne@69 141 if self.completions[cursel][:len(self.start)] == self.start:
jpayne@69 142 # start is a prefix of the selected completion
jpayne@69 143 self.listbox.configure(selectbackground=self.origselbackground,
jpayne@69 144 selectforeground=self.origselforeground)
jpayne@69 145 else:
jpayne@69 146 self.listbox.configure(selectbackground=self.listbox.cget("bg"),
jpayne@69 147 selectforeground=self.listbox.cget("fg"))
jpayne@69 148 # If there are more completions, show them, and call me again.
jpayne@69 149 if self.morecompletions:
jpayne@69 150 self.completions = self.morecompletions
jpayne@69 151 self.morecompletions = None
jpayne@69 152 self.listbox.delete(0, END)
jpayne@69 153 for item in self.completions:
jpayne@69 154 self.listbox.insert(END, item)
jpayne@69 155 self.listbox.select_set(self._binary_search(self.start))
jpayne@69 156 self._selection_changed()
jpayne@69 157
jpayne@69 158 def show_window(self, comp_lists, index, complete, mode, userWantsWin):
jpayne@69 159 """Show the autocomplete list, bind events.
jpayne@69 160
jpayne@69 161 If complete is True, complete the text, and if there is exactly
jpayne@69 162 one matching completion, don't open a list.
jpayne@69 163 """
jpayne@69 164 # Handle the start we already have
jpayne@69 165 self.completions, self.morecompletions = comp_lists
jpayne@69 166 self.mode = mode
jpayne@69 167 self.startindex = self.widget.index(index)
jpayne@69 168 self.start = self.widget.get(self.startindex, "insert")
jpayne@69 169 if complete:
jpayne@69 170 completed = self._complete_string(self.start)
jpayne@69 171 start = self.start
jpayne@69 172 self._change_start(completed)
jpayne@69 173 i = self._binary_search(completed)
jpayne@69 174 if self.completions[i] == completed and \
jpayne@69 175 (i == len(self.completions)-1 or
jpayne@69 176 self.completions[i+1][:len(completed)] != completed):
jpayne@69 177 # There is exactly one matching completion
jpayne@69 178 return completed == start
jpayne@69 179 self.userwantswindow = userWantsWin
jpayne@69 180 self.lasttypedstart = self.start
jpayne@69 181
jpayne@69 182 # Put widgets in place
jpayne@69 183 self.autocompletewindow = acw = Toplevel(self.widget)
jpayne@69 184 # Put it in a position so that it is not seen.
jpayne@69 185 acw.wm_geometry("+10000+10000")
jpayne@69 186 # Make it float
jpayne@69 187 acw.wm_overrideredirect(1)
jpayne@69 188 try:
jpayne@69 189 # This command is only needed and available on Tk >= 8.4.0 for OSX
jpayne@69 190 # Without it, call tips intrude on the typing process by grabbing
jpayne@69 191 # the focus.
jpayne@69 192 acw.tk.call("::tk::unsupported::MacWindowStyle", "style", acw._w,
jpayne@69 193 "help", "noActivates")
jpayne@69 194 except TclError:
jpayne@69 195 pass
jpayne@69 196 self.scrollbar = scrollbar = Scrollbar(acw, orient=VERTICAL)
jpayne@69 197 self.listbox = listbox = Listbox(acw, yscrollcommand=scrollbar.set,
jpayne@69 198 exportselection=False)
jpayne@69 199 for item in self.completions:
jpayne@69 200 listbox.insert(END, item)
jpayne@69 201 self.origselforeground = listbox.cget("selectforeground")
jpayne@69 202 self.origselbackground = listbox.cget("selectbackground")
jpayne@69 203 scrollbar.config(command=listbox.yview)
jpayne@69 204 scrollbar.pack(side=RIGHT, fill=Y)
jpayne@69 205 listbox.pack(side=LEFT, fill=BOTH, expand=True)
jpayne@69 206 acw.lift() # work around bug in Tk 8.5.18+ (issue #24570)
jpayne@69 207
jpayne@69 208 # Initialize the listbox selection
jpayne@69 209 self.listbox.select_set(self._binary_search(self.start))
jpayne@69 210 self._selection_changed()
jpayne@69 211
jpayne@69 212 # bind events
jpayne@69 213 self.hideaid = acw.bind(HIDE_VIRTUAL_EVENT_NAME, self.hide_event)
jpayne@69 214 self.hidewid = self.widget.bind(HIDE_VIRTUAL_EVENT_NAME, self.hide_event)
jpayne@69 215 acw.event_add(HIDE_VIRTUAL_EVENT_NAME, HIDE_FOCUS_OUT_SEQUENCE)
jpayne@69 216 for seq in HIDE_SEQUENCES:
jpayne@69 217 self.widget.event_add(HIDE_VIRTUAL_EVENT_NAME, seq)
jpayne@69 218
jpayne@69 219 self.keypressid = self.widget.bind(KEYPRESS_VIRTUAL_EVENT_NAME,
jpayne@69 220 self.keypress_event)
jpayne@69 221 for seq in KEYPRESS_SEQUENCES:
jpayne@69 222 self.widget.event_add(KEYPRESS_VIRTUAL_EVENT_NAME, seq)
jpayne@69 223 self.keyreleaseid = self.widget.bind(KEYRELEASE_VIRTUAL_EVENT_NAME,
jpayne@69 224 self.keyrelease_event)
jpayne@69 225 self.widget.event_add(KEYRELEASE_VIRTUAL_EVENT_NAME,KEYRELEASE_SEQUENCE)
jpayne@69 226 self.listupdateid = listbox.bind(LISTUPDATE_SEQUENCE,
jpayne@69 227 self.listselect_event)
jpayne@69 228 self.is_configuring = False
jpayne@69 229 self.winconfigid = acw.bind(WINCONFIG_SEQUENCE, self.winconfig_event)
jpayne@69 230 self.doubleclickid = listbox.bind(DOUBLECLICK_SEQUENCE,
jpayne@69 231 self.doubleclick_event)
jpayne@69 232 return None
jpayne@69 233
jpayne@69 234 def winconfig_event(self, event):
jpayne@69 235 if self.is_configuring:
jpayne@69 236 # Avoid running on recursive <Configure> callback invocations.
jpayne@69 237 return
jpayne@69 238
jpayne@69 239 self.is_configuring = True
jpayne@69 240 if not self.is_active():
jpayne@69 241 return
jpayne@69 242 # Position the completion list window
jpayne@69 243 text = self.widget
jpayne@69 244 text.see(self.startindex)
jpayne@69 245 x, y, cx, cy = text.bbox(self.startindex)
jpayne@69 246 acw = self.autocompletewindow
jpayne@69 247 acw.update()
jpayne@69 248 acw_width, acw_height = acw.winfo_width(), acw.winfo_height()
jpayne@69 249 text_width, text_height = text.winfo_width(), text.winfo_height()
jpayne@69 250 new_x = text.winfo_rootx() + min(x, max(0, text_width - acw_width))
jpayne@69 251 new_y = text.winfo_rooty() + y
jpayne@69 252 if (text_height - (y + cy) >= acw_height # enough height below
jpayne@69 253 or y < acw_height): # not enough height above
jpayne@69 254 # place acw below current line
jpayne@69 255 new_y += cy
jpayne@69 256 else:
jpayne@69 257 # place acw above current line
jpayne@69 258 new_y -= acw_height
jpayne@69 259 acw.wm_geometry("+%d+%d" % (new_x, new_y))
jpayne@69 260 acw.update_idletasks()
jpayne@69 261
jpayne@69 262 if platform.system().startswith('Windows'):
jpayne@69 263 # See issue 15786. When on Windows platform, Tk will misbehave
jpayne@69 264 # to call winconfig_event multiple times, we need to prevent this,
jpayne@69 265 # otherwise mouse button double click will not be able to used.
jpayne@69 266 acw.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
jpayne@69 267 self.winconfigid = None
jpayne@69 268
jpayne@69 269 self.is_configuring = False
jpayne@69 270
jpayne@69 271 def _hide_event_check(self):
jpayne@69 272 if not self.autocompletewindow:
jpayne@69 273 return
jpayne@69 274
jpayne@69 275 try:
jpayne@69 276 if not self.autocompletewindow.focus_get():
jpayne@69 277 self.hide_window()
jpayne@69 278 except KeyError:
jpayne@69 279 # See issue 734176, when user click on menu, acw.focus_get()
jpayne@69 280 # will get KeyError.
jpayne@69 281 self.hide_window()
jpayne@69 282
jpayne@69 283 def hide_event(self, event):
jpayne@69 284 # Hide autocomplete list if it exists and does not have focus or
jpayne@69 285 # mouse click on widget / text area.
jpayne@69 286 if self.is_active():
jpayne@69 287 if event.type == EventType.FocusOut:
jpayne@69 288 # On Windows platform, it will need to delay the check for
jpayne@69 289 # acw.focus_get() when click on acw, otherwise it will return
jpayne@69 290 # None and close the window
jpayne@69 291 self.widget.after(1, self._hide_event_check)
jpayne@69 292 elif event.type == EventType.ButtonPress:
jpayne@69 293 # ButtonPress event only bind to self.widget
jpayne@69 294 self.hide_window()
jpayne@69 295
jpayne@69 296 def listselect_event(self, event):
jpayne@69 297 if self.is_active():
jpayne@69 298 self.userwantswindow = True
jpayne@69 299 cursel = int(self.listbox.curselection()[0])
jpayne@69 300 self._change_start(self.completions[cursel])
jpayne@69 301
jpayne@69 302 def doubleclick_event(self, event):
jpayne@69 303 # Put the selected completion in the text, and close the list
jpayne@69 304 cursel = int(self.listbox.curselection()[0])
jpayne@69 305 self._change_start(self.completions[cursel])
jpayne@69 306 self.hide_window()
jpayne@69 307
jpayne@69 308 def keypress_event(self, event):
jpayne@69 309 if not self.is_active():
jpayne@69 310 return None
jpayne@69 311 keysym = event.keysym
jpayne@69 312 if hasattr(event, "mc_state"):
jpayne@69 313 state = event.mc_state
jpayne@69 314 else:
jpayne@69 315 state = 0
jpayne@69 316 if keysym != "Tab":
jpayne@69 317 self.lastkey_was_tab = False
jpayne@69 318 if (len(keysym) == 1 or keysym in ("underscore", "BackSpace")
jpayne@69 319 or (self.mode == FILES and keysym in
jpayne@69 320 ("period", "minus"))) \
jpayne@69 321 and not (state & ~MC_SHIFT):
jpayne@69 322 # Normal editing of text
jpayne@69 323 if len(keysym) == 1:
jpayne@69 324 self._change_start(self.start + keysym)
jpayne@69 325 elif keysym == "underscore":
jpayne@69 326 self._change_start(self.start + '_')
jpayne@69 327 elif keysym == "period":
jpayne@69 328 self._change_start(self.start + '.')
jpayne@69 329 elif keysym == "minus":
jpayne@69 330 self._change_start(self.start + '-')
jpayne@69 331 else:
jpayne@69 332 # keysym == "BackSpace"
jpayne@69 333 if len(self.start) == 0:
jpayne@69 334 self.hide_window()
jpayne@69 335 return None
jpayne@69 336 self._change_start(self.start[:-1])
jpayne@69 337 self.lasttypedstart = self.start
jpayne@69 338 self.listbox.select_clear(0, int(self.listbox.curselection()[0]))
jpayne@69 339 self.listbox.select_set(self._binary_search(self.start))
jpayne@69 340 self._selection_changed()
jpayne@69 341 return "break"
jpayne@69 342
jpayne@69 343 elif keysym == "Return":
jpayne@69 344 self.complete()
jpayne@69 345 self.hide_window()
jpayne@69 346 return 'break'
jpayne@69 347
jpayne@69 348 elif (self.mode == ATTRS and keysym in
jpayne@69 349 ("period", "space", "parenleft", "parenright", "bracketleft",
jpayne@69 350 "bracketright")) or \
jpayne@69 351 (self.mode == FILES and keysym in
jpayne@69 352 ("slash", "backslash", "quotedbl", "apostrophe")) \
jpayne@69 353 and not (state & ~MC_SHIFT):
jpayne@69 354 # If start is a prefix of the selection, but is not '' when
jpayne@69 355 # completing file names, put the whole
jpayne@69 356 # selected completion. Anyway, close the list.
jpayne@69 357 cursel = int(self.listbox.curselection()[0])
jpayne@69 358 if self.completions[cursel][:len(self.start)] == self.start \
jpayne@69 359 and (self.mode == ATTRS or self.start):
jpayne@69 360 self._change_start(self.completions[cursel])
jpayne@69 361 self.hide_window()
jpayne@69 362 return None
jpayne@69 363
jpayne@69 364 elif keysym in ("Home", "End", "Prior", "Next", "Up", "Down") and \
jpayne@69 365 not state:
jpayne@69 366 # Move the selection in the listbox
jpayne@69 367 self.userwantswindow = True
jpayne@69 368 cursel = int(self.listbox.curselection()[0])
jpayne@69 369 if keysym == "Home":
jpayne@69 370 newsel = 0
jpayne@69 371 elif keysym == "End":
jpayne@69 372 newsel = len(self.completions)-1
jpayne@69 373 elif keysym in ("Prior", "Next"):
jpayne@69 374 jump = self.listbox.nearest(self.listbox.winfo_height()) - \
jpayne@69 375 self.listbox.nearest(0)
jpayne@69 376 if keysym == "Prior":
jpayne@69 377 newsel = max(0, cursel-jump)
jpayne@69 378 else:
jpayne@69 379 assert keysym == "Next"
jpayne@69 380 newsel = min(len(self.completions)-1, cursel+jump)
jpayne@69 381 elif keysym == "Up":
jpayne@69 382 newsel = max(0, cursel-1)
jpayne@69 383 else:
jpayne@69 384 assert keysym == "Down"
jpayne@69 385 newsel = min(len(self.completions)-1, cursel+1)
jpayne@69 386 self.listbox.select_clear(cursel)
jpayne@69 387 self.listbox.select_set(newsel)
jpayne@69 388 self._selection_changed()
jpayne@69 389 self._change_start(self.completions[newsel])
jpayne@69 390 return "break"
jpayne@69 391
jpayne@69 392 elif (keysym == "Tab" and not state):
jpayne@69 393 if self.lastkey_was_tab:
jpayne@69 394 # two tabs in a row; insert current selection and close acw
jpayne@69 395 cursel = int(self.listbox.curselection()[0])
jpayne@69 396 self._change_start(self.completions[cursel])
jpayne@69 397 self.hide_window()
jpayne@69 398 return "break"
jpayne@69 399 else:
jpayne@69 400 # first tab; let AutoComplete handle the completion
jpayne@69 401 self.userwantswindow = True
jpayne@69 402 self.lastkey_was_tab = True
jpayne@69 403 return None
jpayne@69 404
jpayne@69 405 elif any(s in keysym for s in ("Shift", "Control", "Alt",
jpayne@69 406 "Meta", "Command", "Option")):
jpayne@69 407 # A modifier key, so ignore
jpayne@69 408 return None
jpayne@69 409
jpayne@69 410 elif event.char and event.char >= ' ':
jpayne@69 411 # Regular character with a non-length-1 keycode
jpayne@69 412 self._change_start(self.start + event.char)
jpayne@69 413 self.lasttypedstart = self.start
jpayne@69 414 self.listbox.select_clear(0, int(self.listbox.curselection()[0]))
jpayne@69 415 self.listbox.select_set(self._binary_search(self.start))
jpayne@69 416 self._selection_changed()
jpayne@69 417 return "break"
jpayne@69 418
jpayne@69 419 else:
jpayne@69 420 # Unknown event, close the window and let it through.
jpayne@69 421 self.hide_window()
jpayne@69 422 return None
jpayne@69 423
jpayne@69 424 def keyrelease_event(self, event):
jpayne@69 425 if not self.is_active():
jpayne@69 426 return
jpayne@69 427 if self.widget.index("insert") != \
jpayne@69 428 self.widget.index("%s+%dc" % (self.startindex, len(self.start))):
jpayne@69 429 # If we didn't catch an event which moved the insert, close window
jpayne@69 430 self.hide_window()
jpayne@69 431
jpayne@69 432 def is_active(self):
jpayne@69 433 return self.autocompletewindow is not None
jpayne@69 434
jpayne@69 435 def complete(self):
jpayne@69 436 self._change_start(self._complete_string(self.start))
jpayne@69 437 # The selection doesn't change.
jpayne@69 438
jpayne@69 439 def hide_window(self):
jpayne@69 440 if not self.is_active():
jpayne@69 441 return
jpayne@69 442
jpayne@69 443 # unbind events
jpayne@69 444 self.autocompletewindow.event_delete(HIDE_VIRTUAL_EVENT_NAME,
jpayne@69 445 HIDE_FOCUS_OUT_SEQUENCE)
jpayne@69 446 for seq in HIDE_SEQUENCES:
jpayne@69 447 self.widget.event_delete(HIDE_VIRTUAL_EVENT_NAME, seq)
jpayne@69 448
jpayne@69 449 self.autocompletewindow.unbind(HIDE_VIRTUAL_EVENT_NAME, self.hideaid)
jpayne@69 450 self.widget.unbind(HIDE_VIRTUAL_EVENT_NAME, self.hidewid)
jpayne@69 451 self.hideaid = None
jpayne@69 452 self.hidewid = None
jpayne@69 453 for seq in KEYPRESS_SEQUENCES:
jpayne@69 454 self.widget.event_delete(KEYPRESS_VIRTUAL_EVENT_NAME, seq)
jpayne@69 455 self.widget.unbind(KEYPRESS_VIRTUAL_EVENT_NAME, self.keypressid)
jpayne@69 456 self.keypressid = None
jpayne@69 457 self.widget.event_delete(KEYRELEASE_VIRTUAL_EVENT_NAME,
jpayne@69 458 KEYRELEASE_SEQUENCE)
jpayne@69 459 self.widget.unbind(KEYRELEASE_VIRTUAL_EVENT_NAME, self.keyreleaseid)
jpayne@69 460 self.keyreleaseid = None
jpayne@69 461 self.listbox.unbind(LISTUPDATE_SEQUENCE, self.listupdateid)
jpayne@69 462 self.listupdateid = None
jpayne@69 463 if self.winconfigid:
jpayne@69 464 self.autocompletewindow.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
jpayne@69 465 self.winconfigid = None
jpayne@69 466
jpayne@69 467 # Re-focusOn frame.text (See issue #15786)
jpayne@69 468 self.widget.focus_set()
jpayne@69 469
jpayne@69 470 # destroy widgets
jpayne@69 471 self.scrollbar.destroy()
jpayne@69 472 self.scrollbar = None
jpayne@69 473 self.listbox.destroy()
jpayne@69 474 self.listbox = None
jpayne@69 475 self.autocompletewindow.destroy()
jpayne@69 476 self.autocompletewindow = None
jpayne@69 477
jpayne@69 478
jpayne@69 479 if __name__ == '__main__':
jpayne@69 480 from unittest import main
jpayne@69 481 main('idlelib.idle_test.test_autocomplete_w', verbosity=2, exit=False)
jpayne@69 482
jpayne@69 483 # TODO: autocomplete/w htest here