diff --git a/copycat/copycat.py b/copycat/copycat.py index da77ca5..7f210de 100644 --- a/copycat/copycat.py +++ b/copycat/copycat.py @@ -53,6 +53,18 @@ class Copycat(object): self.lastUpdate = currentTime self.reporter.report_slipnet(self.slipnet) + def check_reset(self): + if self.gui.app.primary.control.go: + initial, modified, target = self.gui.app.primary.control.get_vars() + self.reset_with_strings(initial, modified, target) + return True + else: + return False + + def reset_with_strings(self, initial, modified, target): + self.workspace.resetWithStrings(initial, modified, target) + self.gui.app.reset_with_strings(initial, modified, target) + def mainLoop(self): currentTime = self.coderack.codeletsRun self.temperature.tryUnclamp(currentTime) @@ -64,7 +76,6 @@ class Copycat(object): if self.showgui: self.gui.refresh() - def runTrial(self): """Run a trial of the copycat algorithm""" self.coderack.reset() @@ -82,12 +93,10 @@ class Copycat(object): return answer def run(self, initial, modified, target, iterations): - self.workspace.resetWithStrings(initial, modified, target) + self.reset_with_strings(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) + if self.check_reset(): answers = {} answer = self.runTrial() @@ -108,6 +117,7 @@ class Copycat(object): return answers def run_forever(self, initial, modified, target): - self.workspace.resetWithStrings(initial, modified, target) + self.reset_with_strings(initial, modified, target) while True: + self.check_reset() self.runTrial() diff --git a/copycat/gui/gui.py b/copycat/gui/gui.py index efa52f6..949659a 100755 --- a/copycat/gui/gui.py +++ b/copycat/gui/gui.py @@ -80,6 +80,9 @@ class MainApplication(GridFrame): listStr = '{}: {}'.format(codelet.name, round(codelet.urgency, 2)) codeletList.insert(tk.END, listStr) + def reset_with_strings(self, initial, modified, target): + self.primary.reset_with_strings(initial, modified, target) + class GUI(object): def __init__(self, title, updateInterval=.1): self.root = tk.Tk() diff --git a/copycat/gui/primary.py b/copycat/gui/primary.py index fd5672e..5b885e8 100644 --- a/copycat/gui/primary.py +++ b/copycat/gui/primary.py @@ -51,13 +51,21 @@ class Primary(GridFrame): def __init__(self, parent, *args, **kwargs): GridFrame.__init__(self, parent, *args, **kwargs) - self.canvas = create_main_canvas(self, 'abc', 'abd', 'ijk', '?') - self.add(self.canvas, 0, 0, xspan=2) + self.initial = '' + self.modified = '' + self.target = '' + self.canvas = create_main_canvas(self, self.initial, self.modified, self.target, '') + self.add(self.canvas, 0, 0, xspan=2) self.control = Control(self) self.add(self.control, 0, 2) def update(self, copycat): answer = '' if copycat.workspace.rule is None else copycat.workspace.rule.buildTranslatedRule() - self.canvas = create_main_canvas(self, 'abc', 'abd', 'ijk', answer) + self.canvas = create_main_canvas(self, self.initial, self.modified, self.target, answer) self.add(self.canvas, 0, 0, xspan=2) + + def reset_with_strings(self, initial, modified, target): + self.initial = initial + self.modified = modified + self.target = target