[new] if QSettings fails, ask to reset!
[bugfix] checkBoxPG outdated in QSettings [bugfix] moved SetChannelComponents to utils (produced circular imports)
This commit is contained in:
parent
c898f93293
commit
017683806b
26
PyLoT.py
26
PyLoT.py
@ -67,7 +67,7 @@ from pylot.core.pick.compare import Comparison
|
|||||||
from pylot.core.pick.utils import symmetrize_error, getQualityFromUncertainty, getPickQuality
|
from pylot.core.pick.utils import symmetrize_error, getQualityFromUncertainty, getPickQuality
|
||||||
from pylot.core.io.phases import picksdict_from_picks
|
from pylot.core.io.phases import picksdict_from_picks
|
||||||
import pylot.core.loc.nll as nll
|
import pylot.core.loc.nll as nll
|
||||||
from pylot.core.util.defaults import FILTERDEFAULTS, SetChannelComponents
|
from pylot.core.util.defaults import FILTERDEFAULTS
|
||||||
from pylot.core.util.errors import DatastructureError, \
|
from pylot.core.util.errors import DatastructureError, \
|
||||||
OverwriteError
|
OverwriteError
|
||||||
from pylot.core.util.connection import checkurl
|
from pylot.core.util.connection import checkurl
|
||||||
@ -76,7 +76,7 @@ from pylot.core.util.utils import fnConstructor, getLogin, \
|
|||||||
full_range, readFilterInformation, trim_station_components, check4gaps, make_pen, pick_color_plt, \
|
full_range, readFilterInformation, trim_station_components, check4gaps, make_pen, pick_color_plt, \
|
||||||
pick_linestyle_plt, remove_underscores, check4doubled, identifyPhaseID, excludeQualityClasses, \
|
pick_linestyle_plt, remove_underscores, check4doubled, identifyPhaseID, excludeQualityClasses, \
|
||||||
check4rotated, transform_colors_mpl, transform_colors_mpl_str, getAutoFilteroptions, check_all_obspy, \
|
check4rotated, transform_colors_mpl, transform_colors_mpl_str, getAutoFilteroptions, check_all_obspy, \
|
||||||
check_all_pylot, real_Bool
|
check_all_pylot, real_Bool, SetChannelComponents
|
||||||
from pylot.core.util.event import Event
|
from pylot.core.util.event import Event
|
||||||
from pylot.core.io.location import create_creation_info, create_event
|
from pylot.core.io.location import create_creation_info, create_event
|
||||||
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
|
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
|
||||||
@ -155,6 +155,8 @@ class MainWindow(QMainWindow):
|
|||||||
self.data._new = False
|
self.data._new = False
|
||||||
self.autodata = Data(self)
|
self.autodata = Data(self)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
if settings.value("user/FullName", None) is None:
|
if settings.value("user/FullName", None) is None:
|
||||||
fulluser = QInputDialog.getText(self, "Enter Name:", "Full name")
|
fulluser = QInputDialog.getText(self, "Enter Name:", "Full name")
|
||||||
settings.setValue("user/FullName", fulluser)
|
settings.setValue("user/FullName", fulluser)
|
||||||
@ -164,6 +166,21 @@ class MainWindow(QMainWindow):
|
|||||||
"Enter authority/institution name:",
|
"Enter authority/institution name:",
|
||||||
"Authority")
|
"Authority")
|
||||||
settings.setValue("agency_id", agency)
|
settings.setValue("agency_id", agency)
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
qmb = QMessageBox(self, icon=QMessageBox.Question,
|
||||||
|
text='Could not init application settings: {}.'
|
||||||
|
'Do you want to reset application settings?'.format(e),
|
||||||
|
windowTitle='PyLoT - Init QSettings warning')
|
||||||
|
qmb.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
|
||||||
|
qmb.setDefaultButton(QMessageBox.No)
|
||||||
|
ret = qmb.exec_()
|
||||||
|
if ret == qmb.Yes:
|
||||||
|
settings.clear()
|
||||||
|
else:
|
||||||
|
sys.exit()
|
||||||
|
print('Settings cleared!')
|
||||||
|
|
||||||
self.fnames = None
|
self.fnames = None
|
||||||
self._stime = None
|
self._stime = None
|
||||||
structure_setting = settings.value("data/Structure", "PILOT")
|
structure_setting = settings.value("data/Structure", "PILOT")
|
||||||
@ -671,11 +688,6 @@ class MainWindow(QMainWindow):
|
|||||||
xlab = self.startTime.strftime('seconds since %Y/%m/%d %H:%M:%S (%Z)')
|
xlab = self.startTime.strftime('seconds since %Y/%m/%d %H:%M:%S (%Z)')
|
||||||
plottitle = None # "Overview: {0} components ".format(self.getComponent())
|
plottitle = None # "Overview: {0} components ".format(self.getComponent())
|
||||||
self.disconnectWFplotEvents()
|
self.disconnectWFplotEvents()
|
||||||
if str(settings.value('pyqtgraphic')) == 'false' or not pg:
|
|
||||||
self.pg = False
|
|
||||||
self.dataPlot = PylotCanvas(parent=self, connect_events=False, multicursor=True)
|
|
||||||
self.dataPlot.updateWidget(xlab, None, plottitle)
|
|
||||||
else:
|
|
||||||
self.pg = pg
|
self.pg = pg
|
||||||
self.dataPlot = WaveformWidgetPG(parent=self,
|
self.dataPlot = WaveformWidgetPG(parent=self,
|
||||||
title=plottitle)
|
title=plottitle)
|
||||||
|
@ -13,8 +13,7 @@ import warnings
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from obspy.core import Stream, UTCDateTime
|
from obspy.core import Stream, UTCDateTime
|
||||||
from pylot.core.util.utils import real_Bool, real_None
|
from pylot.core.util.utils import real_Bool, real_None, SetChannelComponents
|
||||||
from pylot.core.util.defaults import SetChannelComponents
|
|
||||||
|
|
||||||
|
|
||||||
def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, verbosity=1, fig=None, linecolor='k'):
|
def earllatepicker(X, nfac, TSNR, Pick1, iplot=0, verbosity=1, fig=None, linecolor='k'):
|
||||||
|
@ -41,54 +41,3 @@ OUTPUTFORMATS = {'.xml': 'QUAKEML',
|
|||||||
LOCTOOLS = dict(nll=nll, hyposat=hyposat, velest=velest, hypo71=hypo71, hypodd=hypodd)
|
LOCTOOLS = dict(nll=nll, hyposat=hyposat, velest=velest, hypo71=hypo71, hypodd=hypodd)
|
||||||
|
|
||||||
|
|
||||||
class SetChannelComponents(object):
|
|
||||||
def __init__(self):
|
|
||||||
self.setDefaultCompPosition()
|
|
||||||
|
|
||||||
def setDefaultCompPosition(self):
|
|
||||||
# default component order
|
|
||||||
self.compPosition_Map = dict(Z=2, N=1, E=0)
|
|
||||||
self.compName_Map = {'3': 'Z',
|
|
||||||
'1': 'N',
|
|
||||||
'2': 'E'}
|
|
||||||
|
|
||||||
def _getCurrentPosition(self, component):
|
|
||||||
for key, value in self.compName_Map.items():
|
|
||||||
if value == component:
|
|
||||||
return key, value
|
|
||||||
errMsg = 'getCurrentPosition: Could not find former position of component {}.'.format(component)
|
|
||||||
raise ValueError(errMsg)
|
|
||||||
|
|
||||||
def _switch(self, component, component_alter):
|
|
||||||
# Without switching, multiple definitions of the same alter_comp are possible
|
|
||||||
old_alter_comp, _ = self._getCurrentPosition(component)
|
|
||||||
old_comp = self.compName_Map[component_alter]
|
|
||||||
if not old_alter_comp == component_alter and not old_comp == component:
|
|
||||||
self.compName_Map[old_alter_comp] = old_comp
|
|
||||||
print('switch: Automatically switched component {} to {}'.format(old_alter_comp, old_comp))
|
|
||||||
|
|
||||||
def setCompPosition(self, component_alter, component, switch=True):
|
|
||||||
component_alter = str(component_alter)
|
|
||||||
if not component_alter in self.compName_Map.keys():
|
|
||||||
errMsg = 'setCompPosition: Unrecognized alternative component {}. Expecting one of {}.'
|
|
||||||
raise ValueError(errMsg.format(component_alter, self.compName_Map.keys()))
|
|
||||||
if not component in self.compPosition_Map.keys():
|
|
||||||
errMsg = 'setCompPosition: Unrecognized target component {}. Expecting one of {}.'
|
|
||||||
raise ValueError(errMsg.format(component, self.compPosition_Map.keys()))
|
|
||||||
print('setCompPosition: set component {} to {}'.format(component_alter, component))
|
|
||||||
if switch:
|
|
||||||
self._switch(component, component_alter)
|
|
||||||
self.compName_Map[component_alter] = component
|
|
||||||
|
|
||||||
def getCompPosition(self, component):
|
|
||||||
return self._getCurrentPosition(component)[0]
|
|
||||||
|
|
||||||
def getPlotPosition(self, component):
|
|
||||||
component = str(component)
|
|
||||||
if component in self.compPosition_Map.keys():
|
|
||||||
return self.compPosition_Map[component]
|
|
||||||
elif component in self.compName_Map.keys():
|
|
||||||
return self.compPosition_Map[self.compName_Map[component]]
|
|
||||||
else:
|
|
||||||
errMsg = 'getCompPosition: Unrecognized component {}. Expecting one of {} or {}.'
|
|
||||||
raise ValueError(errMsg.format(component, self.compPosition_Map.keys(), self.compName_Map.keys()))
|
|
||||||
|
@ -1214,3 +1214,56 @@ if __name__ == "__main__":
|
|||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
|
||||||
|
|
||||||
|
class SetChannelComponents(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.setDefaultCompPosition()
|
||||||
|
|
||||||
|
def setDefaultCompPosition(self):
|
||||||
|
# default component order
|
||||||
|
self.compPosition_Map = dict(Z=2, N=1, E=0)
|
||||||
|
self.compName_Map = {'3': 'Z',
|
||||||
|
'1': 'N',
|
||||||
|
'2': 'E'}
|
||||||
|
|
||||||
|
def _getCurrentPosition(self, component):
|
||||||
|
for key, value in self.compName_Map.items():
|
||||||
|
if value == component:
|
||||||
|
return key, value
|
||||||
|
errMsg = 'getCurrentPosition: Could not find former position of component {}.'.format(component)
|
||||||
|
raise ValueError(errMsg)
|
||||||
|
|
||||||
|
def _switch(self, component, component_alter):
|
||||||
|
# Without switching, multiple definitions of the same alter_comp are possible
|
||||||
|
old_alter_comp, _ = self._getCurrentPosition(component)
|
||||||
|
old_comp = self.compName_Map[component_alter]
|
||||||
|
if not old_alter_comp == component_alter and not old_comp == component:
|
||||||
|
self.compName_Map[old_alter_comp] = old_comp
|
||||||
|
print('switch: Automatically switched component {} to {}'.format(old_alter_comp, old_comp))
|
||||||
|
|
||||||
|
def setCompPosition(self, component_alter, component, switch=True):
|
||||||
|
component_alter = str(component_alter)
|
||||||
|
if not component_alter in self.compName_Map.keys():
|
||||||
|
errMsg = 'setCompPosition: Unrecognized alternative component {}. Expecting one of {}.'
|
||||||
|
raise ValueError(errMsg.format(component_alter, self.compName_Map.keys()))
|
||||||
|
if not component in self.compPosition_Map.keys():
|
||||||
|
errMsg = 'setCompPosition: Unrecognized target component {}. Expecting one of {}.'
|
||||||
|
raise ValueError(errMsg.format(component, self.compPosition_Map.keys()))
|
||||||
|
print('setCompPosition: set component {} to {}'.format(component_alter, component))
|
||||||
|
if switch:
|
||||||
|
self._switch(component, component_alter)
|
||||||
|
self.compName_Map[component_alter] = component
|
||||||
|
|
||||||
|
def getCompPosition(self, component):
|
||||||
|
return self._getCurrentPosition(component)[0]
|
||||||
|
|
||||||
|
def getPlotPosition(self, component):
|
||||||
|
component = str(component)
|
||||||
|
if component in self.compPosition_Map.keys():
|
||||||
|
return self.compPosition_Map[component]
|
||||||
|
elif component in self.compName_Map.keys():
|
||||||
|
return self.compPosition_Map[self.compName_Map[component]]
|
||||||
|
else:
|
||||||
|
errMsg = 'getCompPosition: Unrecognized component {}. Expecting one of {} or {}.'
|
||||||
|
raise ValueError(errMsg.format(component, self.compPosition_Map.keys(), self.compName_Map.keys()))
|
@ -49,13 +49,12 @@ from pylot.core.io.inputs import FilterOptions, PylotParameter
|
|||||||
from pylot.core.pick.utils import getSNR, earllatepicker, getnoisewin, \
|
from pylot.core.pick.utils import getSNR, earllatepicker, getnoisewin, \
|
||||||
getResolutionWindow, getQualityFromUncertainty
|
getResolutionWindow, getQualityFromUncertainty
|
||||||
from pylot.core.pick.compare import Comparison
|
from pylot.core.pick.compare import Comparison
|
||||||
from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS, \
|
from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS
|
||||||
SetChannelComponents
|
|
||||||
from pylot.core.util.utils import prepTimeAxis, full_range, scaleWFData, \
|
from pylot.core.util.utils import prepTimeAxis, full_range, scaleWFData, \
|
||||||
demeanTrace, isSorted, findComboBoxIndex, clims, pick_linestyle_plt, pick_color_plt, \
|
demeanTrace, isSorted, findComboBoxIndex, clims, pick_linestyle_plt, pick_color_plt, \
|
||||||
check4rotated, check4doubled, check4gaps, remove_underscores, find_horizontals, identifyPhase, \
|
check4rotated, check4doubled, check4gaps, remove_underscores, find_horizontals, identifyPhase, \
|
||||||
loopIdentifyPhase, trim_station_components, transformFilteroptions2String, \
|
loopIdentifyPhase, trim_station_components, transformFilteroptions2String, \
|
||||||
identifyPhaseID, real_Bool, pick_color, getAutoFilteroptions
|
identifyPhaseID, real_Bool, pick_color, getAutoFilteroptions, SetChannelComponents
|
||||||
from autoPyLoT import autoPyLoT
|
from autoPyLoT import autoPyLoT
|
||||||
from pylot.core.util.thread import Thread
|
from pylot.core.util.thread import Thread
|
||||||
from pylot.core.util.dataprocessing import Metadata
|
from pylot.core.util.dataprocessing import Metadata
|
||||||
@ -4617,31 +4616,16 @@ class GraphicsTab(PropTab):
|
|||||||
self.main_layout.addWidget(label, 1, 0)
|
self.main_layout.addWidget(label, 1, 0)
|
||||||
self.main_layout.addWidget(self.spinbox_nth_sample, 1, 1)
|
self.main_layout.addWidget(self.spinbox_nth_sample, 1, 1)
|
||||||
|
|
||||||
def add_pg_cb(self):
|
|
||||||
pg = True
|
|
||||||
text = {True: 'Use pyqtgraphic library for plotting',
|
|
||||||
False: 'Cannot use library: pyqtgraphic not found on system'}
|
|
||||||
label = QLabel('PyQt graphic')
|
|
||||||
label.setToolTip(text[bool(pg)])
|
|
||||||
label.setEnabled(bool(pg))
|
|
||||||
self.checkbox_pg = QtGui.QCheckBox()
|
|
||||||
self.checkbox_pg.setEnabled(bool(pg))
|
|
||||||
self.checkbox_pg.setChecked(bool(pg))
|
|
||||||
self.main_layout.addWidget(label, 0, 0)
|
|
||||||
self.main_layout.addWidget(self.checkbox_pg, 0, 1)
|
|
||||||
|
|
||||||
def set_current_style(self):
|
def set_current_style(self):
|
||||||
selected_style = self.style_cb.currentText()
|
selected_style = self.style_cb.currentText()
|
||||||
self.pylot_mainwindow.set_style(selected_style)
|
self.pylot_mainwindow.set_style(selected_style)
|
||||||
|
|
||||||
def getValues(self):
|
def getValues(self):
|
||||||
values = {'nth_sample': self.spinbox_nth_sample.value(),
|
values = {'nth_sample': self.spinbox_nth_sample.value()}
|
||||||
'pyqtgraphic': self.checkbox_pg.isChecked()}
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def resetValues(self, infile=None):
|
def resetValues(self, infile=None):
|
||||||
values = {'nth_sample': self.spinbox_nth_sample.setValue(1),
|
values = {'nth_sample': self.spinbox_nth_sample.setValue(1)}
|
||||||
'pyqtgraphic': self.checkbox_pg.setChecked(True)}
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user