Commit b5f3dc14 authored by Maximilian Schanner's avatar Maximilian Schanner
Browse files

Add map output and fix the range widget.

parent 010d6fc2
......@@ -118,9 +118,10 @@ class MainWindow(QWidget):
model = Model(self.modelSelector.currentText())
# update the range
self.epoch.min = model.t_min
self.epoch.min = model.t_max
self.epoch.default = int((model.t_max + model.t_min) / 2)
self.epoch.max = model.t_max
self.epoch.default = model.t_max
self.range.setText(f'[{model.t_min}, {model.t_max}]')
self.epoch.validating()
# update the model for saving
self.saveWindow.model = model
......@@ -361,7 +362,8 @@ class SaveWindow(QWidget):
self.setWindowTitle('pymagglobal - output')
# set up a dict for the dropdown menu
self.selectorDict = {'model coefficients at an epoch': 'coeffs-epoch',
'field values at a specific location': 'local'}
'field values at a specific location': 'local',
'global field values at an epoch': 'map'}
# drop down menu of what to store
self.typeSelector = QComboBox()
self.typeSelector.addItems(self.selectorDict.keys())
......@@ -403,6 +405,12 @@ class SaveWindow(QWidget):
+ self.lon.text()
elif selected == 'coeffs-epoch':
params = self.epoch.text()
elif selected == 'map':
if self.saveDifButton.isChecked():
_type = 'dif'
else:
_type = 'nez'
params = '--type ' + _type + ' ' + self.epoch.text()
# get an ouput filename
fname, _ = QFileDialog.getSaveFileName(self, 'Choose filename',
str(Path.home()))
......@@ -429,6 +437,8 @@ class SaveWindow(QWidget):
self.inputWidget = self.locSelector()
elif selected == 'coeffs-epoch':
self.inputWidget = self.epochSelector()
elif selected == 'map':
self.inputWidget = self.mapSelector()
else:
self.inputWidget = QLabel(self.selectorDict[self.typeSelector
.currentText()])
......@@ -480,16 +490,54 @@ class SaveWindow(QWidget):
q.setLayout(vbox)
return q
def mapSelector(self):
''' The argument widget for map output '''
epochLabel = QLabel('Epoch [yrs.]')
epochLabel.setAlignment(Qt.AlignCenter)
self.epoch = QRangeEdit(str(self.model.t_max),
self.model.t_min,
self.model.t_max)
self.epoch.setFixedWidth(100)
# redundant, but looks better as the location selector is in a hbox
epochBox = QHBoxLayout()
epochBox.addWidget(self.epoch)
epochWidget = QWidget()
epochWidget.setLayout(epochBox)
# Radio buttons for field type
typeLabel = QLabel('Field type')
typeLabel.setAlignment(Qt.AlignCenter)
self.saveNezButton = QRadioButton("NEZ")
self.saveDifButton = QRadioButton("DIF")
self.saveDifButton.setChecked(True)
typeBox = QHBoxLayout()
typeBox.addWidget(self.saveNezButton)
typeBox.addWidget(self.saveDifButton)
typeBox.setAlignment(Qt.AlignCenter)
typeWidget = QWidget()
typeWidget.setLayout(typeBox)
# Put into widget
vbox = QVBoxLayout()
vbox.addWidget(epochLabel)
vbox.addWidget(epochWidget)
vbox.addWidget(typeLabel)
vbox.addWidget(typeWidget)
vbox.setAlignment(Qt.AlignTop)
q = QWidget()
q.setLayout(vbox)
return q
def epochSelector(self):
''' The argument widget for coefficient output '''
epochLabel = QLabel('Epoch [yrs.]')
epochLabel.setAlignment(Qt.AlignCenter)
default = int((self.model.t_max + self.model.t_min) / 2)
self.epoch = QRangeEdit(str(default),
self.epoch = QRangeEdit(str(self.model.t_max),
self.model.t_min,
self.model.t_max,
default)
self.model.t_max)
self.epoch.setFixedWidth(100)
# redundant, but looks better as the location selector is in a hbox
epochBox = QHBoxLayout()
......@@ -507,7 +555,6 @@ class SaveWindow(QWidget):
q.setLayout(vbox)
return q
class QHLine(QFrame):
''' Horizontal separation lines on pyQt5 layout
'''
......@@ -520,11 +567,10 @@ class QHLine(QFrame):
class QRangeEdit(QLineEdit):
''' A line edit that checks for input in a given range. If the input is
outside, a default value will be inserted. '''
def __init__(self, init, _min, _max, default=0):
def __init__(self, init, _min, _max):
super().__init__(init)
self.min = _min
self.max = _max
self.default = default
self.editingFinished.connect(self.validating)
......@@ -534,8 +580,13 @@ class QRangeEdit(QLineEdit):
14)[0] == QValidator.Acceptable):
self.setFocus()
else:
self.setText(str(self.default))
try:
if float(self.text()) < self.min:
self.setText(str(self.min))
elif float(self.text()) > self.max:
self.setText(str(self.max))
except ValueError:
self.setText(str(self.max))
def main():
app = QApplication(sys.argv)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment