Adds plot saving

This commit is contained in:
LSaldyt
2017-10-26 11:00:08 -07:00
parent 50bbb468b7
commit 2187511706
2 changed files with 31 additions and 13 deletions

View File

@ -10,6 +10,7 @@ from tkinter import filedialog
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from .status import Status, StatusFrame from .status import Status, StatusFrame
from .status import Plot
from .gridframe import GridFrame from .gridframe import GridFrame
from .primary import Primary from .primary import Primary
from .list import List from .list import List
@ -58,9 +59,11 @@ class MainApplication(GridFrame):
self.logBox = List(self, 10, **style) self.logBox = List(self, 10, **style)
self.add(self.logBox, 1, 0) self.add(self.logBox, 1, 0)
self.graph2 = Status() self.graph2 = Plot(self, 'Answer Distribution')
sframe2 = StatusFrame(self, self.graph2, 'graph 2') #self.graph2 = Status()
self.add(sframe2, 2, 0) #sframe2 = StatusFrame(self, self.graph2, 'graph 2')
#self.add(sframe2, 2, 0)
self.add(self.graph2, 2, 0)
def update(self, copycat): def update(self, copycat):
self.primary.update(copycat) self.primary.update(copycat)
@ -96,7 +99,7 @@ class GUI(object):
def modifier(status): def modifier(status):
with plt.style.context(('dark_background')): with plt.style.context(('dark_background')):
plot_imbedded(answers, status) plot_imbedded(answers, status)
self.app.graph2.modifier = modifier self.app.graph2.status.modifier = modifier
def refresh(self): def refresh(self):
self.root.update_idletasks() self.root.update_idletasks()

View File

@ -11,12 +11,33 @@ import matplotlib.animation as animation
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
LARGE_FONT = ('Verdana', 20)
plt.style.use('dark_background') plt.style.use('dark_background')
from .gridframe import GridFrame
class Plot(GridFrame):
def __init__(self, parent, title):
GridFrame.__init__(self, parent)
self.status = Status()
self.sframe = StatusFrame(self, self.status, title)
self.add(self.sframe, 0, 0, xspan=2)
self.savebutton = ttk.Button(self, text='Save to path:', command=lambda : self.save())
self.add(self.savebutton, 0, 1)
self.pathentry = ttk.Entry(self, style='EntryStyle.TEntry', textvariable='output/dist.png')
self.add(self.pathentry, 1, 1)
def save(self):
path = self.pathentry.get()
if len(path) > 0:
try:
self.status.figure.savefig(path)
except Exception as e:
print(e)
class StatusFrame(ttk.Frame): class StatusFrame(ttk.Frame):
def __init__(self, parent, status, title, toolbar=False): def __init__(self, parent, status, title):
ttk.Frame.__init__(self, parent) ttk.Frame.__init__(self, parent)
self.status = status self.status = status
@ -26,12 +47,6 @@ class StatusFrame(ttk.Frame):
self.animation = animation.FuncAnimation(status.figure, lambda i : status.update_plots(i), interval=1000) self.animation = animation.FuncAnimation(status.figure, lambda i : status.update_plots(i), interval=1000)
if toolbar:
toolbar = NavigationToolbar2TkAgg(self.canvas, self)
toolbar.update()
self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
class Status(object): class Status(object):
def __init__(self): def __init__(self):
self.figure = Figure(figsize=(5,5), dpi=100) self.figure = Figure(figsize=(5,5), dpi=100)