Exemplo n.º 1
0
    def AddCfg(self):
        logging.info('Adding new q330 configuration')

        dlg, dlgUI, dlgUIHlpr = self.setup_edit_dialog(EditDlgHelper.ADD_MODE, WrapperCfg.new_dict())
        # need to keep dlgUIHlpr in scope for GUI callbacks
        if dlg.exec() == QtWidgets.QDialog.Accepted:
            try:
                self.cdm.AddCfg(dlgUI.new_cfg)
                new_tag_no = dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_TAGNO]
                ndx = self.cfg.index_from_tagno(new_tag_no)
                if ndx is not None:
                    self.cur_row = ndx
                    self.main_win.cfgListTV.selectRow(self.cur_row)

                logging.debug('New PyCal Q330 configuration saved.')
            except Exception as e:
                logging.error('Error saving new PyCal Q330 config record. ' + str(e))
                QtWidgets.QMessageBox().critical(self.app_win, 'PyCal ERROR', str(e), QtWidgets.QMessageBox().Close, QtWidgets.QMessageBox().Close)
        else:
            logging.info('Add new configuration cancelled by user.')

        # self.cur_Row = -1
        # self.update_details(self.cur_row)

        self.main_win.cfgListTV.resizeColumnsToContents()
Exemplo n.º 2
0
    def validate(self):
        valid = True

        # check NET
        if WrapperCfg.is_valid_wcfg_key(WrapperCfg.WRAPPER_KEY_NET, self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_NET]):
            self.dlgUI.netLE.setStyleSheet("QLineEdit{color:rgb(0, 102, 0);}")
        else:
            self.dlgUI.netLE.setStyleSheet("QLineEdit{color:rgb(179, 0, 0);}")
            valid = False

        # check STA
        if WrapperCfg.is_valid_wcfg_key(WrapperCfg.WRAPPER_KEY_STA, self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_STA]):
            self.dlgUI.staLE.setStyleSheet("QLineEdit{color:rgb(0, 102, 0);}")
        else:
            self.dlgUI.staLE.setStyleSheet("QLineEdit{color:rgb(179, 0, 0);}")
            valid = False

        # check IP
        if WrapperCfg.is_valid_wcfg_key(WrapperCfg.WRAPPER_KEY_IP, self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_IP]):
            self.dlgUI.ipLE.setStyleSheet("QLineEdit{color:rgb(0, 102, 0);}")
        else:
            self.dlgUI.ipLE.setStyleSheet("QLineEdit{color:rgb(179, 0, 0);}")
            valid = False

        # check TAGNO
        if WrapperCfg.is_valid_wcfg_key(WrapperCfg.WRAPPER_KEY_TAGNO, self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_TAGNO]):
            self.dlgUI.tagnoLE.setStyleSheet("QLineEdit{color:rgb(0, 102, 0);}")
        else:
            self.dlgUI.tagnoLE.setStyleSheet("QLineEdit{color:rgb(179, 0, 0);}")
            valid = False

        # check SN
        if WrapperCfg.is_valid_wcfg_key(WrapperCfg.WRAPPER_KEY_SN, self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_SN]):
            self.dlgUI.snLE.setStyleSheet("QLineEdit{color:rgb(0, 102, 0);}")
        else:
            self.dlgUI.snLE.setStyleSheet("QLineEdit{color:rgb(179, 0, 0);}")
            valid = False

        # check DATAPORT
        if WrapperCfg.is_valid_wcfg_key(WrapperCfg.WRAPPER_KEY_DATAPORT, self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_DATAPORT]):
            self.dlgUI.dpLE.setStyleSheet("QLineEdit{color:rgb(0, 102, 0);}")
        else:
            self.dlgUI.dpLE.setStyleSheet("QLineEdit{color:rgb(179, 0, 0);}")
            valid = False

        # check DP AUTH
        if WrapperCfg.is_valid_wcfg_key(WrapperCfg.WRAPPER_KEY_DP1_AUTH, self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_DP1_AUTH]):
            self.dlgUI.dpauthLE.setStyleSheet("QLineEdit{color:rgb(0, 102, 0);}")
        else:
            self.dlgUI.dpauthLE.setStyleSheet("QLineEdit{color:rgb(179, 0, 0);}")
            valid = False

        # check SENSOR A
        if self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_SENS_COMPNAME_A] in [x[0] for x in self.sensorlist]:
            pal = self.dlgUI.sensACB.palette()
            pal.setColor(QtGui.QPalette.Text, QtGui.QColor(0, 102, 0))
            self.dlgUI.sensACB.setPalette(pal)
        else:
            pal = self.dlgUI.sensACB.palette()
            pal.setColor(QtGui.QPalette.Text, QtGui.QColor(179, 0, 0))
            self.dlgUI.sensACB.setPalette(pal)
            valid = False

        # check SENSOR A CAL MON PORT
        if WrapperCfg.is_valid_wcfg_key(WrapperCfg.WRAPPER_KEY_MONPORT_A, self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_MONPORT_A]) or \
            ((self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_SENS_COMPNAME_A] == WrapperCfg.WRAPPER_KEY_NONE) and
             (self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_MONPORT_A] == WrapperCfg.WRAPPER_KEY_NONE)):
            self.dlgUI.sensAMonPortLE.setStyleSheet("QLineEdit{color:rgb(0, 102, 0);}")
        else:
            self.dlgUI.sensAMonPortLE.setStyleSheet("QLineEdit{color:rgb(179, 0, 0);}")
            valid = False

        # check SENSOR A LOCATION
        if WrapperCfg.is_valid_wcfg_key(WrapperCfg.WRAPPER_KEY_LOCATION_A, self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_LOCATION_A]) or \
            ((self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_SENS_COMPNAME_A] == WrapperCfg.WRAPPER_KEY_NONE) and
             (self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_LOCATION_A] == WrapperCfg.WRAPPER_KEY_NONE)):
            self.dlgUI.sensALocLE.setStyleSheet("QLineEdit{color:rgb(0, 102, 0);}")
        else:
            self.dlgUI.sensALocLE.setStyleSheet("QLineEdit{color:rgb(179, 0, 0);}")
            valid = False

        # check SENSOR A Prim Channels
        if WrapperCfg.is_valid_wcfg_key(WrapperCfg.WRAPPER_KEY_CHANNELS_A, self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_CHANNELS_A]) or \
            ((self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_SENS_COMPNAME_A] == WrapperCfg.WRAPPER_KEY_NONE) and
             (self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_CHANNELS_A] == WrapperCfg.WRAPPER_KEY_NONE)):
            self.dlgUI.sensAPriChnsLE.setStyleSheet("QLineEdit{color:rgb(0, 102, 0);}")
        else:
            self.dlgUI.sensAPriChnsLE.setStyleSheet("QLineEdit{color:rgb(179, 0, 0);}")
            valid = False

        # check SENSOR B
        if self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_SENS_COMPNAME_B] in [x[0] for x in self.sensorlist]:
            pal = self.dlgUI.sensBCB.palette()
            pal.setColor(QtGui.QPalette.Text, QtGui.QColor(0, 102, 0))
            self.dlgUI.sensBCB.setPalette(pal)
        else:
            pal = self.dlgUI.sensBCB.palette()
            pal.setColor(QtGui.QPalette.Text, QtGui.QColor(179, 0, 0))
            self.dlgUI.sensBCB.setPalette(pal)
            # self.dlgUI.sensBCB.setStyleSheet("QComboBox{color:rgb(179, 0, 0);}")
            valid = False

        # check SENSOR B CAL MON PORT
        if WrapperCfg.is_valid_wcfg_key(WrapperCfg.WRAPPER_KEY_MONPORT_B, self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_MONPORT_B]) or \
            ((self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_SENS_COMPNAME_B] == WrapperCfg.WRAPPER_KEY_NONE) and
             (self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_MONPORT_B] == WrapperCfg.WRAPPER_KEY_NONE)):
            self.dlgUI.sensBMonPortLE.setStyleSheet("QLineEdit{color:rgb(0, 102, 0);}")
        else:
            self.dlgUI.sensBMonPortLE.setStyleSheet("QLineEdit{color:rgb(179, 0, 0);}")
            valid = False

        # check SENSOR B LOCATION
        if WrapperCfg.is_valid_wcfg_key(WrapperCfg.WRAPPER_KEY_LOCATION_B,
                                        self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_LOCATION_B]) or \
            ((self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_SENS_COMPNAME_B] == WrapperCfg.WRAPPER_KEY_NONE) and
             (self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_LOCATION_B] == WrapperCfg.WRAPPER_KEY_NONE)):
            self.dlgUI.sensBLocLE.setStyleSheet("QLineEdit{color:rgb(0, 102, 0);}")
        else:
            self.dlgUI.sensBLocLE.setStyleSheet("QLineEdit{color:rgb(179, 0, 0);}")
            valid = False

        # check SENSOR B Prim Channels
        if WrapperCfg.is_valid_wcfg_key(WrapperCfg.WRAPPER_KEY_CHANNELS_B,
                                        self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_CHANNELS_B]) or \
            ((self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_SENS_COMPNAME_B] == WrapperCfg.WRAPPER_KEY_NONE) and
             (self.dlgUI.new_cfg[WrapperCfg.WRAPPER_KEY_CHANNELS_B] == WrapperCfg.WRAPPER_KEY_NONE)):
            self.dlgUI.sensBPriChnsLE.setStyleSheet("QLineEdit{color:rgb(0, 102, 0);}")
        else:
            self.dlgUI.sensBPriChnsLE.setStyleSheet("QLineEdit{color:rgb(179, 0, 0);}")
            valid = False

        self.dlgUI.resetBtn.setEnabled(self.is_dirty())
        self.dlgUI.saveBtn.setEnabled(valid and self.is_dirty())