Cleaned up code
This commit is contained in:
parent
a37583fb06
commit
7e8e120fa1
|
@ -1,14 +1,11 @@
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
|
||||||
QT = False
|
QT = False
|
||||||
if QT:
|
if QT:
|
||||||
import PySimpleGUIQt as sg
|
import PySimpleGUIQt as sg
|
||||||
else:
|
else:
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def autocomplete_popup_show(text_list ):
|
def autocomplete_popup_show(text_list ):
|
||||||
autocomplete_popup_layout = [[sg.Listbox(values=text_list,
|
autocomplete_popup_layout = [[sg.Listbox(values=text_list,
|
||||||
size=(100,20*len(text_list)) if QT else (15, len(text_list)),
|
size=(100,20*len(text_list)) if QT else (15, len(text_list)),
|
||||||
|
@ -19,7 +16,6 @@ def autocomplete_popup_show(text_list ):
|
||||||
|
|
||||||
autocomplete_popup = sg.Window("Borderless Window",
|
autocomplete_popup = sg.Window("Borderless Window",
|
||||||
default_element_size=(12, 1),
|
default_element_size=(12, 1),
|
||||||
text_justification='c',
|
|
||||||
auto_size_text=False,
|
auto_size_text=False,
|
||||||
auto_size_buttons=False,
|
auto_size_buttons=False,
|
||||||
no_titlebar=True,
|
no_titlebar=True,
|
||||||
|
@ -34,23 +30,18 @@ def autocomplete_popup_show(text_list ):
|
||||||
return window
|
return window
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def predict_text(input, lista):
|
def predict_text(input, lista):
|
||||||
pattern = re.compile('.*' + input + '.*')
|
pattern = re.compile('.*' + input + '.*')
|
||||||
return [w for w in lista if re.match(pattern, w)]
|
return [w for w in lista if re.match(pattern, w)]
|
||||||
|
|
||||||
# print(predict_text('1', ['123']))
|
choices = ['ABC' + str(i) for i in range(30)] # dummy data
|
||||||
choices = ['ABC' + str(i) for i in range(30)]
|
|
||||||
# print(predict_text('1', values))
|
|
||||||
# print(values)
|
|
||||||
layout = [ [sg.Text('Your typed chars appear here:')],
|
layout = [ [sg.Text('Your typed chars appear here:')],
|
||||||
[sg.In(key='_INPUT_', size=(10,1), do_not_clear=True),sg.Text('', key='_OUTPUT_')],
|
[sg.In(key='_INPUT_', size=(10,1), do_not_clear=True)],
|
||||||
[sg.Button('Show'), sg.Button('Exit')],
|
[sg.Button('Show'), sg.Button('Exit')],]
|
||||||
]
|
|
||||||
|
|
||||||
window = sg.Window('Window Title', return_keyboard_events=True).Layout(layout)
|
window = sg.Window('Window Title', return_keyboard_events=True).Layout(layout)
|
||||||
|
|
||||||
|
|
||||||
sel_item = -1
|
sel_item = -1
|
||||||
skip_event = False
|
skip_event = False
|
||||||
while True: # Event Loop
|
while True: # Event Loop
|
||||||
|
@ -66,14 +57,10 @@ while True: # Event Loop
|
||||||
except: pass
|
except: pass
|
||||||
fwindow = autocomplete_popup_show(prediction_list)
|
fwindow = autocomplete_popup_show(prediction_list)
|
||||||
list_elem = fwindow.Element('_FLOATING_LISTBOX_')
|
list_elem = fwindow.Element('_FLOATING_LISTBOX_')
|
||||||
|
|
||||||
window.Element('_OUTPUT_').Update(prediction_list[0])
|
|
||||||
|
|
||||||
if event == '_COMBO_':
|
if event == '_COMBO_':
|
||||||
sg.Popup('Chose', values['_COMBO_'])
|
sg.Popup('Chose', values['_COMBO_'])
|
||||||
if event.startswith('Down') or event.startswith('special 16777237'):
|
if event.startswith('Down') or event.startswith('special 16777237'):
|
||||||
sel_item = sel_item + (sel_item<len(prediction_list))
|
sel_item = sel_item + (sel_item<len(prediction_list))
|
||||||
print(f'Sel item {sel_item}')
|
|
||||||
list_elem.Update(set_to_index=sel_item)
|
list_elem.Update(set_to_index=sel_item)
|
||||||
skip_event = True
|
skip_event = True
|
||||||
elif event.startswith('Up') or event.startswith('special 16777235'):
|
elif event.startswith('Up') or event.startswith('special 16777235'):
|
||||||
|
@ -93,7 +80,6 @@ while True: # Event Loop
|
||||||
if ev2 == '_FLOATING_LISTBOX_' and skip_event and QT:
|
if ev2 == '_FLOATING_LISTBOX_' and skip_event and QT:
|
||||||
skip_event = False
|
skip_event = False
|
||||||
elif ev2 != sg.TIMEOUT_KEY and ev2 is not None:
|
elif ev2 != sg.TIMEOUT_KEY and ev2 is not None:
|
||||||
print(f'Event2 = {ev2}')
|
|
||||||
fwindow.Close()
|
fwindow.Close()
|
||||||
window.Element('_INPUT_').Update(vals2['_FLOATING_LISTBOX_'][0], select=True)
|
window.Element('_INPUT_').Update(vals2['_FLOATING_LISTBOX_'][0], select=True)
|
||||||
sel_item = -1
|
sel_item = -1
|
||||||
|
|
Loading…
Reference in New Issue