Fixed import as g instead of sg bug, made some demos borderless, used form.FindElement where possible, fixed PopupGetFile and PopupGetFolder no_window option

This commit is contained in:
MikeTheWatchGuy 2018-09-06 16:20:37 -04:00
parent be6ee091b1
commit b471b5dd05
17 changed files with 153 additions and 147 deletions

View file

@ -16,13 +16,11 @@ def ChatBotWithHistory():
form = sg.FlexForm('Chat window with history', default_element_size=(30, 2), font=('Helvetica',' 13'), default_button_element_size=(8,2), return_keyboard_events=True)
multiline_elem = sg.Multiline(size=(85, 5), enter_submits=True, key='query', do_not_clear=False)
history_elem = sg.T('', size=(20,3))
layout = [
[sg.Text('Your output will go here', size=(40, 1))],
[sg.Output(size=(127, 30), font=('Helvetica 10'))],
[sg.T('Command History'), history_elem],
[multiline_elem,
[sg.T('Command History'), sg.T('', size=(20,3), key='history')],
[sg.Multiline(size=(85, 5), enter_submits=True, key='query', do_not_clear=False),
sg.ReadFormButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True),
sg.SimpleButton('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]
]
@ -39,20 +37,20 @@ def ChatBotWithHistory():
print('The command you entered was {}'.format(query))
command_history.append(query)
history_offset = len(command_history)-1
multiline_elem.Update('') # manually clear input because keyboard events blocks clear
history_elem.Update('\n'.join(command_history[-3:]))
form.FindElement('query').Update('') # manually clear input because keyboard events blocks clear
form.FindElement('history').Update('\n'.join(command_history[-3:]))
elif button is None or button is 'EXIT': # quit if exit button or X
break
elif 'Up' in button and len(command_history):
command = command_history[history_offset]
history_offset -= 1 * (history_offset > 0) # decrement is not zero
multiline_elem.Update(command)
form.FindElement('query').Update(command)
elif 'Down' in button and len(command_history):
history_offset += 1 * (history_offset < len(command_history)-1) # increment up to end of list
command = command_history[history_offset]
multiline_elem.Update(command)
form.FindElement('query').Update(command)
elif 'Escape' in button:
multiline_elem.Update('')
form.FindElement('query').Update('')
exit(69)