From 88f09bb13f10c7733dd215249704b7be89c7c74f Mon Sep 17 00:00:00 2001 From: Michael Dryden Date: Fri, 2 May 2014 16:49:30 -0400 Subject: [PATCH] Menu option to save NPY array of current experiment. --- dstatInterface/dstat_comm.py | 4 --- dstatInterface/interface/dstatInterface.glade | 14 ++++++++--- dstatInterface/interface/save.py | 25 +++++++++++++++++++ dstatInterface/interface_test.py | 11 +++++--- 4 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 dstatInterface/interface/save.py diff --git a/dstatInterface/dstat_comm.py b/dstatInterface/dstat_comm.py index 2bddee4..e1d45de 100644 --- a/dstatInterface/dstat_comm.py +++ b/dstatInterface/dstat_comm.py @@ -128,10 +128,6 @@ class Experiment: def data_postprocessing(self): pass - #remove first two data points - usually bad // Do this when calling for display updates -# for i in self.data: -# i.pop(0) -# i.pop(0) class chronoamp(Experiment): def __init__(self, parameters, view_parameters, plot_instance, databuffer_instance): diff --git a/dstatInterface/interface/dstatInterface.glade b/dstatInterface/interface/dstatInterface.glade index b81b447..e56f064 100644 --- a/dstatInterface/interface/dstatInterface.glade +++ b/dstatInterface/interface/dstatInterface.glade @@ -76,6 +76,11 @@ 0.47999998927116394 gtk-missing-image + + True + False + gtk-save-as + @@ -132,12 +137,13 @@ - - gtk-save + + Save data as NPY True False - True - True + image2 + False + diff --git a/dstatInterface/interface/save.py b/dstatInterface/interface/save.py new file mode 100644 index 0000000..5eca5c2 --- /dev/null +++ b/dstatInterface/interface/save.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +import gtk, io +import numpy as np + +class npSave: + def __init__(self, current_exp): + self.exp = current_exp + self.fcd = gtk.FileChooserDialog("Save...", None, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) + + self.fcd.set_do_overwrite_confirmation(True) + + self.response = self.fcd.run() + + if self.response == gtk.RESPONSE_OK: + self.path = self.fcd.get_filename() + print "Selected filepath: %s" % self.path + self.npy() + self.fcd.destroy() + + def npy(self): + self.data = np.array(self.exp.data) + np.save(self.path, self.data) + + diff --git a/dstatInterface/interface_test.py b/dstatInterface/interface_test.py index f8de963..277b7c4 100644 --- a/dstatInterface/interface_test.py +++ b/dstatInterface/interface_test.py @@ -19,6 +19,7 @@ import interface.cv as cv import interface.swv as swv import interface.acv as acv import interface.pd as pd +import interface.save as save import dstat_comm as comm from serial import SerialException @@ -283,11 +284,11 @@ class main: except SerialException: self.spinner.stop() self.statusbar.push(self.error_context_id, "Could not establish serial connection.") - + except AssertionError as e: self.spinner.stop() self.statusbar.push(self.error_context_id, str(e)) - + self.databuffer.set_text("") self.databuffer.place_cursor(self.databuffer.get_start_iter()) @@ -295,9 +296,13 @@ class main: for j in i: self.databuffer.insert_at_cursor(str(j)+ "\t") self.databuffer.insert_at_cursor("\n") - self.spinner.stop() + def on_file_save_npy_activate(self, menuitem, data=None): + if self.current_exp: + self.save = save.npSave(self.current_exp) + + if __name__ == "__main__": main = main() gtk.main() \ No newline at end of file -- GitLab