class PreferenceDialog(QtWidgets.QDialog):

    def __init__(self, restored, parent=None):
        super().__init__(parent)
        self.ui = Ui_PreferenceDialog()
        self.ui.setupUi(self)
        self.ui.tabWidget.setCurrentIndex(0)

        self.ui.buttonBox.accepted.connect(self.accept)
        self.ui.buttonBox.rejected.connect(self.reject)

        double_valid = QtGui.QDoubleValidator()
        self.ui.ts_gain_lineEdit.setValidator(double_valid)
        self.ui.ts_tm_lineEdit.setValidator(double_valid)

        int_valid = QtGui.QIntValidator(0, 1200)
        self.ui.figure_dpi_lineEdit.setValidator(int_valid)

        self.set_params(restored)

    def set_params(self, params):
        self.ui.detector_comboBox.setCurrentIndex(int(params['detector']))
        self.ui.channel_spinBox.setValue(int(params['channel']))
        self.ui.flowrate_spinBox.setValue(float(params['flowrate']))
        self.ui.linewidth_spinBox.setValue(float(params['linewidth']))
        self.ui.ts_gain_lineEdit.setText(str(params['ts_gain']))
        self.ui.ts_tm_lineEdit.setText(str(params['ts_tm']))
        self.ui.figure_dpi_lineEdit.setText(str(params['figure_dpi']))
        self.ui.sns_style_comboBox.setCurrentIndex(int(params['sns_style']))
        self.ui.sns_context_comboBox.setCurrentIndex(int(params['sns_context']))
        if bool(params['use_seaborn']):
            self.ui.use_seaborn_checkBox.setCheckState(QtCore.Qt.Checked)
            self.ui.seaborn_style_groupBox.setEnabled(True)

    def get_params(self):
        params = {}
        params['detector'] = self.ui.detector_comboBox.currentIndex()
        params['channel'] = self.ui.channel_spinBox.value()
        params['flowrate'] = self.ui.flowrate_spinBox.value()
        params['linewidth'] = self.ui.linewidth_spinBox.value()
        params['ts_gain'] = self.ui.ts_gain_lineEdit.text()
        params['ts_tm'] = self.ui.ts_tm_lineEdit.text()
        params['figure_dpi'] = self.ui.figure_dpi_lineEdit.text()
        params['use_seaborn'] = self.ui.use_seaborn_checkBox.isChecked()
        params['sns_style'] = self.ui.sns_style_comboBox.currentIndex()
        params['sns_context'] = self.ui.sns_context_comboBox.currentIndex()
        return params
    def __init__(self, restored, parent=None):
        super().__init__(parent)
        self.ui = Ui_PreferenceDialog()
        self.ui.setupUi(self)
        self.ui.tabWidget.setCurrentIndex(0)

        self.ui.buttonBox.accepted.connect(self.accept)
        self.ui.buttonBox.rejected.connect(self.reject)

        double_valid = QtGui.QDoubleValidator()
        self.ui.ts_gain_lineEdit.setValidator(double_valid)
        self.ui.ts_tm_lineEdit.setValidator(double_valid)

        int_valid = QtGui.QIntValidator(0, 1200)
        self.ui.figure_dpi_lineEdit.setValidator(int_valid)

        self.set_params(restored)