[changed] major change in QSettings behavior when saving channel order (alternative naming (ZNE -> 123)), RESET OF QSETTINGS MIGHT BE NECESSARY (PyLoT.py --reset_qsettings)
This commit is contained in:
parent
1a20d7fbcb
commit
9486d7aced
2
PyLoT.py
2
PyLoT.py
@ -196,8 +196,6 @@ class MainWindow(QMainWindow):
|
||||
dirname = QFileDialog().getExistingDirectory(
|
||||
caption='Choose data root ...')
|
||||
settings.setValue("data/dataRoot", dirname)
|
||||
if settings.value('compclass', None) is None:
|
||||
settings.setValue('compclass', SetChannelComponents())
|
||||
if settings.value('useGuiFilter') is None:
|
||||
settings.setValue('useGuiFilter', False)
|
||||
if settings.value('output/Format', None) is None:
|
||||
|
@ -1182,11 +1182,6 @@ def station_id_remove_channel(station_id):
|
||||
station_id = station_id.rpartition('.')[0]
|
||||
return station_id
|
||||
|
||||
if __name__ == "__main__":
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
||||
|
||||
class SetChannelComponents(object):
|
||||
def __init__(self):
|
||||
@ -1206,15 +1201,16 @@ class SetChannelComponents(object):
|
||||
errMsg = 'getCurrentPosition: Could not find former position of component {}.'.format(component)
|
||||
raise ValueError(errMsg)
|
||||
|
||||
def _switch(self, component, component_alter):
|
||||
def _switch(self, component, component_alter, verbosity=0):
|
||||
# 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))
|
||||
if verbosity > 0:
|
||||
print('switch: Automatically switched component {} to {}'.format(old_alter_comp, old_comp))
|
||||
|
||||
def setCompPosition(self, component_alter, component, switch=True):
|
||||
def setCompPosition(self, component_alter, component, switch=True, verbosity=1):
|
||||
component_alter = str(component_alter)
|
||||
if not component_alter in self.compName_Map.keys():
|
||||
errMsg = 'setCompPosition: Unrecognized alternative component {}. Expecting one of {}.'
|
||||
@ -1222,9 +1218,10 @@ class SetChannelComponents(object):
|
||||
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 verbosity > 0:
|
||||
print('setCompPosition: set component {} to {}'.format(component_alter, component))
|
||||
if switch:
|
||||
self._switch(component, component_alter)
|
||||
self._switch(component, component_alter, verbosity)
|
||||
self.compName_Map[component_alter] = component
|
||||
|
||||
def getCompPosition(self, component):
|
||||
@ -1239,3 +1236,23 @@ class SetChannelComponents(object):
|
||||
else:
|
||||
errMsg = 'getCompPosition: Unrecognized component {}. Expecting one of {} or {}.'
|
||||
raise ValueError(errMsg.format(component, self.compPosition_Map.keys(), self.compName_Map.keys()))
|
||||
|
||||
@staticmethod
|
||||
def from_qsettings(settings):
|
||||
scc = SetChannelComponents()
|
||||
for value in ['Z', 'N', 'E']:
|
||||
key = settings.value(value, None)
|
||||
if not key:
|
||||
print('Could not get channel component map from QSettings. Writing default channel order to QSettings.')
|
||||
scc.setDefaultCompPosition()
|
||||
for value in ['Z', 'N', 'E']:
|
||||
settings.setValue(value, scc.getCompPosition(value))
|
||||
return scc
|
||||
scc.setCompPosition(key, value, verbosity=0)
|
||||
return scc
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
@ -803,10 +803,7 @@ class WaveformWidgetPG(QtGui.QWidget):
|
||||
nmax = 0
|
||||
|
||||
settings = QSettings()
|
||||
compclass = settings.value('compclass')
|
||||
if not type(compclass) == SetChannelComponents:
|
||||
print('Warning: No settings for channel components found. Using default')
|
||||
compclass = SetChannelComponents()
|
||||
compclass = SetChannelComponents.from_qsettings(settings)
|
||||
|
||||
if not component == '*':
|
||||
alter_comp = compclass.getCompPosition(component)
|
||||
@ -1303,10 +1300,7 @@ class PylotCanvas(FigureCanvas):
|
||||
nmax = 0
|
||||
|
||||
settings = QSettings()
|
||||
compclass = settings.value('compclass')
|
||||
if not compclass:
|
||||
print('Warning: No settings for channel components found. Using default')
|
||||
compclass = SetChannelComponents()
|
||||
compclass = SetChannelComponents.from_qsettings(settings)
|
||||
|
||||
if not component == '*':
|
||||
alter_comp = compclass.getCompPosition(component)
|
||||
@ -2951,7 +2945,7 @@ class PickDlg(QDialog):
|
||||
def getChannelSettingsP(channel):
|
||||
settings = QSettings()
|
||||
rval = get_Bool(settings.value('p_channel_{}'.format(channel)))
|
||||
compclass = settings.value('compclass')
|
||||
compclass = SetChannelComponents.from_qsettings(settings)
|
||||
components = ['Z']
|
||||
for component in components[:]:
|
||||
components.append(compclass.getCompPosition(component))
|
||||
@ -2966,7 +2960,7 @@ class PickDlg(QDialog):
|
||||
def getChannelSettingsS(channel):
|
||||
settings = QSettings()
|
||||
rval = get_Bool(settings.value('s_channel_{}'.format(channel)))
|
||||
compclass = settings.value('compclass')
|
||||
compclass = SetChannelComponents.from_qsettings(settings)
|
||||
components = ['N', 'E']
|
||||
for component in components[:]:
|
||||
components.append(compclass.getCompPosition(component))
|
||||
@ -4549,23 +4543,13 @@ class PropertiesDlg(QDialog):
|
||||
@staticmethod
|
||||
def setValues(tabValues):
|
||||
settings = QSettings()
|
||||
compclass = settings.value('compclass')
|
||||
if not compclass:
|
||||
print('Warning: No settings for channel components found. Using default')
|
||||
compclass = SetChannelComponents()
|
||||
compclass = SetChannelComponents.from_qsettings(settings)
|
||||
|
||||
for setting, value in tabValues.items():
|
||||
settings.setValue(setting, value)
|
||||
if value is not None:
|
||||
if setting.startswith('Channel Z'):
|
||||
component = 'Z'
|
||||
compclass.setCompPosition(value, component, False)
|
||||
elif setting.startswith('Channel E'):
|
||||
component = 'E'
|
||||
compclass.setCompPosition(value, component, False)
|
||||
elif setting.startswith('Channel N'):
|
||||
component = 'N'
|
||||
compclass.setCompPosition(value, component, False)
|
||||
if setting in ['Z', 'N', 'E']:
|
||||
compclass.setCompPosition(value, setting, False)
|
||||
|
||||
settings.sync()
|
||||
|
||||
@ -4884,10 +4868,7 @@ class ChannelOrderTab(PropTab):
|
||||
|
||||
self.dirty = False
|
||||
settings = QSettings()
|
||||
compclass = settings.value('compclass')
|
||||
if not compclass:
|
||||
print('Warning: No settings for channel components found. Using default')
|
||||
compclass = SetChannelComponents()
|
||||
compclass = SetChannelComponents.from_qsettings(settings)
|
||||
|
||||
ChannelOrderLabelZ = QLabel("Channel Z [up/down, default=3]")
|
||||
ChannelOrderLabelN = QLabel("Channel N [north/south, default=1]")
|
||||
@ -4953,18 +4934,18 @@ class ChannelOrderTab(PropTab):
|
||||
channelOrderEdits[key].setText('')
|
||||
|
||||
def getValues(self):
|
||||
values = {"Channel Z [up/down, default=3]": int(self.ChannelOrderZEdit.text()),
|
||||
"Channel N [north/south, default=1]": int(self.ChannelOrderNEdit.text()),
|
||||
"Channel E [east/west, default=2]": int(self.ChannelOrderEEdit.text())}
|
||||
values = {"Z": int(self.ChannelOrderZEdit.text()),
|
||||
"N": int(self.ChannelOrderNEdit.text()),
|
||||
"E": int(self.ChannelOrderEEdit.text())}
|
||||
return values
|
||||
|
||||
def resetValues(self, infile=None):
|
||||
Zdefault = 3
|
||||
Ndefault = 1
|
||||
Edefault = 2
|
||||
values = {"Channel Z [up/down, default=3]": self.ChannelOrderZEdit.setText("%d" % Zdefault),
|
||||
"Channel N [north/south, default=1]": self.ChannelOrderNEdit.setText("%d" % Ndefault),
|
||||
"Channel E [east/west, default=2]": self.ChannelOrderEEdit.setText("%d" % Edefault)}
|
||||
values = {"Z": self.ChannelOrderZEdit.setText("%d" % Zdefault),
|
||||
"N": self.ChannelOrderNEdit.setText("%d" % Ndefault),
|
||||
"E": self.ChannelOrderEEdit.setText("%d" % Edefault)}
|
||||
return values
|
||||
|
||||
# MP MP: No idea why this function exists!?
|
||||
|
Loading…
Reference in New Issue
Block a user