Exemple #1
0
    def setReadOnly(self, ro):
        pal = QtGui.QPalette()
        if ro:
            pal.setColor(QtGui.QPalette.Base, QtGui.QColor('lightgrey'))
        self.setPalette(pal)

        super(NotesTextEdit, self).setReadOnly(ro)
    def __init__(self, **kwargs):
        super(DefaultParameterBinding, self).__init__(**kwargs)

        log.info("DefaultParameterBinding: target=%s", self.target)

        if isinstance(self.target, QtWidgets.QWidget):
            self._original_palette = QtGui.QPalette(self.target.palette())
        else:
            self._original_palette = None
            log.info("DefaultParameterBinding: non QWidget target %s", self.target)
    def _get_palette_old(self, rf):
        pal = QtGui.QPalette(self._original_palette)

        try:
            result = rf.result()
            if isinstance(result, bm.SetResult) and not result:
                raise RuntimeError()
        except Exception:
            pal.setColor(QtGui.QPalette.Base, QtGui.QColor('red'))
            log.debug("_get_palette: Exception from result future; setting red background color")
            return pal

        if (self.write_mode == util.COMBINED
                and self.device.has_hw
                and self.device.has_cfg
                and self.profile is not None
                and self.get_write_profile().should_be_stored()):
            try:
                log.debug("_get_palette: comparing hardware and config")
                f_cfg = self.device.cfg.get_parameter(self.write_address)
                f_hw  = self.device.hw.get_parameter(self.read_address)

                if not f_cfg.done():
                    log.debug("_get_palette: adding update callback to config future")
                    f_cfg.add_done_callback(self._update_wrapper)

                if not f_hw.done():
                    log.debug("_get_palette: adding update callback to hardware future")
                    f_hw.add_done_callback(self._update_wrapper)

                if f_cfg.done() and f_hw.done():
                    cfg_value = int(f_cfg)
                    hw_value  = int(f_hw)
                    log.debug("_get_palette: both cfg and hw futures are done; ra=%d, wa=%d, cfg_value=%d, hw_value=%d",
                            self.read_address, self.write_address, cfg_value, hw_value)

                    if cfg_value != hw_value:
                        log.debug("_get_palette: ra=%d, wa=%d, cfg and hw differ; returning orange",
                                self.read_address, self.write_address)
                        pal.setColor(QtGui.QPalette.Base, QtGui.QColor('orange'))

            except (future.IncompleteFuture, KeyError,
                    util.SocketError, util.Disconnected):
                log.exception("_get_palette")

        else:
            log.debug("_get_palette: hw vs cfg condition failed; returning original palette")

        return pal
    def _get_palette(self, rf):
        pal = QtGui.QPalette(self._original_palette)

        try:
            result = rf.result()
            if isinstance(result, bm.SetResult) and not result:
                raise RuntimeError()
        except Exception:
            pal.setColor(QtGui.QPalette.Base, QtGui.QColor('red'))
            log.debug("_get_palette: Exception from result future; setting red background color")
            return future.Future().set_result(pal)

        ret = future.Future()

        if (self.write_mode == util.COMBINED
                and self.device.has_hw
                and self.device.has_cfg
                and self.profile is not None
                and self.get_write_profile().should_be_stored()):
            try:
                f_cfg    = self.device.cfg.get_parameter(self.write_address)
                f_hw     = self.device.hw.get_parameter(self.read_address)
                f_params = self.device.get_config_parameters()

                def all_done(_):
                    has_param = any(pp.address in (self.write_address, self.read_address) for pp in f_params.result())
                    if has_param:
                        cfg_value = int(f_cfg)
                        hw_value  = int(f_hw)

                        if cfg_value != hw_value:
                            log.debug("_get_palette: ra=%d, wa=%d, cfg and hw differ; returning orange",
                                    self.read_address, self.write_address)
                            pal.setColor(QtGui.QPalette.Base, QtGui.QColor('orange'))

                    ret.set_result(pal)

                future.all_done(f_cfg, f_hw, f_params).add_done_callback(all_done)
                return ret

            except (future.IncompleteFuture, KeyError,
                    util.SocketError, util.Disconnected):
                pass

        return ret.set_result(pal)