Adds entry method
This commit is contained in:
@ -1,2 +1 @@
|
|||||||
from .copycat import Copycat, Reporter # noqa
|
from .copycat import Copycat, Reporter # noqa
|
||||||
from .plot import plot_answers
|
|
||||||
|
|||||||
@ -64,6 +64,7 @@ class Copycat(object):
|
|||||||
if self.showgui:
|
if self.showgui:
|
||||||
self.gui.refresh()
|
self.gui.refresh()
|
||||||
|
|
||||||
|
|
||||||
def runTrial(self):
|
def runTrial(self):
|
||||||
"""Run a trial of the copycat algorithm"""
|
"""Run a trial of the copycat algorithm"""
|
||||||
self.coderack.reset()
|
self.coderack.reset()
|
||||||
@ -84,6 +85,11 @@ class Copycat(object):
|
|||||||
self.workspace.resetWithStrings(initial, modified, target)
|
self.workspace.resetWithStrings(initial, modified, target)
|
||||||
answers = {}
|
answers = {}
|
||||||
for i in range(iterations):
|
for i in range(iterations):
|
||||||
|
if self.gui.app.primary.control.go:
|
||||||
|
initial, modified, target = self.gui.app.primary.control.get_vars()
|
||||||
|
self.workspace.resetWithStrings(initial, modified, target)
|
||||||
|
answers = {}
|
||||||
|
|
||||||
answer = self.runTrial()
|
answer = self.runTrial()
|
||||||
d = answers.setdefault(answer['answer'], {
|
d = answers.setdefault(answer['answer'], {
|
||||||
'count': 0,
|
'count': 0,
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import tkinter as tk
|
|||||||
import tkinter.ttk as ttk
|
import tkinter.ttk as ttk
|
||||||
|
|
||||||
from .gridframe import GridFrame
|
from .gridframe import GridFrame
|
||||||
|
from .entry import Entry
|
||||||
|
|
||||||
class Control(GridFrame):
|
class Control(GridFrame):
|
||||||
def __init__(self, parent, *args, **kwargs):
|
def __init__(self, parent, *args, **kwargs):
|
||||||
@ -9,6 +10,7 @@ class Control(GridFrame):
|
|||||||
|
|
||||||
self.paused = True
|
self.paused = True
|
||||||
self.steps = 0
|
self.steps = 0
|
||||||
|
self.go = False
|
||||||
|
|
||||||
self.playbutton = tk.Button(self, bd=0, text='Play', command=lambda : self.toggle(), background='black', foreground='white', activebackground='black', activeforeground='blue')
|
self.playbutton = tk.Button(self, bd=0, text='Play', command=lambda : self.toggle(), background='black', foreground='white', activebackground='black', activeforeground='blue')
|
||||||
self.add(self.playbutton, 0, 0)
|
self.add(self.playbutton, 0, 0)
|
||||||
@ -16,6 +18,12 @@ class Control(GridFrame):
|
|||||||
self.stepbutton = tk.Button(self, bd=0, text='Step', command=lambda : self.step(), background='black', foreground='white', activebackground='black', activeforeground='blue')
|
self.stepbutton = tk.Button(self, bd=0, text='Step', command=lambda : self.step(), background='black', foreground='white', activebackground='black', activeforeground='blue')
|
||||||
self.add(self.stepbutton, 1, 0)
|
self.add(self.stepbutton, 1, 0)
|
||||||
|
|
||||||
|
self.entry = Entry(self)
|
||||||
|
self.add(self.entry, 0, 1, xspan=2)
|
||||||
|
|
||||||
|
self.gobutton = tk.Button(self, bd=0, text='Go', command=lambda : self.set_go(), background='black', foreground='white', activebackground='black', activeforeground='blue')
|
||||||
|
self.add(self.gobutton, 0, 2, xspan=2)
|
||||||
|
|
||||||
def toggle(self):
|
def toggle(self):
|
||||||
self.paused = not self.paused
|
self.paused = not self.paused
|
||||||
self.playbutton['text'] = 'Pause' if not self.paused else 'Play'
|
self.playbutton['text'] = 'Pause' if not self.paused else 'Play'
|
||||||
@ -29,3 +37,9 @@ class Control(GridFrame):
|
|||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def set_go(self):
|
||||||
|
self.go = True
|
||||||
|
|
||||||
|
def get_vars(self):
|
||||||
|
return self.entry.a.get(), self.entry.b.get(), self.entry.c.get()
|
||||||
|
|||||||
28
copycat/gui/entry.py
Normal file
28
copycat/gui/entry.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
import tkinter as tk
|
||||||
|
import tkinter.ttk as ttk
|
||||||
|
|
||||||
|
from .gridframe import GridFrame
|
||||||
|
|
||||||
|
style = dict(background='black', foreground='white')
|
||||||
|
|
||||||
|
class Entry(GridFrame):
|
||||||
|
def __init__(self, parent, *args, **kwargs):
|
||||||
|
GridFrame.__init__(self, parent, *args, **kwargs)
|
||||||
|
self.aLabel = tk.Label(self, text='Initial:', **style)
|
||||||
|
self.a = tk.Entry(self, **style)
|
||||||
|
|
||||||
|
self.add(self.aLabel, 0, 0)
|
||||||
|
self.add(self.a, 0, 1)
|
||||||
|
|
||||||
|
self.bLabel = tk.Label(self, text='Final:', **style)
|
||||||
|
self.b = tk.Entry(self, **style)
|
||||||
|
|
||||||
|
self.add(self.bLabel, 1, 0)
|
||||||
|
self.add(self.b, 1, 1)
|
||||||
|
|
||||||
|
self.cLabel = tk.Label(self, text='Next:', **style)
|
||||||
|
self.c = tk.Entry(self, **style)
|
||||||
|
|
||||||
|
self.add(self.cLabel, 2, 0)
|
||||||
|
self.add(self.c, 2, 1)
|
||||||
@ -1,18 +0,0 @@
|
|||||||
import matplotlib.pyplot as plt; plt.rcdefaults()
|
|
||||||
import numpy as np
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
|
|
||||||
plt.style.use('dark_background')
|
|
||||||
|
|
||||||
def plot_answers(answers):
|
|
||||||
answers = sorted(answers.items(), key=lambda kv : kv[1]['count'])
|
|
||||||
objects = [t[0] + ' (temp:{})'.format(t[1]['avgtemp']) for t in answers]
|
|
||||||
yvalues = [t[1]['count'] for t in answers]
|
|
||||||
|
|
||||||
y_pos = np.arange(len(objects))
|
|
||||||
|
|
||||||
plt.bar(y_pos, yvalues, align='center', alpha=0.5)
|
|
||||||
plt.xticks(y_pos, objects)
|
|
||||||
plt.ylabel('Count')
|
|
||||||
plt.title('Answers')
|
|
||||||
plt.show()
|
|
||||||
2
main.py
2
main.py
@ -27,7 +27,5 @@ def main():
|
|||||||
for answer, d in sorted(iter(answers.items()), key=lambda kv: kv[1]['avgtemp']):
|
for answer, d in sorted(iter(answers.items()), key=lambda kv: kv[1]['avgtemp']):
|
||||||
print('%s: %d (avg time %.1f, avg temp %.1f)' % (answer, d['count'], d['avgtime'], d['avgtemp']))
|
print('%s: %d (avg time %.1f, avg temp %.1f)' % (answer, d['count'], d['avgtime'], d['avgtemp']))
|
||||||
|
|
||||||
#plot_answers(answers)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user