Skip to content

Commit

Permalink
Merge e8f6bf5 into 6e66bda
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Jun 20, 2014
2 parents 6e66bda + e8f6bf5 commit e830d36
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions pvextractor/gui.py
Expand Up @@ -295,11 +295,26 @@ def __init__(self, filename, backend="Qt4Agg", clim=None):
self.save_button_ax = self.fig.add_axes([0.65, 0.90, 0.20, 0.05])
self.save_button = Button(self.save_button_ax, 'Save slice to FITS')
self.save_button.on_clicked(self.save_fits)
self.file_status_text = self.fig.text(0.75, 0.875, "", ha='center', va='center')
self.set_file_status(None)

self.set_file_status(None)
self.pv_slice = None

self.cidpress = self.fig.canvas.mpl_connect('button_press_event', self.click)

def set_file_status(self, status, filename=None):
if status == 'instructions':
self.file_status_text.set_text('Please enter filename in terminal')
self.file_status_text.set_color('red')
elif status == 'saved':
self.file_status_text.set_text('File successfully saved to {0}'.format(filename))
self.file_status_text.set_color('green')
else:
self.file_status_text.set_text('')
self.file_status_text.set_color('black')
self.fig.canvas.draw()

def click(self, event):

if event.inaxes != self.ax2:
Expand All @@ -309,22 +324,23 @@ def click(self, event):

def save_fits(self, *args, **kwargs):

if self.backend == 'Qt4Agg':
from matplotlib.backends.backend_qt4 import _getSaveFileName
plot_name = _getSaveFileName(self.fig.canvas.manager.window, "Choose filename",
os.path.dirname(os.path.abspath(self.filename)), "", None)
plot_name = str(plot_name)
else:
print("Enter filename: ", end='')
self.set_file_status('instructions')

print("Enter filename: ", end='')
try:
plot_name = raw_input()
except NameError:
plot_name = input()

if self.pv_slice is None:
return

from astropy.io import fits
fits.writeto(plot_name, self.pv_slice, clobber=True)
self.pv_slice.writeto(plot_name, clobber=True)
print("Saved file to: ", plot_name)

self.set_file_status('saved', filename=plot_name)

def update_pv_slice(self, box):

path = Path(zip(box.x, box.y))
Expand Down

0 comments on commit e830d36

Please sign in to comment.