Major update of all demo programs to use new PEP8 bindings, etc

This commit is contained in:
PySimpleGUI 2019-10-23 16:10:03 -04:00
parent 3f7c87c562
commit 7f52778bcc
307 changed files with 19546 additions and 3297 deletions

View file

@ -1,13 +1,7 @@
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import PySimpleGUI as sg
from chatterbot import ChatBot
import chatterbot.utils
from gtts import gTTS
from pygame import mixer
import time
@ -22,18 +16,18 @@ to collect user input that is sent to the chatbot. The reply is displayed in th
# Create the 'Trainer GUI'
# The Trainer GUI consists of a lot of progress bars stacked on top of each other
sg.ChangeLookAndFeel('NeutralBlue')
sg.change_look_and_feel('NeutralBlue')
# sg.DebugWin()
MAX_PROG_BARS = 20 # number of training sessions
bars = []
texts = []
training_layout = [[sg.T('TRAINING PROGRESS', size=(20, 1), font=('Helvetica', 17))], ]
training_layout = [[sg.Text('TRAINING PROGRESS', size=(20, 1), font=('Helvetica', 17))], ]
for i in range(MAX_PROG_BARS):
bars.append(sg.ProgressBar(100, size=(30, 4)))
texts.append(sg.T(' ' * 20, size=(20, 1), justification='right'))
texts.append(sg.Text(' ' * 20, size=(20, 1), justification='right'))
training_layout += [[texts[i], bars[i]],] # add a single row
training_window = sg.Window('Training').Layout(training_layout)
training_window = sg.Window('Training', training_layout)
current_bar = 0
# callback function for training runs
@ -43,12 +37,12 @@ def print_progress_bar(description, iteration_counter, total_items, progress_bar
global texts
global training_window
# update the window and the bars
button, values = training_window.Read(timeout=0)
button, values = training_window.read(timeout=0)
if button is None: # if user closed the window on us, exit
sys.exit(69)
if bars[current_bar].UpdateBar(iteration_counter, max=total_items) is False:
sys.exit(69)
texts[current_bar].Update(description) # show the training dataset name
return
if bars[current_bar].update_bar(iteration_counter, max=total_items) is False:
return
texts[current_bar].update(description) # show the training dataset name
if iteration_counter == total_items:
current_bar += 1
@ -79,14 +73,14 @@ chatbot.train("chatterbot.corpus.english")
################# GUI #################
layout = [[sg.Output(size=(80, 20))],
[sg.Multiline(size=(70, 5), enter_submits=True),
[sg.MLine(size=(70, 5), enter_submits=True),
sg.Button('SEND', bind_return_key=True), sg.Button('EXIT')]]
window = sg.Window('Chat Window', auto_size_text=True, default_element_size=(30, 2)).Layout(layout)
window = sg.Window('Chat Window', layout, default_element_size=(30, 2))
# ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
while True:
event, (value,) = window.Read()
event, (value,) = window.read()
if event != 'SEND':
break
string = value.rstrip()
@ -94,4 +88,6 @@ while True:
# send the user input to chatbot to get a response
response = chatbot.get_response(value.rstrip())
print(response)
speak(str(response))
speak(str(response))
window.close()