Removed Contrtol C, Updated All Widgets, new Cookbook demo!

This commit is contained in:
MikeTheWatchGuy 2018-08-29 13:36:03 -04:00
parent 3eb65e5093
commit c1de1938c1
4 changed files with 790 additions and 64 deletions

View file

@ -22,11 +22,12 @@ def HowDoI():
form = sg.FlexForm('How Do I ??', default_element_size=(30, 2), icon=DEFAULT_ICON, 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=(40,3))
layout = [
[sg.Text('Ask and your answer will appear here....', size=(40, 1))],
[sg.Output(size=(127, 30), font=('Helvetica 10'))],
[ sg.Spin(values=(1, 2, 3, 4), initial_value=1, size=(2, 1), key='Num Answers', font='Helvetica 15'), sg.T('Num Answers',font='Helvetica 15'), sg.Checkbox('Display Full Text', key='full text', font='Helvetica 15')],
[sg.T('Command History'), history_elem],
[multiline_elem,
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]))]
@ -41,18 +42,17 @@ def HowDoI():
query = value['query'].rstrip()
QueryHowDoI(query, value['Num Answers'], value['full text']) # send the string to HowDoI
command_history.append(query)
history_offset = len(command_history)
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:]))
elif button is None or button is 'EXIT': # if exit button or closed using X
break
elif 'Up' in button: # scroll back in history
history_offset -= 1 * (history_offset > 0) # decrement is not zero
elif 'Up' in button and len(command_history): # scroll back in history
command = command_history[history_offset]
history_offset -= 1 * (history_offset > 0) # decrement is not zero
multiline_elem.Update(command)
elif 'Down' in button: # scroll forward in history
elif 'Down' in button and len(command_history): # scroll forward in history
history_offset += 1 * (history_offset < len(command_history)-1) # increment up to end of list
if history_offset >= len(command_history):
history_offset = len(command_history)-1
command = command_history[history_offset]
multiline_elem.Update(command)
elif 'Escape' in button: # clear currently line