def ChatBotWithHistory(): # ------- Make a new Window ------- # sg.ChangeLookAndFeel('GreenTan') # give our form a spiffy set of colors layout = [[sg.Text('Your output will go here', size=(40, 1))], [sg.Output(size=(127, 30), font=('Helvetica 10'))], [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.ReadButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True), sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0])) ]] window = sg.Window('Chat window with history', default_element_size=(30, 2), font=('Helvetica', ' 13'), default_button_element_size=(8, 2), return_keyboard_events=True).Layout(layout) # ---===--- Loop taking in user input and using it --- # command_history = [] history_offset = 0 while True: (button, value) = window.Read() if button is 'SEND': query = value['query'].rstrip() # EXECUTE YOUR COMMAND HERE print('The command you entered was {}'.format(query)) command_history.append(query) history_offset = len(command_history) - 1 window.FindElement('query').Update( '' ) # manually clear input because keyboard events blocks clear window.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 window.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] window.FindElement('query').Update(command) elif 'Escape' in button: window.FindElement('query').Update('') sys.exit(69)
def Launcher2(): sg.ChangeLookAndFeel('GreenTan') window = sg.Window('Script launcher') filelist = glob.glob(LOCATION_OF_YOUR_SCRIPTS + '*.py') namesonly = [] for file in filelist: namesonly.append(ntpath.basename(file)) layout = [ [ sg.Listbox(values=namesonly, size=(30, 19), select_mode=sg.SELECT_MODE_EXTENDED, key='demolist'), sg.Output(size=(88, 20), font='Courier 10') ], [ sg.Checkbox('Wait for program to complete', default=False, key='wait') ], [ sg.ReadButton('Run'), sg.ReadButton('Shortcut 1'), sg.ReadButton('Fav Program'), sg.Button('EXIT') ], ] window.Layout(layout) # ---===--- Loop taking in user input and using it to query HowDoI --- # while True: (button, value) = window.Read() if button in ('EXIT', None): break # exit button clicked if button in ('Shortcut 1', 'Fav Program'): print( 'Quickly launch your favorite programs using these shortcuts') print( 'Or copy files to your github folder. Or anything else you type on the command line' ) # copyfile(source, dest) elif button is 'Run': for index, file in enumerate(value['demolist']): print('Launching %s' % file) window.Refresh() # make the print appear immediately if value['wait']: execute_command_blocking(LOCATION_OF_YOUR_SCRIPTS + file) else: execute_command_nonblocking(LOCATION_OF_YOUR_SCRIPTS + file)
def HowDoI(): ''' Make and show a window (PySimpleGUI form) that takes user input and sends to the HowDoI web oracle Excellent example of 2 GUI concepts 1. Output Element that will show text in a scrolled window 2. Non-Window-Closing Buttons - These buttons will cause the form to return with the form's values, but doesn't close the form :return: never returns ''' # ------- Make a new Window ------- # sg.ChangeLookAndFeel('GreenTan') # give our form a spiffy set of colors 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.Text('Num Answers',font='Helvetica 15'), sg.Checkbox('Display Full Text', key='full text', font='Helvetica 15'), sg.T('Command History', font='Helvetica 15'), sg.T('', size=(40,3), text_color=sg.BLUES[0], key='history')], [sg.Multiline(size=(85, 5), enter_submits=True, key='query', do_not_clear=False), sg.ReadButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True), sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))] ] window = sg.Window('How Do I ??', default_element_size=(30, 2), icon=DEFAULT_ICON, font=('Helvetica',' 13'), default_button_element_size=(8,2), return_keyboard_events=True, no_titlebar=True, grab_anywhere=True) window.Layout(layout) # ---===--- Loop taking in user input and using it to query HowDoI --- # command_history = [] history_offset = 0 while True: (button, value) = window.Read() if button is 'SEND': query = value['query'].rstrip() print(query) QueryHowDoI(query, value['Num Answers'], value['full text']) # send the string to HowDoI command_history.append(query) history_offset = len(command_history)-1 window.FindElement('query').Update('') # manually clear input because keyboard events blocks clear window.FindElement('history').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 and len(command_history): # scroll back in history command = command_history[history_offset] history_offset -= 1 * (history_offset > 0) # decrement is not zero window.FindElement('query').Update(command) 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 command = command_history[history_offset] window.FindElement('query').Update(command) elif 'Escape' in button: # clear currently line window.FindElement('query').Update('')
def TestMenus(): import PySimpleGUI as sg sg.ChangeLookAndFeel('LightGreen') sg.SetOptions(element_padding=(0, 0)) # ------ Menu Definition ------ # menu_def = [ ['File', ['Open', 'Save', 'Properties']], [ 'Edit', ['Paste', [ 'Special', 'Normal', ], 'Undo'], ], ['Help', 'About...'], ] # ------ GUI Defintion ------ # layout = [[sg.Menu(menu_def, tearoff=True)], [sg.Output(size=(60, 20))], [sg.In('Test', key='input', do_not_clear=True)]] window = sg.Window("Windows-like program", default_element_size=(12, 1), auto_size_text=False, auto_size_buttons=False, default_button_element_size=(12, 1)).Layout(layout) # ------ Loop & Process button menu choices ------ # while True: button, values = window.Read() if button is None or button == 'Exit': return print('Button = ', button) # ------ Process menu choices ------ # if button == 'About...': sg.Popup('About this program', 'Version 1.0', 'PySimpleGUI rocks...') elif button == 'Open': filename = sg.PopupGetFile('file to open', no_window=True) print(filename) elif button == 'Properties': SecondForm()
def DownloadSubtitlesGUI(): sg.ChangeLookAndFeel('Dark') combobox = sg.InputCombo(values=['',], size=(10,1), key='lang') layout = [ [sg.Text('Subtitle Grabber', size=(40, 1), font=('Any 15'))], [sg.T('YouTube Link'),sg.In(default_text='',size=(60,1), key='link', do_not_clear=True) ], [sg.Output(size=(90,20), font='Courier 12')], [sg.ReadButton('Get List')], [sg.T('Language Code'), combobox, sg.ReadButton('Download')], [sg.Button('Exit', button_color=('white', 'firebrick3'))] ] window = sg.Window('Subtitle Grabber launcher', text_justification='r', default_element_size=(15,1), font=('Any 14')).Layout(layout) # ---===--- Loop taking in user input and using it to query HowDoI --- # while True: (button, gui) = window.Read() if button in ('EXIT', None): break # exit button clicked link = gui['link'] if button is 'Get List': print('Getting list of subtitles....') window.Refresh() command = [f'C:/Python/PycharmProjects/GooeyGUI/youtube-dl --list-subs {link}',] output = ExecuteCommandSubprocess(command, wait=True, quiet=True) lang_list = [o[:5].rstrip() for o in output.split('\n') if 'vtt' in o] lang_list = sorted(lang_list) combobox.Update(values=lang_list) print('Done') elif button is 'Download': lang = gui['lang'] if lang is '': lang = 'en' print(f'Downloading subtitle for {lang}...') window.Refresh() command = (f'C:/Python/PycharmProjects/GooeyGUI/youtube-dl --sub-lang {lang} --write-sub {link}',) ExecuteCommandSubprocess(command, wait=True) print('Done')
def __init__(self): self.deler = 0 self.run_face = 0 self.ledsign = 0 self.recognizer = None self.detector = None self.datasets = "./datasets" self.face_number = "./face_number" self.trainer = "./trainer" self.button = None self.value = None self.font = 'Arial' self.layout = [[ sg.Text('ID'), sg.Input(key='id', size=(10, 1)), sg.Text('Age'), sg.Input(key='age', size=(10, 1)) ], [ sg.Button('Import face', font=self.font), sg.Button('Training model', font=self.font), sg.Button('Recognize faces', key='first', font=self.font), sg.Button('Clean up the model', font=self.font), sg.Button('Clean up all data', font=self.font), ], [sg.Output(size=(60, 8), font=self.font)], [ sg.Button('exit', font=self.font), ]] self.window = sg.Window('Face recognition system', font=self.font, layout=self.layout)
if iteration_counter == total_items: current_bar += 1 # redefine the chatbot text based progress bar with a graphical one chatterbot.utils.print_progress_bar = print_progress_bar chatbot = ChatBot('Ron Obvious', trainer='chatterbot.trainers.ChatterBotCorpusTrainer') # Train based on the english corpus chatbot.train("chatterbot.corpus.english") ################# GUI ################# layout = [[sg.Output(size=(80, 20))], [ sg.Multiline(size=(70, 5), enter_submits=True), sg.ReadButton('SEND', bind_return_key=True), sg.ReadButton('EXIT') ]] window = sg.Window('Chat Window', auto_size_text=True, default_element_size=(30, 2)).Layout(layout) # ---===--- Loop taking in user input and using it to query HowDoI web oracle --- # while True: button, (value, ) = window.Read() if button is not 'SEND': break
import PySimpleGUI27 as sg import subprocess import util import os menu_def = [['[F]ile', ['Extract', ['NSP', '!XCI']]], ['[M]isc', 'About']] layout = [[ sg.MenuBar(menu_def), sg.Output(size=(60, 5), background_color='Black', text_color='Green', font='None') ]] window = sg.Window('LazyExtractor [Alpha]').Layout(layout) while True: event, value = window.Read() if event is None or event == 'Exit': break if event == 'NSP': filename = sg.PopupGetFile('Open File', no_window=True, file_types=(("Switch File Types", "*.nsp"), )) if filename is not '': print 'Extracting NSP:' window.Refresh() print subprocess.check_output([ 'squirrel', '-ogame_files/nca', '--NSP_copy_nca',
sg.ChangeLookAndFeel('GreenTan') tab2_layout = [[sg.T('This is inside tab 2')], [sg.T('Tabs can be anywhere now!')]] tab1_layout = [[sg.T('Type something here and click button'), sg.In(key='in')]] tab3_layout = [[sg.T('This is inside tab 3')]] tab4_layout = [[sg.T('This is inside tab 4')]] tab_layout = [[sg.T('This is inside of a tab')]] tab_group = sg.TabGroup( [[sg.Tab('Tab 7', tab_layout), sg.Tab('Tab 8', tab_layout)]]) tab5_layout = [[sg.T('Watch this window')], [sg.Output(size=(40, 5))]] tab6_layout = [[sg.T('This is inside tab 6')], [sg.T('How about a second row of stuff in tab 6?'), tab_group]] layout = [ [sg.T('My Window!')], [ sg.Frame('A Frame', layout=[[ sg.TabGroup([[ sg.Tab('Tab 1', tab1_layout), sg.Tab('Tab 2', tab2_layout) ]]), sg.TabGroup([[ sg.Tab('Tab3', tab3_layout), sg.Tab('Tab 4', tab4_layout)
#!/usr/bin/env python import sys if sys.version_info[0] < 3: import PySimpleGUI27 as sg else: import PySimpleGUI as sg ''' A chat window. Add call to your send-routine, print the response and you're done ''' sg.ChangeLookAndFeel('GreenTan') # give our window a spiffy set of colors layout = [[sg.Text('Your output will go here', size=(40, 1))], [sg.Output(size=(127, 30), font=('Helvetica 10'))], [ sg.Multiline(size=(85, 5), enter_submits=True, key='query'), sg.ReadButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True), sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0])) ]] window = sg.Window('Chat window', default_element_size=(30, 2), font=('Helvetica', ' 13'), default_button_element_size=(8, 2)).Layout(layout) # ---===--- Loop taking in user input and using it --- # while True: (button, value) = window.Read() if button is 'SEND':