import numpy as np
import math
import Tkinter as tk
import tkFileDialog
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
from DataIO import DataIO
[docs]class DataViewer(tk.Frame):
def __init__(self, master=None):
# Initialise GUI
tk.Frame.__init__(self, master)
self.master.title("Data Viewer")
self.grid()
# Initialize Standard Values for GUI
self.FileText = tk.StringVar()
self.Meas_Path = ''
self.TestText = tk.StringVar()
self.test_counter = 0
self.BoxVar = tk.StringVar()
self.ActiveTest = ''
# Bind Key Strokes To Function
#self.bind('<KeyRelease-Left>', self.leftKey)
#self.bind('<KeyRelease-Right>', self.rightKey)
self.createWidgets()
# Setup Element on GUI
# GUI triggered functions
[docs] def FileBrowse(self):
try:
inputFiles = tkFileDialog.askopenfilenames()
self.FileText.set(self.master.tk.splitlist(inputFiles)[0])
self.FileLoad()
except IndexError:
pass # No file selected, no reason to report error
except Exception as e:
print("Error: {}".format(e.stack))
[docs] def ClearCanvas(self):
self.f.clf()
self.f.canvas.draw()
[docs] def TestNameBoxChange(self,value):
self.ActiveTest = value
self.BoxVar.set(value)
[docs] def NameLoad(self):
if self.ActiveTest != '':
self.TestText.set(self.ActiveTest)
self.update_canvas(self.Meas_Path, self.ActiveTest,False)
[docs] def BackLoad(self):
if self.test_counter > 0:
self.test_counter -= 1
self.TestText.set(self.test_names[self.test_counter])
self.update_canvas(self.Meas_Path,self.test_names[self.test_counter])
[docs] def NextLoad(self):
if self.test_counter < len(self.test_names)-1:
self.test_counter += 1
self.TestText.set(self.test_names[self.test_counter])
self.update_canvas(self.Meas_Path,self.test_names[self.test_counter])
[docs] def FileLoad(self):
self.Meas_Path = self.FileText.get()
#get_test_names and fill up option_menu
self.test_names = DataIO.get_test_names(self.Meas_Path)
self.TestNameBox["menu"].delete(0, "end")
for entry in self.test_names:
self.TestNameBox["menu"].add_command(label=entry,command=lambda value=entry: self.TestNameBoxChange(value))
#show_first_data
self.test_counter = 0
self.TestText.set(self.test_names[0])
self.update_canvas(self.Meas_Path,self.test_names[0])
def _quit():
root.quit() # stops mainloop
root.destroy()
#
# FUNCTIONAL Functions ###############################
#
[docs] def update_canvas(self,path,test_name,clear=True):
data = DataIO.get_test_data(path, test_name)
if clear:
self.f.clf()
a = self.f.add_subplot(111)
try:
a.plot(zip(*data)[0],zip(*data)[1],'b')
self.f.canvas.draw()
except IndexError:
print("Dataset '{}' only has 1 dimension, not able to plot.".format(test_name))
self.f.clf()
if __name__ == "__main__":
root = tk.Tk()
main = DataViewer(root)
main.pack(side="top", fill="both", expand=True)
root.mainloop()
'''
Copyright (C) 2017 Robert Polster
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''