Fixed wasn't returning window when creating popup. Made a main func instead of a flat program structure

This commit is contained in:
PySimpleGUI 2020-01-22 16:21:46 -05:00
parent fa103b7246
commit 7a7513e00d
1 changed files with 65 additions and 67 deletions

View File

@ -2,20 +2,17 @@ import PySimpleGUI as sg
import re
'''
Exampel of Input element features.
Demo of using a borderless window to show possible matches for autocomplete feature
'''
def autocomplete_popup_show(text_list):
autocomplete_popup_layout = [
[sg.Listbox(values=text_list,
layout = [[ sg.Listbox(values=text_list,
size=(15, len(text_list)),
change_submits=True, bind_return_key=True,
key='-FLOATING-LISTBOX-', enable_events=True)
]
]
key='-FLOATING-LISTBOX-', enable_events=True) ]]
autocomplete_popup = sg.Window("Borderless Window",
autocomplete_popup_layout,
return sg.Window("Borderless Window",
layout,
default_element_size=(12, 1),
auto_size_text=False, keep_on_top=True,
no_titlebar=True, grab_anywhere=True,
@ -25,25 +22,25 @@ def autocomplete_popup_show(text_list):
default_button_element_size=(12, 1),
location=(1320, 622), finalize=True)
return window
def predict_text(input, lista):
pattern = re.compile('.*' + input + '.*')
return [w for w in lista if re.match(pattern, w)]
choices = ['ABC' + str(i) for i in range(30)] # dummy data
def main():
layout = [[sg.Text('Your typed chars appear here:')],
choices = ['ABC' + str(i) for i in range(30)] # dummy data
layout = [[sg.Text('Your typed chars appear here:')],
[sg.Input(key='-INPUT-', size=(10, 1))],
[sg.Button('Show'), sg.Button('Exit')], ]
window = sg.Window('Window Title', layout, return_keyboard_events=True)
window = sg.Window('Autocomplete Demo', layout, return_keyboard_events=True)
sel_item = -1
skip_event = False
while True: # Event Loop
sel_item = -1
fwindow = list_elem = values2 = None
while True: # Event Loop
event, values = window.read(timeout=500)
if event in (None, 'Exit'):
@ -66,17 +63,15 @@ while True: # Event Loop
if event.startswith('Down') or event.startswith('special 16777237'):
sel_item = sel_item + (sel_item < len(prediction_list))
list_elem.update(set_to_index=sel_item)
skip_event = True
elif event.startswith('Up') or event.startswith('special 16777235'):
sel_item = sel_item - (sel_item > 0)
list_elem.update(set_to_index=sel_item)
skip_event = True
if event == '\r' or event.startswith('special 16777220'):
chosen = values2['-FLOATING-LISTBOX-']
window['-INPUT-'].update(values2['-FLOATING-LISTBOX-']
[0], select=True)
chosen = values2['-FLOATING-LISTBOX-'] if values2 is not None else None
if chosen:
window['-INPUT-'].update(chosen[0], select=True)
fwindow.close()
sel_item = -1
@ -97,4 +92,7 @@ while True: # Event Loop
except:
pass
window.close()
window.close()
if __name__ == '__main__':
main()