diff --git a/copycat/__init__.py b/copycat/__init__.py index 14c0cc1..67e5cc9 100644 --- a/copycat/__init__.py +++ b/copycat/__init__.py @@ -1,2 +1 @@ from .copycat import Copycat, Reporter # noqa -from .plot import plot_answers diff --git a/copycat/copycat.py b/copycat/copycat.py index ade6a4d..da77ca5 100644 --- a/copycat/copycat.py +++ b/copycat/copycat.py @@ -64,6 +64,7 @@ class Copycat(object): if self.showgui: self.gui.refresh() + def runTrial(self): """Run a trial of the copycat algorithm""" self.coderack.reset() @@ -84,6 +85,11 @@ class Copycat(object): self.workspace.resetWithStrings(initial, modified, target) answers = {} 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() d = answers.setdefault(answer['answer'], { 'count': 0, diff --git a/copycat/gui/control.py b/copycat/gui/control.py index 2e48959..069c69d 100644 --- a/copycat/gui/control.py +++ b/copycat/gui/control.py @@ -2,6 +2,7 @@ import tkinter as tk import tkinter.ttk as ttk from .gridframe import GridFrame +from .entry import Entry class Control(GridFrame): def __init__(self, parent, *args, **kwargs): @@ -9,13 +10,20 @@ class Control(GridFrame): self.paused = True 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.add(self.playbutton, 0, 0) - 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.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): self.paused = not self.paused self.playbutton['text'] = 'Pause' if not self.paused else 'Play' @@ -29,3 +37,9 @@ class Control(GridFrame): return True else: 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() diff --git a/copycat/gui/entry.py b/copycat/gui/entry.py new file mode 100644 index 0000000..556a3f0 --- /dev/null +++ b/copycat/gui/entry.py @@ -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) diff --git a/copycat/plot.py b/copycat/plot.py deleted file mode 100644 index 7e6ec71..0000000 --- a/copycat/plot.py +++ /dev/null @@ -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() diff --git a/main.py b/main.py index 36b5f0c..abc9c0b 100755 --- a/main.py +++ b/main.py @@ -27,7 +27,5 @@ def main(): 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'])) - #plot_answers(answers) - if __name__ == '__main__': main()