[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(
|
dirname = QFileDialog().getExistingDirectory(
|
||||||
caption='Choose data root ...')
|
caption='Choose data root ...')
|
||||||
settings.setValue("data/dataRoot", dirname)
|
settings.setValue("data/dataRoot", dirname)
|
||||||
if settings.value('compclass', None) is None:
|
|
||||||
settings.setValue('compclass', SetChannelComponents())
|
|
||||||
if settings.value('useGuiFilter') is None:
|
if settings.value('useGuiFilter') is None:
|
||||||
settings.setValue('useGuiFilter', False)
|
settings.setValue('useGuiFilter', False)
|
||||||
if settings.value('output/Format', None) is None:
|
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]
|
station_id = station_id.rpartition('.')[0]
|
||||||
return station_id
|
return station_id
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
import doctest
|
|
||||||
|
|
||||||
doctest.testmod()
|
|
||||||
|
|
||||||
|
|
||||||
class SetChannelComponents(object):
|
class SetChannelComponents(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -1206,15 +1201,16 @@ class SetChannelComponents(object):
|
|||||||
errMsg = 'getCurrentPosition: Could not find former position of component {}.'.format(component)
|
errMsg = 'getCurrentPosition: Could not find former position of component {}.'.format(component)
|
||||||
raise ValueError(errMsg)
|
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
|
# Without switching, multiple definitions of the same alter_comp are possible
|
||||||
old_alter_comp, _ = self._getCurrentPosition(component)
|
old_alter_comp, _ = self._getCurrentPosition(component)
|
||||||
old_comp = self.compName_Map[component_alter]
|
old_comp = self.compName_Map[component_alter]
|
||||||
if not old_alter_comp == component_alter and not old_comp == component:
|
if not old_alter_comp == component_alter and not old_comp == component:
|
||||||
self.compName_Map[old_alter_comp] = old_comp
|
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)
|
component_alter = str(component_alter)
|
||||||
if not component_alter in self.compName_Map.keys():
|
if not component_alter in self.compName_Map.keys():
|
||||||
errMsg = 'setCompPosition: Unrecognized alternative component {}. Expecting one of {}.'
|
errMsg = 'setCompPosition: Unrecognized alternative component {}. Expecting one of {}.'
|
||||||
@ -1222,9 +1218,10 @@ class SetChannelComponents(object):
|
|||||||
if not component in self.compPosition_Map.keys():
|
if not component in self.compPosition_Map.keys():
|
||||||
errMsg = 'setCompPosition: Unrecognized target component {}. Expecting one of {}.'
|
errMsg = 'setCompPosition: Unrecognized target component {}. Expecting one of {}.'
|
||||||
raise ValueError(errMsg.format(component, self.compPosition_Map.keys()))
|
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:
|
if switch:
|
||||||
self._switch(component, component_alter)
|
self._switch(component, component_alter, verbosity)
|
||||||
self.compName_Map[component_alter] = component
|
self.compName_Map[component_alter] = component
|
||||||
|
|
||||||
def getCompPosition(self, component):
|
def getCompPosition(self, component):
|
||||||
@ -1239,3 +1236,23 @@ class SetChannelComponents(object):
|
|||||||
else:
|
else:
|
||||||
errMsg = 'getCompPosition: Unrecognized component {}. Expecting one of {} or {}.'
|
errMsg = 'getCompPosition: Unrecognized component {}. Expecting one of {} or {}.'
|
||||||
raise ValueError(errMsg.format(component, self.compPosition_Map.keys(), self.compName_Map.keys()))
|
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
|
nmax = 0
|
||||||
|
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
compclass = settings.value('compclass')
|
compclass = SetChannelComponents.from_qsettings(settings)
|
||||||
if not type(compclass) == SetChannelComponents:
|
|
||||||
print('Warning: No settings for channel components found. Using default')
|
|
||||||
compclass = SetChannelComponents()
|
|
||||||
|
|
||||||
if not component == '*':
|
if not component == '*':
|
||||||
alter_comp = compclass.getCompPosition(component)
|
alter_comp = compclass.getCompPosition(component)
|
||||||
@ -1303,10 +1300,7 @@ class PylotCanvas(FigureCanvas):
|
|||||||
nmax = 0
|
nmax = 0
|
||||||
|
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
compclass = settings.value('compclass')
|
compclass = SetChannelComponents.from_qsettings(settings)
|
||||||
if not compclass:
|
|
||||||
print('Warning: No settings for channel components found. Using default')
|
|
||||||
compclass = SetChannelComponents()
|
|
||||||
|
|
||||||
if not component == '*':
|
if not component == '*':
|
||||||
alter_comp = compclass.getCompPosition(component)
|
alter_comp = compclass.getCompPosition(component)
|
||||||
@ -2951,7 +2945,7 @@ class PickDlg(QDialog):
|
|||||||
def getChannelSettingsP(channel):
|
def getChannelSettingsP(channel):
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
rval = get_Bool(settings.value('p_channel_{}'.format(channel)))
|
rval = get_Bool(settings.value('p_channel_{}'.format(channel)))
|
||||||
compclass = settings.value('compclass')
|
compclass = SetChannelComponents.from_qsettings(settings)
|
||||||
components = ['Z']
|
components = ['Z']
|
||||||
for component in components[:]:
|
for component in components[:]:
|
||||||
components.append(compclass.getCompPosition(component))
|
components.append(compclass.getCompPosition(component))
|
||||||
@ -2966,7 +2960,7 @@ class PickDlg(QDialog):
|
|||||||
def getChannelSettingsS(channel):
|
def getChannelSettingsS(channel):
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
rval = get_Bool(settings.value('s_channel_{}'.format(channel)))
|
rval = get_Bool(settings.value('s_channel_{}'.format(channel)))
|
||||||
compclass = settings.value('compclass')
|
compclass = SetChannelComponents.from_qsettings(settings)
|
||||||
components = ['N', 'E']
|
components = ['N', 'E']
|
||||||
for component in components[:]:
|
for component in components[:]:
|
||||||
components.append(compclass.getCompPosition(component))
|
components.append(compclass.getCompPosition(component))
|
||||||
@ -4549,23 +4543,13 @@ class PropertiesDlg(QDialog):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def setValues(tabValues):
|
def setValues(tabValues):
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
compclass = settings.value('compclass')
|
compclass = SetChannelComponents.from_qsettings(settings)
|
||||||
if not compclass:
|
|
||||||
print('Warning: No settings for channel components found. Using default')
|
|
||||||
compclass = SetChannelComponents()
|
|
||||||
|
|
||||||
for setting, value in tabValues.items():
|
for setting, value in tabValues.items():
|
||||||
settings.setValue(setting, value)
|
settings.setValue(setting, value)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
if setting.startswith('Channel Z'):
|
if setting in ['Z', 'N', 'E']:
|
||||||
component = 'Z'
|
compclass.setCompPosition(value, setting, False)
|
||||||
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)
|
|
||||||
|
|
||||||
settings.sync()
|
settings.sync()
|
||||||
|
|
||||||
@ -4884,10 +4868,7 @@ class ChannelOrderTab(PropTab):
|
|||||||
|
|
||||||
self.dirty = False
|
self.dirty = False
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
compclass = settings.value('compclass')
|
compclass = SetChannelComponents.from_qsettings(settings)
|
||||||
if not compclass:
|
|
||||||
print('Warning: No settings for channel components found. Using default')
|
|
||||||
compclass = SetChannelComponents()
|
|
||||||
|
|
||||||
ChannelOrderLabelZ = QLabel("Channel Z [up/down, default=3]")
|
ChannelOrderLabelZ = QLabel("Channel Z [up/down, default=3]")
|
||||||
ChannelOrderLabelN = QLabel("Channel N [north/south, default=1]")
|
ChannelOrderLabelN = QLabel("Channel N [north/south, default=1]")
|
||||||
@ -4953,18 +4934,18 @@ class ChannelOrderTab(PropTab):
|
|||||||
channelOrderEdits[key].setText('')
|
channelOrderEdits[key].setText('')
|
||||||
|
|
||||||
def getValues(self):
|
def getValues(self):
|
||||||
values = {"Channel Z [up/down, default=3]": int(self.ChannelOrderZEdit.text()),
|
values = {"Z": int(self.ChannelOrderZEdit.text()),
|
||||||
"Channel N [north/south, default=1]": int(self.ChannelOrderNEdit.text()),
|
"N": int(self.ChannelOrderNEdit.text()),
|
||||||
"Channel E [east/west, default=2]": int(self.ChannelOrderEEdit.text())}
|
"E": int(self.ChannelOrderEEdit.text())}
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def resetValues(self, infile=None):
|
def resetValues(self, infile=None):
|
||||||
Zdefault = 3
|
Zdefault = 3
|
||||||
Ndefault = 1
|
Ndefault = 1
|
||||||
Edefault = 2
|
Edefault = 2
|
||||||
values = {"Channel Z [up/down, default=3]": self.ChannelOrderZEdit.setText("%d" % Zdefault),
|
values = {"Z": self.ChannelOrderZEdit.setText("%d" % Zdefault),
|
||||||
"Channel N [north/south, default=1]": self.ChannelOrderNEdit.setText("%d" % Ndefault),
|
"N": self.ChannelOrderNEdit.setText("%d" % Ndefault),
|
||||||
"Channel E [east/west, default=2]": self.ChannelOrderEEdit.setText("%d" % Edefault)}
|
"E": self.ChannelOrderEEdit.setText("%d" % Edefault)}
|
||||||
return values
|
return values
|
||||||
|
|
||||||
# MP MP: No idea why this function exists!?
|
# MP MP: No idea why this function exists!?
|
||||||
|
Loading…
Reference in New Issue
Block a user