-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.py
More file actions
50 lines (38 loc) · 1.29 KB
/
example.py
File metadata and controls
50 lines (38 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from fingui import Entry, Menu
from glob import glob
class AutocompletePathEntry(Entry):
menu = None
def showSuggestions(self, newValue):
suggestions = glob(newValue + '*')
if not newValue or newValue[-1] != '/':
suggestions += glob(newValue + '/*')
if newValue in suggestions:
suggestions.remove(newValue)
if not suggestions:
if self.menu:
self.menu.hide()
return
if not self.menu:
self.menu = Menu(suggestions, self.x, self.y + self.height, alwaysHighlight = True, delegate = self)
else:
self.menu.items = suggestions
self.menu.show()
self.menu.columns = self.columns = max(20, self.menu.columns, len(self.get()))
def onChange(self, oldValue, newValue):
self.showSuggestions(newValue)
def onSelect(self, item):
self.set(item)
def onReturn(self):
if self.menu:
self.menu.selectHighlighted()
def onDown(self):
if self.menu:
self.menu.moveHighlight(1)
def onUp(self):
if self.menu:
self.menu.moveHighlight(-1)
def onFocus(self):
self.showSuggestions(self.get())
def onFocusLost(self):
self.menu.hide()
AutocompletePathEntry()