Fixes bugs with pausing

This commit is contained in:
LSaldyt
2017-11-01 10:19:22 -07:00
parent 20b25125d8
commit af1e2e042e
7 changed files with 162987 additions and 92 deletions

36
copycat/gui/gui.py Executable file → Normal file
View File

@ -30,25 +30,18 @@ class MainApplication(GridFrame):
self.add(self.primary, 0, 0, xspan=2)
self.create_widgets()
GridFrame.configure(self)
#self.messages = []
#def log(self, message):
# self.messages.append(message)
def create_widgets(self):
self.slipList = List(self, 10)
columns = 20
self.slipList = List(self, columns)
self.add(self.slipList, 0, 1)
self.codeletList = List(self, 10)
self.codeletList = List(self, columns)
self.add(self.codeletList, 1, 1)
self.objectList = List(self, 10)
self.objectList = List(self, columns)
self.add(self.objectList, 2, 1)
#self.logBox = List(self, 10)
#self.add(self.logBox, 1, 0)
self.graph2 = Plot(self, 'Answer Distribution')
self.add(self.graph2, 2, 0)
@ -62,14 +55,21 @@ class MainApplication(GridFrame):
self.slipList.update(slipnodes, key=lambda s:s.activation,
formatter=lambda s : '{}: {}'.format(s.name, round(s.activation, 2)))
self.codeletList.update(codelets, key=lambda c:c.urgency, formatter= lambda s : '{}: {}'.format(s.name, round(s.urgency, 2)))
self.objectList.update(objects, formatter=lambda s : '{}'.format(str(s.descriptions)))
#self.logBox.update(list(reversed(self.messages))[:10])
self.objectList.update(objects, formatter=lambda s : '{}'.format(', '.join(map(str, s.descriptions))))
if len(objects) > 0:
print('Descriptions:')
for obj in objects:
print(obj)
for description in obj.descriptions:
print(' {}:'.format(description))
print(' {}'.format(description.descriptionType.name))
print(' {}'.format(description.descriptor.name))
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):
def __init__(self, title):
self.root = tk.Tk()
self.root.title(title)
tk.Grid.rowconfigure(self.root, 0, weight=1)
@ -79,9 +79,6 @@ class GUI(object):
configure_style(ttk.Style())
self.lastUpdated = time.time()
self.updateInterval = updateInterval
def add_answers(self, answers):
def modifier(status):
with plt.style.context(('dark_background')):
@ -92,7 +89,8 @@ class GUI(object):
self.root.update_idletasks()
self.root.update()
def paused(self):
return self.app.primary.control.paused
def update(self, copycat):
current = time.time()
self.app.update(copycat)
self.lastUpdated = current

View File

@ -7,66 +7,23 @@ from tkinter import filedialog
from .control import Control
from .gridframe import GridFrame
font1Size = 32
font2Size = 16
font1 = ('Helvetica', str(font1Size))
font2 = ('Helvetica', str(font2Size))
style = dict(background='black',
foreground='white',
font=font2)
def create_main_canvas(root, initial, final, new, guess):
padding = 100
canvas = tk.Canvas(root, background='black')
def add_sequences(sequences, x, y):
for sequence in sequences:
x += padding
if sequence is None:
sequence = ''
for char in sequence:
canvas.create_text(x, y, text=char, anchor=tk.NW, font=font1, fill='white')
x += font1Size
return x, y
x = 0
y = padding
add_sequences([initial, final], x, y)
x = 0
y += padding
add_sequences([new, guess], x, y)
#canvas['height'] = str(int(canvas['height']) + padding)
#canvas['width'] = str(int(canvas['width']) + padding)
return canvas
from .workspacecanvas import WorkspaceCanvas
class Primary(GridFrame):
def __init__(self, parent, *args, **kwargs):
GridFrame.__init__(self, parent, *args, **kwargs)
self.initial = ''
self.modified = ''
self.target = ''
self.canvas = create_main_canvas(self, self.initial, self.modified, self.target, '')
self.canvas = WorkspaceCanvas(self)
self.add(self.canvas, 0, 0, xspan=2)
self.control = Control(self)
self.add(self.control, 0, 2)
GridFrame.configure(self)
def update(self, copycat):
answer = '' if copycat.workspace.rule is None else copycat.workspace.rule.buildTranslatedRule()
#self.canvas = create_main_canvas(self, self.initial, self.modified, self.target, answer)
#self.add(self.canvas, 0, 0, xspan=2)
self.canvas.update(copycat)
def reset_with_strings(self, initial, modified, target):
self.initial = initial
self.modified = modified
self.target = target
self.canvas.reset_with_strings(initial, modified, target)

159787
copycat/gui/sys Normal file

File diff suppressed because it is too large Load Diff

3093
copycat/gui/time Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,64 @@
import tkinter as tk
import tkinter.ttk as ttk
from .gridframe import GridFrame
font1Size = 16
font1 = ('Helvetica', font1Size)
class WorkspaceCanvas(GridFrame):
def __init__(self, parent, *args, **kwargs):
GridFrame.__init__(self, parent, *args, **kwargs)
self.initial = ''
self.modified = ''
self.target = ''
self.answer = ''
self.changed = False
self.canvas = tk.Canvas(self, background='black')
self.add(self.canvas, 0, 0)
GridFrame.configure(self)
def update(self, copycat):
answer = '' if copycat.workspace.rule is None else copycat.workspace.rule.buildTranslatedRule()
if answer != self.answer:
self.changed = True
if self.changed:
self.canvas.delete('all')
self.add_text()
def add_text(self):
padding = 100
def add_sequences(sequences, x, y):
for sequence in sequences:
x += padding
if sequence is None:
sequence = ''
for char in sequence:
self.canvas.create_text(x, y, text=char, anchor=tk.NW, font=font1, fill='white')
x += font1Size
return x, y
x = 0
y = padding
add_sequences([self.initial, self.modified], x, y)
x = 0
y += padding
add_sequences([self.target, self.answer], x, y)
def reset_with_strings(self, initial, modified, target):
if initial != self.initial or \
modified != self.modified or \
target != self.target:
self.changed = True
self.initial = initial
self.modified = modified
self.target = target