Merge pull request #106 from MikeTheWatchGuy/Dev-latest

Dev latest
This commit is contained in:
MikeTheWatchGuy 2018-09-03 08:48:11 -04:00 committed by GitHub
commit c7f33c6082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 100 additions and 41 deletions

View File

@ -10,14 +10,16 @@ to collect user input that is sent to the chatbot. The reply is displayed in th
'''
# Create the 'Trainer GUI'
MAX_PROG_BARS = 20
# The Trainer GUI consists of a lot of progress bars stacked on top of each other
g.ChangeLookAndFeel('GreenTan')
MAX_PROG_BARS = 20 # number of training sessions
bars = []
texts = []
training_layout = [[g.T('TRAINING PROGRESS', size=(20,1), font=('Helvetica', 17))]]
training_layout = [[g.T('TRAINING PROGRESS', size=(20,1), font=('Helvetica', 17))],]
for i in range(MAX_PROG_BARS):
bars.append(g.ProgressBar(100, size=(30, 5)))
texts.append(g.T(' '*20))
training_layout += [[texts[i], bars[i]]]
bars.append(g.ProgressBar(100, size=(30, 4)))
texts.append(g.T(' '*20, size=(20,1), justification='right'))
training_layout += [[texts[i], bars[i]],] # add a single row
training_form = g.FlexForm('Training')
training_form.Layout(training_layout)
@ -31,11 +33,11 @@ def print_progress_bar(description, iteration_counter, total_items, progress_bar
global training_form
# update the form and the bars
button, values = training_form.ReadNonBlocking()
if button is None and values is None:
if button is None and values is None: # if user closed the form on us, exit
exit(69)
if bars[current_bar].UpdateBar(iteration_counter, max=total_items) is False:
exit(69)
texts[current_bar].Update(description)
texts[current_bar].Update(description) # show the training dataset name
if iteration_counter == total_items:
current_bar += 1
@ -51,15 +53,16 @@ chatbot.train("chatterbot.corpus.english")
with g.FlexForm('Chat Window', auto_size_text=True, default_element_size=(30, 2)) as form:
layout = [[g.Output(size=(80, 20))],
[g.Multiline(size=(70, 5), enter_submits=True),
g.ReadFormButton('SEND', bind_return_key=True), g.SimpleButton('EXIT')]]
g.ReadFormButton('SEND', bind_return_key=True), g.ReadFormButton('EXIT')]]
form.Layout(layout)
# ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
while True:
button, (value,) = form.Read()
if button != 'SEND':
if button is not 'SEND':
break
print(value.rstrip())
string = value.rstrip()
print(string.rjust(120))
# send the user input to chatbot to get a response
response = chatbot.get_response(value.rstrip())
print(response)

View File

@ -273,7 +273,10 @@ class InputText(Element):
def Update(self, new_value):
self.TKStringVar.set(new_value)
try:
self.TKStringVar.set(new_value)
except: pass
self.DefaultText = new_value
def Get(self):
return self.TKStringVar.get()
@ -285,8 +288,7 @@ class InputText(Element):
# Combo #
# ---------------------------------------------------------------------- #
class InputCombo(Element):
def __init__(self, values, scale=(None, None), size=(None, None), auto_size_text=None, background_color=None, text_color=None, key=None, pad=None):
def __init__(self, values, default_value=None, scale=(None, None), size=(None, None), auto_size_text=None, background_color=None, text_color=None, key=None, pad=None):
'''
Input Combo Box Element (also called Dropdown box)
:param values:
@ -296,6 +298,7 @@ class InputCombo(Element):
:param background_color: Color for Element. Text or RGB Hex
'''
self.Values = values
self.DefaultValue = default_value
self.TKComboBox = None
bg = background_color if background_color else DEFAULT_INPUT_ELEMENTS_COLOR
fg = text_color if text_color is not None else DEFAULT_INPUT_TEXT_COLOR
@ -305,7 +308,10 @@ class InputCombo(Element):
def Update(self, value):
for index, v in enumerate(self.Values):
if v == value:
self.TKCombo.current(index)
try:
self.TKCombo.current(index)
except: pass
self.DefaultValue = value
break
@ -321,8 +327,7 @@ class InputCombo(Element):
# Option Menu #
# ---------------------------------------------------------------------- #
class InputOptionMenu(Element):
def __init__(self, values, scale=(None, None), size=(None, None), auto_size_text=None, background_color=None, text_color=None, key=None, pad=None):
def __init__(self, values, default_value=None, scale=(None, None), size=(None, None), auto_size_text=None, background_color=None, text_color=None, key=None, pad=None):
'''
Input Combo Box Element (also called Dropdown box)
:param values:
@ -332,6 +337,7 @@ class InputOptionMenu(Element):
:param background_color: Color for Element. Text or RGB Hex
'''
self.Values = values
self.DefaultValue = default_value
self.TKOptionMenu = None
bg = background_color if background_color else DEFAULT_INPUT_ELEMENTS_COLOR
fg = text_color if text_color is not None else DEFAULT_INPUT_TEXT_COLOR
@ -341,7 +347,10 @@ class InputOptionMenu(Element):
def Update(self, value):
for index, v in enumerate(self.Values):
if v == value:
self.TKStringVar.set(value)
try:
self.TKStringVar.set(value)
except: pass
self.DefaultValue = value
break
@ -356,7 +365,7 @@ class InputOptionMenu(Element):
# Listbox #
# ---------------------------------------------------------------------- #
class Listbox(Element):
def __init__(self, values, select_mode=None, select_submits=False, scale=(None, None), size=(None, None), auto_size_text=None, font=None, background_color=None, text_color=None, key=None, pad=None):
def __init__(self, values, default_values=None, select_mode=None, select_submits=False, scale=(None, None), size=(None, None), auto_size_text=None, font=None, background_color=None, text_color=None, key=None, pad=None):
'''
Listbox Element
:param values:
@ -367,6 +376,7 @@ class Listbox(Element):
:param auto_size_text: True if should shrink field to fit the default text
:param background_color: Color for Element. Text or RGB Hex '''
self.Values = values
self.DefaultValues = default_values
self.TKListbox = None
self.SelectSubmits = select_submits
if select_mode == LISTBOX_SELECT_MODE_BROWSE:
@ -390,12 +400,15 @@ class Listbox(Element):
self.TKListbox.insert(tk.END, item)
self.TKListbox.selection_set(0, 0)
def SetValue(self, value):
def SetValue(self, values):
for index, item in enumerate(self.Values):
if item in value:
self.TKListbox.selection_set(index)
else:
self.TKListbox.selection_clear(index)
try:
if item in values:
self.TKListbox.selection_set(index)
else:
self.TKListbox.selection_clear(index)
except: pass
self.DefaultValues = values
def __del__(self):
try:
@ -435,7 +448,10 @@ class Radio(Element):
if not value:
return
location = EncodeRadioRowCol(self.Position[0], self.Position[1])
self.TKIntVar.set(location)
try:
self.TKIntVar.set(location)
except: pass
self.InitialState = value
def __del__(self):
try:
@ -471,11 +487,14 @@ class Checkbox(Element):
return self.TKIntVar.get()
def Update(self, value):
if value is None:
self.TKCheckbutton.configure(state='disabled')
else:
self.TKCheckbutton.configure(state='normal')
self.TKIntVar.set(value)
try:
if value is None:
self.TKCheckbutton.configure(state='disabled')
else:
self.TKCheckbutton.configure(state='normal')
self.TKIntVar.set(value)
except: pass
self.InitialState = value
def __del__(self):
@ -510,7 +529,10 @@ class Spin(Element):
return
def Update(self, new_value):
self.TKStringVar.set(new_value)
try:
self.TKStringVar.set(new_value)
except: pass
self.DefaultValue = new_value
def SpinChangedHandler(self, event):
# first, get the results table built
@ -550,9 +572,12 @@ class Multiline(Element):
super().__init__(ELEM_TYPE_INPUT_MULTILINE, scale=scale, size=size, auto_size_text=auto_size_text, background_color=bg, text_color=fg, key=key, pad=pad)
return
def Update(self, NewValue):
self.TKText.delete('1.0', tk.END)
self.TKText.insert(1.0, NewValue)
def Update(self, new_value):
try:
self.TKText.delete('1.0', tk.END)
self.TKText.insert(1.0, new_value)
except: pass
self.DefaultText = new_value
def Get(self):
return self.TKText.get(1.0, tk.END)
@ -1005,9 +1030,12 @@ class Slider(Element):
return
def Update(self, value, range=(None, None)):
self.TKIntVar.set(value)
if range != (None, None):
self.TKScale.config(from_ = range[0], to_ = range[1])
try:
self.TKIntVar.set(value)
if range != (None, None):
self.TKScale.config(from_ = range[0], to_ = range[1])
except: pass
self.DefaultValue = value
def SliderChangedHandler(self, event):
# first, get the results table built
@ -1663,7 +1691,6 @@ def FillSubformWithValues(form, values_dict):
value = values_dict[element.Key]
except:
continue
if element.Type == ELEM_TYPE_INPUT_TEXT:
element.Update(value)
elif element.Type == ELEM_TYPE_INPUT_CHECKBOX:
@ -1887,12 +1914,19 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
# if element.BackgroundColor is not None:
# element.TKCombo.configure(background=element.BackgroundColor)
element.TKCombo.pack(side=tk.LEFT,padx=element.Pad[0], pady=element.Pad[1])
element.TKCombo.current(0)
if element.DefaultValue:
for i, v in enumerate(element.Values):
if v == element.DefaultValue:
element.TKCombo.current(i)
break
else:
element.TKCombo.current(0)
# ------------------------- OPTION MENU (Like ComboBox but different) element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_OPTION_MENU:
max_line_len = max([len(str(l)) for l in element.Values])
element.TKStringVar = tk.StringVar()
element.TKStringVar.set(element.Values[0])
default = element.DefaultValue if element.DefaultValue else element.Values[0]
element.TKStringVar.set(default)
element.TKOptionMenu = tk.OptionMenu(tk_row_frame, element.TKStringVar ,*element.Values )
element.TKOptionMenu.config(highlightthickness=0, font=font)
element.TKOptionMenu.config(borderwidth=border_depth)
@ -1909,9 +1943,11 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
listbox_frame = tk.Frame(tk_row_frame)
element.TKStringVar = tk.StringVar()
element.TKListbox= tk.Listbox(listbox_frame, height=element_size[1], width=width, selectmode=element.SelectMode, font=font)
for item in element.Values:
for index, item in enumerate(element.Values):
element.TKListbox.insert(tk.END, item)
element.TKListbox.selection_set(0,0)
if element.DefaultValues is not None and item in element.DefaultValues:
element.TKListbox.selection_set(index)
# element.TKListbox.selection_set(0,0)
if element.BackgroundColor is not None and element.BackgroundColor != COLOR_SYSTEM_DEFAULT:
element.TKListbox.configure(background=element.BackgroundColor)
if text_color is not None and text_color != COLOR_SYSTEM_DEFAULT:
@ -3046,6 +3082,26 @@ def ChangeLookAndFeel(index):
'PROGRESS': DEFAULT_PROGRESS_BAR_COLOR, 'BORDER': 1, 'SLIDER_DEPTH': 0,
'PROGRESS_DEPTH': 0},
'Tan': {'BACKGROUND': '#fdf6e3', 'TEXT': '#268bd1', 'INPUT': '#eee8d5',
'TEXT_INPUT': '#6c71c3', 'SCROLL': '#eee8d5', 'BUTTON': ('white', '#063542'),
'PROGRESS': DEFAULT_PROGRESS_BAR_COLOR, 'BORDER': 1, 'SLIDER_DEPTH': 0,
'PROGRESS_DEPTH': 0},
'TanBlue': {'BACKGROUND': '#e5dece', 'TEXT': '#063289', 'INPUT': '#f9f8f4',
'TEXT_INPUT': '#242834', 'SCROLL': '#eee8d5', 'BUTTON': ('white', '#063289'),
'PROGRESS': DEFAULT_PROGRESS_BAR_COLOR, 'BORDER': 1, 'SLIDER_DEPTH': 0,
'PROGRESS_DEPTH': 0},
'DarkTanBlue': {'BACKGROUND': '#242834', 'TEXT': '#dfe6f8', 'INPUT': '#4f5764',
'TEXT_INPUT': 'white', 'SCROLL': '#a9afbb', 'BUTTON': ('white', '#063289'),
'PROGRESS': DEFAULT_PROGRESS_BAR_COLOR, 'BORDER': 1, 'SLIDER_DEPTH': 0,
'PROGRESS_DEPTH': 0},
'DarkBlue': {'BACKGROUND': '#1a2835', 'TEXT': '#d1ecff', 'INPUT': '#335267',
'TEXT_INPUT': '#acc2d0', 'SCROLL': '#1b6497', 'BUTTON': ('black', '#fafaf8'),
'PROGRESS': DEFAULT_PROGRESS_BAR_COLOR, 'BORDER': 1, 'SLIDER_DEPTH': 0,
'PROGRESS_DEPTH': 0},
'Reds': {'BACKGROUND': '#280001', 'TEXT': 'white', 'INPUT': '#d8d584',
'TEXT_INPUT': 'black', 'SCROLL': '#763e00', 'BUTTON': ('black', '#daad28'),
'PROGRESS': DEFAULT_PROGRESS_BAR_COLOR, 'BORDER': 1, 'SLIDER_DEPTH': 0,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 23 KiB