From 1266f08da8eb7b68039be1f143d98699f32b71ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20K=C3=BCperkoch?= Date: Fri, 31 Mar 2017 11:26:42 +0200 Subject: [PATCH] Additional restore button in preferences-dialog box to reset preferences. Gets values from infile (e.g. pylot.in) assumed as default values. --- pylot/core/util/widgets.py | 61 ++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 0e1e0728..8ea341f2 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -817,6 +817,7 @@ class PickDlg(QDialog): self.disconnectMotionEvent() self.cidpress = self.connectPressEvent(self.setPick) + print(self.selectPhase.currentText()) if self.selectPhase.currentText().upper().startswith('P'): self.setIniPickP(gui_event, wfdata, trace_number) elif self.selectPhase.currentText().upper().startswith('S'): @@ -1192,13 +1193,15 @@ class PickDlg(QDialog): class PropertiesDlg(QDialog): - def __init__(self, parent=None): + def __init__(self, parent=None, infile=None): super(PropertiesDlg, self).__init__(parent) + self.infile = infile + + appName = QApplication.applicationName() self.setWindowTitle("{0} Properties".format(appName)) - self.tabWidget = QTabWidget() self.tabWidget.addTab(InputsTab(self), "Inputs") self.tabWidget.addTab(OutputsTab(self), "Outputs") @@ -1207,7 +1210,8 @@ class PropertiesDlg(QDialog): self.tabWidget.addTab(LocalisationTab(self), "Loc Tools") self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Apply | - QDialogButtonBox.Close) + QDialogButtonBox.Close | + QDialogButtonBox.RestoreDefaults) layout = QVBoxLayout() layout.addWidget(self.tabWidget) @@ -1216,8 +1220,11 @@ class PropertiesDlg(QDialog): self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) - self.buttonBox.button(QDialogButtonBox.Apply).clicked.connect( - self.apply) + self.buttonBox.button(QDialogButtonBox.Apply).clicked.connect(self.apply) + self.buttonBox.button(QDialogButtonBox.RestoreDefaults).clicked.connect(self.restore) + + def getinfile(self): + return self.infile def accept(self, *args, **kwargs): self.apply() @@ -1230,6 +1237,14 @@ class PropertiesDlg(QDialog): if values is not None: self.setValues(values) + def restore(self): + for widint in range(self.tabWidget.count()): + curwid = self.tabWidget.widget(widint) + values = curwid.resetValues(self.getinfile()) + if values is not None: + self.setValues(values) + + @staticmethod def setValues(tabValues): settings = QSettings() @@ -1245,16 +1260,19 @@ class PropTab(QWidget): def getValues(self): return None + def resetValues(self, infile=None): + return None class InputsTab(PropTab): - def __init__(self, parent): + def __init__(self, parent, infile=None): super(InputsTab, self).__init__(parent) settings = QSettings() + pylot_user = getpass.getuser() fulluser = settings.value("user/FullName") login = settings.value("user/Login") - fullNameLabel = QLabel("Full name for user '{0}': ".format(login)) + fullNameLabel = QLabel("Full name for user '{0}': ".format(pylot_user)) # get the full name of the actual user self.fullNameEdit = QLineEdit() @@ -1297,9 +1315,24 @@ class InputsTab(PropTab): "data/Structure": self.structureSelect.currentText()} return values + def resetValues(self, infile): + para = AutoPickParameter(infile) + datstruct = para.get('datastructure') + if datstruct == 'SeisComp': + index = 0 + else: + index = 2 + datapath = para.get('datapath') + rootpath = para.get('rootpath') + database = para.get('database') + path = os.path.join(os.path.expanduser('~'), rootpath, datapath, database) + values = {"data/dataRoot": self.dataDirEdit.setText("%s" % path), + "user/FullName": self.fullNameEdit.text(), + "data/Structure": self.structureSelect.setCurrentIndex(index)} + return values class OutputsTab(PropTab): - def __init__(self, parent=None): + def __init__(self, parent=None, infile=None): super(OutputsTab, self).__init__(parent) settings = QSettings() @@ -1323,6 +1356,9 @@ class OutputsTab(PropTab): values = {"output/Format": self.eventOutputComboBox.currentText()} return values + def resetValues(self, infile): + values = {"output/Format": self.eventOutputComboBox.setCurrentIndex(1)} + return values class PhasesTab(PropTab): def __init__(self, parent=None): @@ -1339,7 +1375,7 @@ class GraphicsTab(PropTab): class LocalisationTab(PropTab): - def __init__(self, parent=None): + def __init__(self, parent=None, infile=None): super(LocalisationTab, self).__init__(parent) settings = QSettings() @@ -1409,6 +1445,13 @@ class LocalisationTab(PropTab): "loc/tool": loctool} return values + def resetValues(self, infile): + para = AutoPickParameter(infile) + nllocroot = para.get('nllocroot') + nllocbin = para.get('nllocbin') + loctool = self.locToolComboBox.setCurrentIndex(3) + values = {"nll/rootPath": self.rootedit.setText("%s" % nllocroot), + "nll/binPath": self.binedit.setText("%s" % nllocbin)} class NewEventDlg(QDialog): def __init__(self, parent=None, titleString="Create a new event"):