MCPcopy Index your code
hub / github.com/python/cpython / show_window

Method show_window

Lib/idlelib/autocomplete_w.py:161–231  ·  view source on GitHub ↗

Show the autocomplete list, bind events. If complete is True, complete the text, and if there is exactly one matching completion, don't open a list.

(self, comp_lists, index, complete, mode, userWantsWin)

Source from the content-addressed store, hash-verified

159 self._selection_changed()
160
161 def show_window(self, comp_lists, index, complete, mode, userWantsWin):
162 """Show the autocomplete list, bind events.
163
164 If complete is True, complete the text, and if there is exactly
165 one matching completion, don't open a list.
166 """
167 # Handle the start we already have
168 self.completions, self.morecompletions = comp_lists
169 self.mode = mode
170 self.startindex = self.widget.index(index)
171 self.start = self.widget.get(self.startindex, "insert")
172 if complete:
173 completed = self._complete_string(self.start)
174 start = self.start
175 self._change_start(completed)
176 i = self._binary_search(completed)
177 if self.completions[i] == completed and \
178 (i == len(self.completions)-1 or
179 self.completions[i+1][:len(completed)] != completed):
180 # There is exactly one matching completion
181 return completed == start
182 self.userwantswindow = userWantsWin
183 self.lasttypedstart = self.start
184
185 self.autocompletewindow = acw = Toplevel(self.widget)
186 acw.withdraw()
187 acw.wm_overrideredirect(1)
188 try:
189 # Prevent grabbing focus on macOS.
190 acw.tk.call("::tk::unsupported::MacWindowStyle", "style", acw._w,
191 "help", "noActivates")
192 except TclError:
193 pass
194 self.scrollbar = scrollbar = Scrollbar(acw, orient=VERTICAL)
195 self.listbox = listbox = Listbox(acw, yscrollcommand=scrollbar.set,
196 exportselection=False)
197 for item in self.completions:
198 listbox.insert(END, item)
199 self.origselforeground = listbox.cget("selectforeground")
200 self.origselbackground = listbox.cget("selectbackground")
201 scrollbar.config(command=listbox.yview)
202 scrollbar.pack(side=RIGHT, fill=Y)
203 listbox.pack(side=LEFT, fill=BOTH, expand=True)
204 #acw.update_idletasks() # Need for tk8.6.8 on macOS: #40128.
205 acw.lift() # work around bug in Tk 8.5.18+ (issue #24570)
206
207 # Initialize the listbox selection
208 self.listbox.select_set(self._binary_search(self.start))
209 self._selection_changed()
210
211 # bind events
212 self.hideaid = acw.bind(HIDE_VIRTUAL_EVENT_NAME, self.hide_event)
213 self.hidewid = self.widget.bind(HIDE_VIRTUAL_EVENT_NAME, self.hide_event)
214 acw.event_add(HIDE_VIRTUAL_EVENT_NAME, HIDE_FOCUS_OUT_SEQUENCE)
215 for seq in HIDE_SEQUENCES:
216 self.widget.event_add(HIDE_VIRTUAL_EVENT_NAME, seq)
217
218 self.keypressid = self.widget.bind(KEYPRESS_VIRTUAL_EVENT_NAME,

Callers 1

open_completionsMethod · 0.80

Calls 15

_complete_stringMethod · 0.95
_change_startMethod · 0.95
_binary_searchMethod · 0.95
insertMethod · 0.95
_selection_changedMethod · 0.95
ScrollbarClass · 0.90
ToplevelClass · 0.85
ListboxClass · 0.85
wm_overrideredirectMethod · 0.80
indexMethod · 0.45
getMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected