diff --git a/Demo_HowDoI.py b/Demo_HowDoI.py index 2d260e8b..405d27b2 100644 --- a/Demo_HowDoI.py +++ b/Demo_HowDoI.py @@ -1,9 +1,9 @@ import PySimpleGUI as sg import subprocess -import howdoi + # Test this command in a dos window if you are having trouble. -HOW_DO_I_COMMAND = 'python -m howdoi.howdoi -n 2' +HOW_DO_I_COMMAND = 'python -m howdoi.howdoi' # if you want an icon on your taskbar for this gui, then change this line of code to point to the ICO file DEFAULT_ICON = 'E:\\TheRealMyDocs\\Icons\\QuestionMark.ico' @@ -17,26 +17,46 @@ def HowDoI(): :return: never returns ''' # ------- Make a new FlexForm ------- # - # Set system-wide options that will affect all future forms. Give our form a spiffy look and feel - sg.SetOptions(background_color='#9FB8AD', text_element_background_color='#9FB8AD', element_background_color='#9FB8AD', scrollbar_color=None, input_elements_background_color='#F7F3EC', button_color=('white', '#475841')) - form = sg.FlexForm('How Do I ??', auto_size_text=True, default_element_size=(30, 2), icon=DEFAULT_ICON) + sg.ChangeLookAndFeel('GreenTan') # give our form a spiffy set of colors + + 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) + layout = [ [sg.Text('Ask and your answer will appear here....', size=(40, 1))], - [sg.Output(size=(88, 20))], - [ sg.Spin(values=(1, 2, 3, 4), initial_value=1, size=(2, 1), key='Num Answers'), sg.T('Num Answers'), sg.Checkbox('Display Full Text', key='full text')], - [sg.Multiline(size=(85, 5), enter_submits=True, key='query'), + [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')], + [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]))] ] form.Layout(layout) # ---===--- Loop taking in user input and using it to query HowDoI --- # + command_history = [] + history_offset = 0 while True: (button, value) = form.Read() - - if button == 'SEND': - QueryHowDoI(value['query'], value['Num Answers'], value['full text']) # send string without carriage return on end - else: - break # exit button clicked + if button is 'SEND': + 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) + multiline_elem.Update('') # manually clear input because keyboard events blocks clear + 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 + command = command_history[history_offset] + multiline_elem.Update(command) + elif 'Down' in button: # 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 + multiline_elem.Update('') exit(69) @@ -51,8 +71,8 @@ def QueryHowDoI(Query, num_answers, full_text): full_text_option = ' -a' if full_text else '' t = subprocess.Popen(howdoi_command + ' '+ Query + ' -n ' + str(num_answers)+full_text_option, stdout=subprocess.PIPE) (output, err) = t.communicate() - print('You asked: '+ Query) - print('_______________________________________') + print('{:^88}'.format(Query.rstrip())) + print('_'*60) print(output.decode("utf-8") ) exit_code = t.wait() diff --git a/PySimpleGUI.py b/PySimpleGUI.py index 53a91ae4..3244b1e7 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -6,7 +6,6 @@ import tkinter.scrolledtext as tkst import tkinter.font import datetime import sys -from sys import platform import textwrap # ----====----====----==== Constants the user CAN safely change ====----====----====----# @@ -471,6 +470,7 @@ class Multiline(Element): return def Update(self, NewValue): + self.TKText.delete('1.0', tk.END) self.TKText.insert(1.0, NewValue) def Get(self):