Creates primary gui frame class
This commit is contained in:
@ -1,60 +0,0 @@
|
||||
import matplotlib
|
||||
matplotlib.use("TkAgg")
|
||||
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
|
||||
from matplotlib.figure import Figure
|
||||
|
||||
import tkinter as tk
|
||||
import tkinter.ttk as ttk
|
||||
|
||||
import time
|
||||
|
||||
LARGE_FONT = ('Verdana', 14)
|
||||
|
||||
class FigureFrame(tk.Frame):
|
||||
|
||||
def __init__(self, parent, figure, title):
|
||||
self.figure = figure
|
||||
|
||||
tk.Frame.__init__(self, parent)
|
||||
label = tk.Label(self, text=title, font=LARGE_FONT)
|
||||
label.pack(pady=10,padx=10)
|
||||
|
||||
self.canvas = FigureCanvasTkAgg(self.figure, self)
|
||||
self.canvas.show()
|
||||
self.canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
|
||||
|
||||
toolbar = NavigationToolbar2TkAgg(self.canvas, self)
|
||||
toolbar.update()
|
||||
self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
|
||||
|
||||
def update(self, figure):
|
||||
self.canvas = FigureCanvasTkAgg(self.figure, self)
|
||||
self.canvas.show()
|
||||
|
||||
if __name__ == '__main__':
|
||||
root = tk.Tk()
|
||||
|
||||
x = [1,2,3,4]
|
||||
y = [2,3,4,5]
|
||||
f = Figure(figsize=(5,5), dpi=100)
|
||||
a = f.add_subplot(111)
|
||||
a.plot(x, y)
|
||||
|
||||
figure = FigureFrame(root, f, 'Lines')
|
||||
figure.pack()
|
||||
|
||||
i = 0
|
||||
while True:
|
||||
root.update()
|
||||
root.update_idletasks()
|
||||
time.sleep(1)
|
||||
i += 1
|
||||
x += [i]
|
||||
y += [i**2]
|
||||
print(x, y)
|
||||
f = Figure(figsize=(5,5), dpi=100)
|
||||
a = f.add_subplot(111)
|
||||
a.plot(x, y)
|
||||
#a.clear()
|
||||
#a.plot(x, y)
|
||||
figure = FigureFrame(root, f, 'Lines')
|
||||
1
copycat/gui/__init__.py
Normal file
1
copycat/gui/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .gui import GUI
|
||||
@ -1,4 +1,3 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import time
|
||||
|
||||
@ -9,6 +8,7 @@ from tkinter import scrolledtext
|
||||
from tkinter import filedialog
|
||||
|
||||
from .status import Status, StatusFrame
|
||||
from .primary import Primary
|
||||
|
||||
font1Size = 32
|
||||
font2Size = 16
|
||||
@ -21,48 +21,18 @@ style = dict(background='black',
|
||||
relief=tk.GROOVE,
|
||||
font=font2)
|
||||
|
||||
def create_main_canvas(root, initial, final, new, guess):
|
||||
padding = 100
|
||||
|
||||
canvas = tk.Canvas(root, borderwidth=5, relief=tk.GROOVE, background='#70747a')
|
||||
|
||||
def add_sequences(sequences, x, y):
|
||||
for sequence in sequences:
|
||||
x += padding
|
||||
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
|
||||
|
||||
class MainApplication(ttk.Frame):
|
||||
MAX_COLUMNS = 10
|
||||
|
||||
def __init__(self, parent, *args, **kwargs):
|
||||
ttk.Frame.__init__(self, parent, *args, **kwargs)
|
||||
self.widgets = dict()
|
||||
|
||||
self.parent = parent
|
||||
self.primary = Primary(self, *args, **kwargs)
|
||||
self.primary.grid(column=0, row=0, sticky=tk.N+tk.S+tk.E+tk.W)
|
||||
self.create_widgets()
|
||||
self.canvas = None
|
||||
|
||||
def create_widgets(self):
|
||||
self.canvas = create_main_canvas(self, 'abc', 'abd', 'ijk', '?')
|
||||
self.canvas.grid(column=0, row=0, sticky=tk.N+tk.S+tk.E+tk.W)
|
||||
|
||||
tempLabel = ttk.Label(self, text='', **style, padding=30)
|
||||
#tempLabel.grid(column=1, row=0, sticky=tk.N+tk.S+tk.E+tk.W)
|
||||
@ -91,16 +61,13 @@ class MainApplication(ttk.Frame):
|
||||
sframe.grid(column=2, row=0, sticky=tk.N+tk.S+tk.E+tk.W)
|
||||
|
||||
def update(self, copycat):
|
||||
self.primary.update(copycat)
|
||||
temp = copycat.temperature.value()
|
||||
slipnodes = copycat.slipnet.slipnodes
|
||||
codelets = copycat.coderack.codelets
|
||||
answer = '' if copycat.workspace.rule is None else copycat.workspace.rule.buildTranslatedRule()
|
||||
|
||||
slipList = self.widgets['sliplist']
|
||||
slipList.delete(0, slipList.size())
|
||||
|
||||
self.canvas = create_main_canvas(self, 'abc', 'abd', 'ijk', answer)
|
||||
self.canvas.grid(column=0, row=0, sticky=tk.N+tk.S+tk.E+tk.W)
|
||||
self.widgets['temp']['text'] = 'Temp:\n{}'.format(round(temp, 2))
|
||||
slipnodes = sorted(slipnodes, key=lambda s:s.activation, reverse=True)
|
||||
for item in slipnodes:
|
||||
@ -114,25 +81,12 @@ class MainApplication(ttk.Frame):
|
||||
listStr = '{}: {}'.format(codelet.name, round(codelet.urgency, 2))
|
||||
codeletList.insert(tk.END, listStr)
|
||||
|
||||
'''
|
||||
descriptionsFrame = tk.Frame(self)
|
||||
for i, obj in enumerate(sorted(copycat.workspace.objects, key=lambda o:o.string.string)):
|
||||
l = tk.Label(descriptionsFrame, text=obj.string.string)
|
||||
l.grid(column=i, row=0)
|
||||
for j, description in enumerate(obj.descriptions):
|
||||
l = tk.Label(descriptionsFrame, text='[]')
|
||||
l.grid(column=i, row=j+1)
|
||||
descriptionsFrame.grid(row=1)
|
||||
'''
|
||||
|
||||
|
||||
class GUI(object):
|
||||
def __init__(self, title, updateInterval=.1):
|
||||
self.root = tk.Tk()
|
||||
self.root.title(title)
|
||||
tk.Grid.rowconfigure(self.root, 0, weight=1)
|
||||
tk.Grid.columnconfigure(self.root, 0, weight=1)
|
||||
#self.root.geometry('1200x800')
|
||||
self.app = MainApplication(self.root)
|
||||
self.app.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W)
|
||||
|
||||
60
copycat/gui/primary.py
Normal file
60
copycat/gui/primary.py
Normal file
@ -0,0 +1,60 @@
|
||||
import tkinter as tk
|
||||
import tkinter.ttk as ttk
|
||||
|
||||
from tkinter import scrolledtext
|
||||
from tkinter import filedialog
|
||||
|
||||
font1Size = 32
|
||||
font2Size = 16
|
||||
font1 = ('Helvetica', str(font1Size))
|
||||
font2 = ('Helvetica', str(font2Size))
|
||||
|
||||
style = dict(background='black',
|
||||
foreground='white',
|
||||
borderwidth=5,
|
||||
relief=tk.GROOVE,
|
||||
font=font2)
|
||||
|
||||
def create_main_canvas(root, initial, final, new, guess):
|
||||
padding = 100
|
||||
|
||||
canvas = tk.Canvas(root, borderwidth=5, relief=tk.GROOVE, background='#70747a')
|
||||
|
||||
def add_sequences(sequences, x, y):
|
||||
for sequence in sequences:
|
||||
x += padding
|
||||
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
|
||||
|
||||
class Primary(ttk.Frame):
|
||||
|
||||
def __init__(self, parent, *args, **kwargs):
|
||||
ttk.Frame.__init__(self, parent, *args, **kwargs)
|
||||
|
||||
self.canvas = create_main_canvas(self, 'abc', 'abd', 'ijk', '?')
|
||||
self.canvas.grid(column=0, row=0, sticky=tk.N+tk.S+tk.E+tk.W)
|
||||
|
||||
self.rowconfigure(0, weight=1)
|
||||
self.columnconfigure(0, weight=1)
|
||||
|
||||
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.grid(column=0, row=0, sticky=tk.N+tk.S+tk.E+tk.W)
|
||||
@ -1,57 +0,0 @@
|
||||
import matplotlib
|
||||
matplotlib.use("TkAgg")
|
||||
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
|
||||
from matplotlib.figure import Figure
|
||||
|
||||
import tkinter as tk
|
||||
import tkinter.ttk as ttk
|
||||
|
||||
import time
|
||||
import matplotlib.animation as animation
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
plt.style.use('dark_background')
|
||||
|
||||
LARGE_FONT = ('Verdana', 20)
|
||||
|
||||
f = Figure(figsize=(5,5), dpi=100)
|
||||
a = f.add_subplot(111)
|
||||
|
||||
|
||||
def animate(i):
|
||||
print(i)
|
||||
pullData = open("sampleText.txt","r").read()
|
||||
dataList = pullData.split('\n')
|
||||
xList = []
|
||||
yList = []
|
||||
for eachLine in dataList:
|
||||
if len(eachLine) > 1:
|
||||
x, y = eachLine.split(',')
|
||||
xList.append(int(x))
|
||||
yList.append(int(y))
|
||||
|
||||
a.clear()
|
||||
a.plot(xList, yList)
|
||||
|
||||
class test(tk.Frame):
|
||||
|
||||
def __init__(self, parent):
|
||||
tk.Frame.__init__(self, parent)
|
||||
label = tk.Label(self, text="Graph Page!", font=LARGE_FONT)
|
||||
label.pack(pady=10,padx=10)
|
||||
|
||||
canvas = FigureCanvasTkAgg(f, self)
|
||||
canvas.show()
|
||||
canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
|
||||
|
||||
toolbar = NavigationToolbar2TkAgg(canvas, self)
|
||||
toolbar.update()
|
||||
canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
|
||||
|
||||
|
||||
app = tk.Tk()
|
||||
test = test(app)
|
||||
test.grid()
|
||||
ani = animation.FuncAnimation(f, animate, interval=1000)
|
||||
app.mainloop()
|
||||
Reference in New Issue
Block a user