Lines Matching refs:self

29     def __init__(self, widget, tags):
31 self.widget = widget
33 self.tags = tags
35 self.autocompletewindow = self.listbox = self.scrollbar = None
39 self.origselforeground = self.origselbackground = None
41 self.completions = None
43 self.morecompletions = None
45 self.mode = None
47 self.start = None
49 self.startindex = None
52 self.lasttypedstart = None
55 self.userwantswindow = None
57 self.hideid = self.keypressid = self.listupdateid = \
58 self.winconfigid = self.keyreleaseid = self.doubleclickid = None
60 self.lastkey_was_tab = False
62 self.is_configuring = False
64 def _change_start(self, newstart):
65 min_len = min(len(self.start), len(newstart))
67 while i < min_len and self.start[i] == newstart[i]:
69 if i < len(self.start):
70 self.widget.delete("%s+%dc" % (self.startindex, i),
71 "%s+%dc" % (self.startindex, len(self.start)))
73 self.widget.insert("%s+%dc" % (self.startindex, i),
75 self.tags)
76 self.start = newstart
78 def _binary_search(self, s):
79 """Find the first index in self.completions where completions[i] is
82 i = 0; j = len(self.completions)
85 if self.completions[m] >= s:
89 return min(i, len(self.completions)-1)
91 def _complete_string(self, s):
92 """Assuming that s is the prefix of a string in self.completions,
96 first = self._binary_search(s)
97 if self.completions[first][:len(s)] != s:
102 j = len(self.completions)
105 if self.completions[m][:len(s)] != s:
112 return self.completions[first]
115 first_comp = self.completions[first]
116 last_comp = self.completions[last]
123 def _selection_changed(self):
128 cursel = int(self.listbox.curselection()[0])
130 self.listbox.see(cursel)
132 lts = self.lasttypedstart
133 selstart = self.completions[cursel]
134 if self._binary_search(lts) == cursel:
142 self._change_start(newstart)
144 if self.completions[cursel][:len(self.start)] == self.start:
146 self.listbox.configure(selectbackground=self.origselbackground,
147 selectforeground=self.origselforeground)
149 self.listbox.configure(selectbackground=self.listbox.cget("bg"),
150 selectforeground=self.listbox.cget("fg"))
152 if self.morecompletions:
153 self.completions = self.morecompletions
154 self.morecompletions = None
155 self.listbox.delete(0, END)
156 for item in self.completions:
157 self.listbox.insert(END, item)
158 self.listbox.select_set(self._binary_search(self.start))
159 self._selection_changed()
161 def show_window(self, comp_lists, index, complete, mode, userWantsWin):
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")
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):
182 self.userwantswindow = userWantsWin
183 self.lasttypedstart = self.start
185 self.autocompletewindow = acw = Toplevel(self.widget)
194 self.scrollbar = scrollbar = Scrollbar(acw, orient=VERTICAL)
195 self.listbox = listbox = Listbox(acw, yscrollcommand=scrollbar.set,
197 for item in self.completions:
199 self.origselforeground = listbox.cget("selectforeground")
200 self.origselbackground = listbox.cget("selectbackground")
208 self.listbox.select_set(self._binary_search(self.start))
209 self._selection_changed()
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)
216 self.widget.event_add(HIDE_VIRTUAL_EVENT_NAME, seq)
218 self.keypressid = self.widget.bind(KEYPRESS_VIRTUAL_EVENT_NAME,
219 self.keypress_event)
221 self.widget.event_add(KEYPRESS_VIRTUAL_EVENT_NAME, seq)
222 self.keyreleaseid = self.widget.bind(KEYRELEASE_VIRTUAL_EVENT_NAME,
223 self.keyrelease_event)
224 self.widget.event_add(KEYRELEASE_VIRTUAL_EVENT_NAME,KEYRELEASE_SEQUENCE)
225 self.listupdateid = listbox.bind(LISTUPDATE_SEQUENCE,
226 self.listselect_event)
227 self.is_configuring = False
228 self.winconfigid = acw.bind(WINCONFIG_SEQUENCE, self.winconfig_event)
229 self.doubleclickid = listbox.bind(DOUBLECLICK_SEQUENCE,
230 self.doubleclick_event)
233 def winconfig_event(self, event):
234 if self.is_configuring:
238 self.is_configuring = True
239 if not self.is_active():
246 text = self.widget
247 text.see(self.startindex)
248 x, y, cx, cy = text.bbox(self.startindex)
249 acw = self.autocompletewindow
279 acw.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
282 self.winconfigid = None
284 self.is_configuring = False
286 def _hide_event_check(self):
287 if not self.autocompletewindow:
291 if not self.autocompletewindow.focus_get():
292 self.hide_window()
296 self.hide_window()
298 def hide_event(self, event):
301 if self.is_active():
306 self.widget.after(1, self._hide_event_check)
308 # ButtonPress event only bind to self.widget
309 self.hide_window()
311 def listselect_event(self, event):
312 if self.is_active():
313 self.userwantswindow = True
314 cursel = int(self.listbox.curselection()[0])
315 self._change_start(self.completions[cursel])
317 def doubleclick_event(self, event):
319 cursel = int(self.listbox.curselection()[0])
320 self._change_start(self.completions[cursel])
321 self.hide_window()
323 def keypress_event(self, event):
324 if not self.is_active():
332 self.lastkey_was_tab = False
334 or (self.mode == FILES and keysym in
339 self._change_start(self.start + keysym)
341 self._change_start(self.start + '_')
343 self._change_start(self.start + '.')
345 self._change_start(self.start + '-')
348 if len(self.start) == 0:
349 self.hide_window()
351 self._change_start(self.start[:-1])
352 self.lasttypedstart = self.start
353 self.listbox.select_clear(0, int(self.listbox.curselection()[0]))
354 self.listbox.select_set(self._binary_search(self.start))
355 self._selection_changed()
359 self.complete()
360 self.hide_window()
363 elif (self.mode == ATTRS and keysym in
366 (self.mode == FILES and keysym in
372 cursel = int(self.listbox.curselection()[0])
373 if self.completions[cursel][:len(self.start)] == self.start \
374 and (self.mode == ATTRS or self.start):
375 self._change_start(self.completions[cursel])
376 self.hide_window()
382 self.userwantswindow = True
383 cursel = int(self.listbox.curselection()[0])
387 newsel = len(self.completions)-1
389 jump = self.listbox.nearest(self.listbox.winfo_height()) - \
390 self.listbox.nearest(0)
395 newsel = min(len(self.completions)-1, cursel+jump)
400 newsel = min(len(self.completions)-1, cursel+1)
401 self.listbox.select_clear(cursel)
402 self.listbox.select_set(newsel)
403 self._selection_changed()
404 self._change_start(self.completions[newsel])
408 if self.lastkey_was_tab:
410 cursel = int(self.listbox.curselection()[0])
411 self._change_start(self.completions[cursel])
412 self.hide_window()
416 self.userwantswindow = True
417 self.lastkey_was_tab = True
427 self._change_start(self.start + event.char)
428 self.lasttypedstart = self.start
429 self.listbox.select_clear(0, int(self.listbox.curselection()[0]))
430 self.listbox.select_set(self._binary_search(self.start))
431 self._selection_changed()
436 self.hide_window()
439 def keyrelease_event(self, event):
440 if not self.is_active():
442 if self.widget.index("insert") != \
443 self.widget.index("%s+%dc" % (self.startindex, len(self.start))):
445 self.hide_window()
447 def is_active(self):
448 return self.autocompletewindow is not None
450 def complete(self):
451 self._change_start(self._complete_string(self.start))
454 def hide_window(self):
455 if not self.is_active():
459 self.autocompletewindow.event_delete(HIDE_VIRTUAL_EVENT_NAME,
462 self.widget.event_delete(HIDE_VIRTUAL_EVENT_NAME, seq)
464 self.autocompletewindow.unbind(HIDE_VIRTUAL_EVENT_NAME, self.hideaid)
465 self.widget.unbind(HIDE_VIRTUAL_EVENT_NAME, self.hidewid)
466 self.hideaid = None
467 self.hidewid = None
469 self.widget.event_delete(KEYPRESS_VIRTUAL_EVENT_NAME, seq)
470 self.widget.unbind(KEYPRESS_VIRTUAL_EVENT_NAME, self.keypressid)
471 self.keypressid = None
472 self.widget.event_delete(KEYRELEASE_VIRTUAL_EVENT_NAME,
474 self.widget.unbind(KEYRELEASE_VIRTUAL_EVENT_NAME, self.keyreleaseid)
475 self.keyreleaseid = None
476 self.listbox.unbind(LISTUPDATE_SEQUENCE, self.listupdateid)
477 self.listupdateid = None
478 if self.winconfigid:
479 self.autocompletewindow.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
480 self.winconfigid = None
483 self.widget.focus_set()
486 self.scrollbar.destroy()
487 self.scrollbar = None
488 self.listbox.destroy()
489 self.listbox = None
490 self.autocompletewindow.destroy()
491 self.autocompletewindow = None