-
Notifications
You must be signed in to change notification settings - Fork 2
/
autoFill.py
57 lines (55 loc) · 2.08 KB
/
autoFill.py
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
51
52
53
54
55
56
57
from ipywidgets import *
def autoFill(opts=[''], val='',txt='',placehold='Please type here...',callback=False):
opts.append('')
def dropFunc(value):
if (value.new in opts):
dropClose()
if (callable(callback)):
callback(value)
text.value = value.new
def dropClose():
drop.layout.visibility='hidden'
selDropBox.layout.visibility='hidden'
selDropBox.layout.display='none'
def textFunc(value):
matched = False
if (len(value.new)!=len(value.old)):
if (len(value.new)>0):
word = value.new
out = [word]
for mystring in opts:
if word.lower() in mystring.lower():
if (mystring.lower()==word.lower()):
matched = True
final = mystring
out.append(mystring)
if (not matched):
drop.layout.visibility='visible'
selDropBox.layout.visibility='visible'
selDropBox.layout.display='flex'
out.append('')
drop.options=out
else:
text.value = final
dropClose()
else:
text.value = ''
dropClose()
drop = Select(
options=opts,
value=val,
rows=10,
description=txt,
disabled=False,
)
text = Text(
value=val,
placeholder=placehold,
description=txt,
disabled=False,
)
drop.observe(dropFunc, names='value')
text.observe (textFunc,names='value')
selTextBox = Box([text])
selDropBox = Box([drop], layout = Layout(display='none', top='-32px', visibility='hidden', flex_flow='column'))
return (VBox([selTextBox, selDropBox],layout = Layout(display='flex', flex_flow='column')))