Adds GridFrame and Step button
This commit is contained in:
@ -37,7 +37,7 @@ class Copycat(object):
|
|||||||
self.lastUpdate = float('-inf')
|
self.lastUpdate = float('-inf')
|
||||||
|
|
||||||
def step(self):
|
def step(self):
|
||||||
if (not self.showgui) or (self.showgui and not self.gui.app.primary.control.paused):
|
if (not self.showgui) or (self.showgui and (not self.gui.app.primary.control.paused or self.gui.app.primary.control.has_step())):
|
||||||
self.coderack.chooseAndRunCodelet()
|
self.coderack.chooseAndRunCodelet()
|
||||||
self.reporter.report_coderack(self.coderack)
|
self.reporter.report_coderack(self.coderack)
|
||||||
self.reporter.report_temperature(self.temperature)
|
self.reporter.report_temperature(self.temperature)
|
||||||
|
|||||||
@ -1,22 +1,31 @@
|
|||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
import tkinter.ttk as ttk
|
import tkinter.ttk as ttk
|
||||||
|
|
||||||
class Control(ttk.Frame):
|
from .gridframe import GridFrame
|
||||||
|
|
||||||
|
class Control(GridFrame):
|
||||||
def __init__(self, parent, *args, **kwargs):
|
def __init__(self, parent, *args, **kwargs):
|
||||||
tk.Frame.__init__(self, parent, *args, **kwargs)
|
GridFrame.__init__(self, parent, *args, **kwargs)
|
||||||
|
|
||||||
self.paused = True
|
self.paused = True
|
||||||
|
self.steps = 0
|
||||||
|
|
||||||
#self.style = ttk.Style()
|
|
||||||
#self.style.configure('TButton', background='black', foreground='white')
|
|
||||||
|
|
||||||
#self.playbutton = ttk.Button(self, text='Play/Pause', command=lambda : self.play())
|
|
||||||
self.playbutton = tk.Button(self, text='Play', command=lambda : self.toggle(), background='black', foreground='white', activebackground='black', activeforeground='blue')
|
self.playbutton = tk.Button(self, text='Play', command=lambda : self.toggle(), background='black', foreground='white', activebackground='black', activeforeground='blue')
|
||||||
self.playbutton.grid(column=0, row=0, stick=tk.N+tk.E+tk.S+tk.W)
|
self.add(self.playbutton, 0, 0)
|
||||||
self.rowconfigure(0, weight=1)
|
|
||||||
self.columnconfigure(0, weight=1)
|
self.stepbutton= tk.Button(self, text='Step', command=lambda : self.step(), background='black', foreground='white', activebackground='black', activeforeground='blue')
|
||||||
|
self.add(self.stepbutton, 1, 0)
|
||||||
|
|
||||||
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'
|
||||||
#def step(self):
|
|
||||||
|
def step(self):
|
||||||
|
self.steps += 1
|
||||||
|
|
||||||
|
def has_step(self):
|
||||||
|
if self.steps > 0:
|
||||||
|
self.steps -= 1
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|||||||
11
copycat/gui/gridframe.py
Normal file
11
copycat/gui/gridframe.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import tkinter as tk
|
||||||
|
import tkinter.ttk as ttk
|
||||||
|
|
||||||
|
class GridFrame(ttk.Frame):
|
||||||
|
def __init__(self, parent, *args, **kwargs):
|
||||||
|
ttk.Frame.__init__(self, parent, *args, **kwargs)
|
||||||
|
|
||||||
|
def add(self, element, x, y, xspan=1, yspan=1):
|
||||||
|
element.grid(column=x, row=y, columnspan=xspan, rowspan=yspan, sticky=tk.N+tk.E+tk.S+tk.W)
|
||||||
|
self.rowconfigure(x, weight=1)
|
||||||
|
self.columnconfigure(y, weight=1)
|
||||||
@ -8,6 +8,7 @@ from tkinter import scrolledtext
|
|||||||
from tkinter import filedialog
|
from tkinter import filedialog
|
||||||
|
|
||||||
from .status import Status, StatusFrame
|
from .status import Status, StatusFrame
|
||||||
|
from .gridframe import GridFrame
|
||||||
from .primary import Primary
|
from .primary import Primary
|
||||||
|
|
||||||
font1Size = 32
|
font1Size = 32
|
||||||
@ -19,15 +20,15 @@ style = dict(background='black',
|
|||||||
foreground='white',
|
foreground='white',
|
||||||
font=font2)
|
font=font2)
|
||||||
|
|
||||||
class MainApplication(ttk.Frame):
|
class MainApplication(GridFrame):
|
||||||
|
|
||||||
def __init__(self, parent, *args, **kwargs):
|
def __init__(self, parent, *args, **kwargs):
|
||||||
ttk.Frame.__init__(self, parent, *args, **kwargs)
|
GridFrame.__init__(self, parent, *args, **kwargs)
|
||||||
self.widgets = dict()
|
self.widgets = dict()
|
||||||
|
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.primary = Primary(self, *args, **kwargs)
|
self.primary = Primary(self, *args, **kwargs)
|
||||||
self.primary.grid(column=0, row=0, sticky=tk.N+tk.S+tk.E+tk.W)
|
self.add(self.primary, 0, 0)
|
||||||
self.create_widgets()
|
self.create_widgets()
|
||||||
|
|
||||||
def create_widgets(self):
|
def create_widgets(self):
|
||||||
@ -37,26 +38,22 @@ class MainApplication(ttk.Frame):
|
|||||||
self.widgets['temp'] = tempLabel
|
self.widgets['temp'] = tempLabel
|
||||||
|
|
||||||
slipList = tk.Listbox(self, **style)
|
slipList = tk.Listbox(self, **style)
|
||||||
slipList.grid(column=0, row=1, sticky=tk.N+tk.S+tk.E+tk.W)
|
self.add(slipList, 0, 1)
|
||||||
self.widgets['sliplist'] = slipList
|
self.widgets['sliplist'] = slipList
|
||||||
|
|
||||||
codeletList = tk.Listbox(self, **style)
|
codeletList = tk.Listbox(self, **style)
|
||||||
codeletList.grid(column=1, row=1, sticky=tk.N+tk.S+tk.E+tk.W)
|
self.add(codeletList, 1, 1)
|
||||||
self.widgets['codeletlist'] = codeletList
|
self.widgets['codeletlist'] = codeletList
|
||||||
|
|
||||||
l = ttk.Label(self, text='temp', **style, padding=30)
|
l = ttk.Label(self, text='temp', **style, padding=30)
|
||||||
l.grid(column=2, row=1, sticky=tk.N+tk.S+tk.E+tk.W)
|
self.add(l, 2, 1)
|
||||||
|
|
||||||
self.rowconfigure(0, weight=1)
|
|
||||||
for i in range(4):
|
|
||||||
self.columnconfigure(i, weight=1)
|
|
||||||
|
|
||||||
self.graph1 = Status()
|
self.graph1 = Status()
|
||||||
sframe = StatusFrame(self, self.graph1, 'graph 1')
|
sframe1 = StatusFrame(self, self.graph1, 'graph 1')
|
||||||
sframe.grid(column=1, row=0, sticky=tk.N+tk.S+tk.E+tk.W)
|
self.add(sframe1, 1, 0)
|
||||||
self.graph2 = Status()
|
self.graph2 = Status()
|
||||||
sframe = StatusFrame(self, self.graph2, 'graph 2')
|
sframe2 = StatusFrame(self, self.graph2, 'graph 2')
|
||||||
sframe.grid(column=2, row=0, sticky=tk.N+tk.S+tk.E+tk.W)
|
self.add(sframe2, 2, 0)
|
||||||
|
|
||||||
def update(self, copycat):
|
def update(self, copycat):
|
||||||
self.primary.update(copycat)
|
self.primary.update(copycat)
|
||||||
|
|||||||
@ -5,6 +5,7 @@ from tkinter import scrolledtext
|
|||||||
from tkinter import filedialog
|
from tkinter import filedialog
|
||||||
|
|
||||||
from .control import Control
|
from .control import Control
|
||||||
|
from .gridframe import GridFrame
|
||||||
|
|
||||||
font1Size = 32
|
font1Size = 32
|
||||||
font2Size = 16
|
font2Size = 16
|
||||||
@ -43,23 +44,18 @@ def create_main_canvas(root, initial, final, new, guess):
|
|||||||
|
|
||||||
return canvas
|
return canvas
|
||||||
|
|
||||||
class Primary(ttk.Frame):
|
class Primary(GridFrame):
|
||||||
|
|
||||||
def __init__(self, parent, *args, **kwargs):
|
def __init__(self, parent, *args, **kwargs):
|
||||||
ttk.Frame.__init__(self, parent, *args, **kwargs)
|
GridFrame.__init__(self, parent, *args, **kwargs)
|
||||||
|
|
||||||
self.canvas = create_main_canvas(self, 'abc', 'abd', 'ijk', '?')
|
self.canvas = create_main_canvas(self, 'abc', 'abd', 'ijk', '?')
|
||||||
self.canvas.grid(column=0, row=0, rowspan=2, sticky=tk.N+tk.S+tk.E+tk.W)
|
self.add(self.canvas, 0, 0, xspan=2)
|
||||||
|
|
||||||
self.rowconfigure(0, weight=1)
|
|
||||||
self.columnconfigure(0, weight=1)
|
|
||||||
|
|
||||||
self.control = Control(self)
|
self.control = Control(self)
|
||||||
self.control.grid(column=0, row=2, sticky=tk.N+tk.S+tk.E+tk.W)
|
self.add(self.control, 0, 2)
|
||||||
self.rowconfigure(0, weight=1)
|
|
||||||
self.columnconfigure(2, weight=1)
|
|
||||||
|
|
||||||
def update(self, copycat):
|
def update(self, copycat):
|
||||||
answer = '' if copycat.workspace.rule is None else copycat.workspace.rule.buildTranslatedRule()
|
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, 'abc', 'abd', 'ijk', answer)
|
||||||
self.canvas.grid(column=0, row=0, rowspan=2, sticky=tk.N+tk.S+tk.E+tk.W)
|
self.add(self.canvas, 0, 0, xspan=2)
|
||||||
|
|||||||
@ -15,9 +15,9 @@ LARGE_FONT = ('Verdana', 20)
|
|||||||
|
|
||||||
plt.style.use('dark_background')
|
plt.style.use('dark_background')
|
||||||
|
|
||||||
class StatusFrame(tk.Frame):
|
class StatusFrame(ttk.Frame):
|
||||||
def __init__(self, parent, status, title, toolbar=False):
|
def __init__(self, parent, status, title, toolbar=False):
|
||||||
tk.Frame.__init__(self, parent)
|
ttk.Frame.__init__(self, parent)
|
||||||
self.status = status
|
self.status = status
|
||||||
|
|
||||||
self.canvas = FigureCanvasTkAgg(status.figure, self)
|
self.canvas = FigureCanvasTkAgg(status.figure, self)
|
||||||
|
|||||||
Reference in New Issue
Block a user