Adds plot saving
This commit is contained in:
@ -10,6 +10,7 @@ from tkinter import filedialog
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from .status import Status, StatusFrame
|
||||
from .status import Plot
|
||||
from .gridframe import GridFrame
|
||||
from .primary import Primary
|
||||
from .list import List
|
||||
@ -58,9 +59,11 @@ class MainApplication(GridFrame):
|
||||
self.logBox = List(self, 10, **style)
|
||||
self.add(self.logBox, 1, 0)
|
||||
|
||||
self.graph2 = Status()
|
||||
sframe2 = StatusFrame(self, self.graph2, 'graph 2')
|
||||
self.add(sframe2, 2, 0)
|
||||
self.graph2 = Plot(self, 'Answer Distribution')
|
||||
#self.graph2 = Status()
|
||||
#sframe2 = StatusFrame(self, self.graph2, 'graph 2')
|
||||
#self.add(sframe2, 2, 0)
|
||||
self.add(self.graph2, 2, 0)
|
||||
|
||||
def update(self, copycat):
|
||||
self.primary.update(copycat)
|
||||
@ -96,7 +99,7 @@ class GUI(object):
|
||||
def modifier(status):
|
||||
with plt.style.context(('dark_background')):
|
||||
plot_imbedded(answers, status)
|
||||
self.app.graph2.modifier = modifier
|
||||
self.app.graph2.status.modifier = modifier
|
||||
|
||||
def refresh(self):
|
||||
self.root.update_idletasks()
|
||||
|
||||
@ -11,12 +11,33 @@ import matplotlib.animation as animation
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
LARGE_FONT = ('Verdana', 20)
|
||||
|
||||
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):
|
||||
def __init__(self, parent, status, title, toolbar=False):
|
||||
def __init__(self, parent, status, title):
|
||||
ttk.Frame.__init__(self, parent)
|
||||
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)
|
||||
|
||||
if toolbar:
|
||||
toolbar = NavigationToolbar2TkAgg(self.canvas, self)
|
||||
toolbar.update()
|
||||
self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
|
||||
|
||||
|
||||
class Status(object):
|
||||
def __init__(self):
|
||||
self.figure = Figure(figsize=(5,5), dpi=100)
|
||||
|
||||
Reference in New Issue
Block a user