diff --git a/pylot/RELEASE-VERSION b/pylot/RELEASE-VERSION index a434f915..7509fd8d 100644 --- a/pylot/RELEASE-VERSION +++ b/pylot/RELEASE-VERSION @@ -1 +1 @@ -a2ab-dirty +cae5-dirty diff --git a/pylot/core/io/inputs.py b/pylot/core/io/inputs.py index 7500b2c5..40428633 100644 --- a/pylot/core/io/inputs.py +++ b/pylot/core/io/inputs.py @@ -47,47 +47,12 @@ class AutoPickParameter(object): self.__init_default_paras() self.__init_subsettings() self.__filename = fnin - parFileCont = {} + self._verbosity = verbosity + self._parFileCont = {} # io from parsed arguments alternatively for key, val in kwargs.items(): - parFileCont[key] = val - - if self.__filename is not None: - inputFile = open(self.__filename, 'r') - else: - return - try: - lines = inputFile.readlines() - for line in lines: - parspl = line.split('\t')[:2] - parFileCont[parspl[0].strip()] = parspl[1] - except IndexError as e: - if verbosity > 0: - self._printParameterError(e) - inputFile.seek(0) - lines = inputFile.readlines() - for line in lines: - if not line.startswith(('#', '%', '\n', ' ')): - parspl = line.split('#')[:2] - parFileCont[parspl[1].strip()] = parspl[0].strip() - for key, value in parFileCont.items(): - try: - val = int(value) - except: - try: - val = float(value) - except: - if len(value.split(' ')) > 1: - vallist = value.strip().split(' ') - val = [] - for val0 in vallist: - val0 = float(val0) - val.append(val0) - else: - val = str(value.strip()) - parFileCont[key] = val - self.__parameter = parFileCont - + self._parFileCont[key] = val + self.from_file() if fnout: self.export2File(fnout) @@ -199,6 +164,51 @@ class AutoPickParameter(object): def _printParameterError(errmsg): print('ParameterError:\n non-existent parameter %s' % errmsg) + def reset_defaults(self): + defaults = self.get_defaults() + for param in defaults: + self.setParamKV(param, defaults[param]['value']) + + def from_file(self, fnin=None): + if not fnin: + if self.__filename is not None: + fnin = self.__filename + else: + return + + inputFile = open(fnin, 'r') + try: + lines = inputFile.readlines() + for line in lines: + parspl = line.split('\t')[:2] + self._parFileCont[parspl[0].strip()] = parspl[1] + except IndexError as e: + if self._verbosity > 0: + self._printParameterError(e) + inputFile.seek(0) + lines = inputFile.readlines() + for line in lines: + if not line.startswith(('#', '%', '\n', ' ')): + parspl = line.split('#')[:2] + self._parFileCont[parspl[1].strip()] = parspl[0].strip() + for key, value in self._parFileCont.items(): + try: + val = int(value) + except: + try: + val = float(value) + except: + if len(value.split(' ')) > 1: + vallist = value.strip().split(' ') + val = [] + for val0 in vallist: + val0 = float(val0) + val.append(val0) + else: + val = str(value.strip()) + self._parFileCont[key] = val + self.__parameter = self._parFileCont + def export2File(self, fnout): fid_out = open(fnout, 'w') lines = [] diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 03f82638..ccb0afc0 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -1764,7 +1764,8 @@ class AutoPickParaBox(QtGui.QWidget): QtGui.QWidget.__init__(self, parent) self.ap = ap self.tabs = QtGui.QTabWidget() - self.layout = QtGui.QHBoxLayout() + self.layout = QtGui.QVBoxLayout() + self._init_buttons() self.layout.addWidget(self.tabs) self.boxes = {} self._init_sublayouts() @@ -1778,6 +1779,19 @@ class AutoPickParaBox(QtGui.QWidget): self._main_layout = QtGui.QVBoxLayout() self._advanced_layout = QtGui.QVBoxLayout() self._create_advanced_cb() + + def _init_buttons(self): + self._buttons_layout = QtGui.QHBoxLayout() + self.loadButton = QtGui.QPushButton('&Load settings') + self.saveButton = QtGui.QPushButton('&Save settings') + self.defaultsButton = QtGui.QPushButton('&Defaults') + self._buttons_layout.addWidget(self.loadButton) + self._buttons_layout.addWidget(self.saveButton) + self._buttons_layout.addWidget(self.defaultsButton) + self.layout.addLayout(self._buttons_layout) + self.loadButton.clicked.connect(self.openFile) + self.saveButton.clicked.connect(self.saveFile) + self.defaultsButton.clicked.connect(self.restoreDefaults) def _create_advanced_cb(self): self._advanced_cb = QtGui.QCheckBox('Enable Advanced Settings') @@ -1954,6 +1968,42 @@ class AutoPickParaBox(QtGui.QWidget): value = tuple(value) return value + def openFile(self): + fd = QtGui.QFileDialog() + fname = fd.getOpenFileName(self, 'Browse for settings file.', '*.in') + if fname[0]: + try: + self.ap.from_file(fname[0]) + self.params_to_gui() + except Exception as e: + self._warn('Could not open file {}:\n{}'.format(fname[0], e)) + return + + def saveFile(self): + fd = QtGui.QFileDialog() + fname = fd.getSaveFileName(self, 'Browse for settings file.', '*.in') + if fname[0]: + try: + self.params_from_gui() + self.ap.export2File(fname[0]) + except Exception as e: + self._warn('Could not save file {}:\n{}'.format(fname[0], e)) + return + + def restoreDefaults(self): + try: + self.ap.reset_defaults() + self.params_to_gui() + except Exception as e: + self._warn('Could not restore defaults:\n{}'.format(e)) + return + + def _warn(self, message): + self.qmb = QtGui.QMessageBox(QtGui.QMessageBox.Icon.Warning, + 'Warning', message) + self.qmb.show() + + class ParametersTab(PropTab): def __init__(self, parent=None, infile=None): super(ParametersTab, self).__init__(parent)