Skip to content

Commit

Permalink
Resolved issues #13 and #14, made window grab focus
Browse files Browse the repository at this point in the history
1) Resolved range=0 ValueError by adding a check to validateChoices() so that plotting routine will abort if axes are incorrectly set this way and show an informative error warning.

2) Wrapped plotting routine in an error handling statment to catch ValueErrors (although these should nominally not occur)

3) Added a line at the top that makes the window pop up on top when dataview is opened (so you don't have to go searching for it behind other windows).
  • Loading branch information
pheuer committed Apr 16, 2019
1 parent 1ba7886 commit b0c157a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 36 deletions.
Binary file modified dataview/.png
Binary file not shown.
61 changes: 25 additions & 36 deletions dataview/dataview.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from astropy import units

from PyQt5 import QtWidgets, QtGui
from PyQt5 import QtWidgets, QtGui, QtCore

import matplotlib
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
Expand All @@ -30,6 +30,7 @@ def __init__(self):
def buildGUI(self):
self._main = QtWidgets.QWidget()
self.setCentralWidget(self._main)
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)

#Playing around with a custom style sheet...
#self.setStyleSheet(open('stylesheet.css').read())
Expand Down Expand Up @@ -181,12 +182,13 @@ def buildGUI(self):
self.datarange_auto.setChecked(True)
self.datarange_box.addWidget(self.datarange_auto)
self.datarange_auto.stateChanged.connect(self.updateDataRange)
self.connectedList.append(self.datarange_auto)

self.datarange_center = QtWidgets.QCheckBox("Center zero?")
self.datarange_center.setChecked(False)
self.datarange_box.addWidget(self.datarange_center)
self.datarange_center.stateChanged.connect(self.updateDataRange)

self.connectedList.append(self.datarange_center)

self.datarange_lbl = QtWidgets.QLabel("Data Range: ")
self.datarange_lbl.setFixedWidth(80)
Expand Down Expand Up @@ -588,21 +590,17 @@ def updateDataRange(self):










#PLOTTING ROUTINES

def validateChoices(self):
#Make a temporary array of the axes that are ACTUALLY about to be
#plotted (ignoring 2nd one if the plot is 2D)
if self.plottype_field.currentIndex() == 0:
thisplot_axes = [self.axes[0]]
thisplot_axes = [self.cur_axes[0]]
elif self.plottype_field.currentIndex() == 1:
thisplot_axes = self.axes
thisplot_axes = self.cur_axes


#Validate file
Expand All @@ -619,44 +617,35 @@ def validateChoices(self):
self.warninglabel.setText("WARNING: Axes selected need to be different!")
return False

#Current axes should be larger than 1D
for axind in self.cur_axes:
ax = self.axes[axind]
#Check that the original axis is is > 1 long
l = ax['ax'].shape[0]
if l > 1:
pass
else:
self.warninglabel.setText("WARNING: Axis must have length > 1: " + str(ax['name']))
return False
#Check to make sure it hasn't been TRIMMED to be < 2



#Check to make sure the axes make sense
for ind, ax_dict in enumerate(self.axes):
for ind, ax in enumerate(self.axes):
if ind in thisplot_axes:
if ax_dict['ind_a'].text() == ax_dict['ind_b'].text():
self.warninglabel.setText("WARNING: Axes range is 0!")
a = int(ax['ind_a'].value())
b = int(ax['ind_b'].value())
#Range should not be zero!
if np.abs(b - a) < 2:
self.warninglabel.setText("WARNING: Axes range is must be greater than 2!")
return False
elif float(ax_dict['ind_a'].text()) > float(ax_dict['ind_b'].text()):
#Order of elements in range should be correct!
elif a > b:
self.warninglabel.setText("WARNING: First range element should be smallest!")
return False

#If no warnings are found, set the label to blank and return True
self.warninglabel.setText("")
return True




def makePlot(self):
self.clearCanvas()
if self.validateChoices():
if self.plottype_field.currentIndex() == 0:
self.plot1D()
elif self.plottype_field.currentIndex() == 1:
self.plot2D()
try:
if self.validateChoices():
if self.plottype_field.currentIndex() == 0:
self.plot1D()
elif self.plottype_field.currentIndex() == 1:
self.plot2D()
except ValueError as e:
print("Value Error!: " + str(e))



Expand Down Expand Up @@ -1006,7 +995,7 @@ def format_float(value):
else:
#print('QApplication instance already exists: %s' % str(app))
pass

w = ApplicationWindow()
w.show()
app.exec()

0 comments on commit b0c157a

Please sign in to comment.