From 21875117061e1804c67317581e07a25b0901c04f Mon Sep 17 00:00:00 2001 From: LSaldyt Date: Thu, 26 Oct 2017 11:00:08 -0700 Subject: [PATCH] Adds plot saving --- copycat/gui/gui.py | 11 +++++++---- copycat/gui/status.py | 33 ++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/copycat/gui/gui.py b/copycat/gui/gui.py index b4f2bdf..1341ae2 100755 --- a/copycat/gui/gui.py +++ b/copycat/gui/gui.py @@ -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() diff --git a/copycat/gui/status.py b/copycat/gui/status.py index 9b5363a..e9863a1 100644 --- a/copycat/gui/status.py +++ b/copycat/gui/status.py @@ -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)