def updateStyle(self): """Reimplemented from :class:`TaurusBaseWritableWidget`""" TaurusBaseWritableWidget.updateStyle(self) value = self.getValue() if value is None or not self.isTextValid() or not self.isEnabled(): # invalid value color, weight = 'gray', 'normal' else: # check if there are pending operations if self.hasPendingOperations(): color, weight = 'blue', 'bold' else: color, weight = 'black', 'normal' # also check alarms (if applicable) modelObj = self.getModelObj() if modelObj and modelObj.type in [ DataType.Integer, DataType.Float ]: min_, max_ = modelObj.alarms if ((min_ is not None and value < min_) or (max_ is not None and value > max_)): color = 'orange' # apply style style = ('TaurusValueLineEdit {color: %s; font-weight: %s}' % (color, weight)) self.setStyleSheet(style)
def postDetach(self): '''reimplemented from :class:`TaurusBaseWritableWidget`''' TaurusBaseWritableWidget.postDetach(self) Qt.QObject.disconnect(self, Qt.SIGNAL("currentIndexChanged(int)"), self.writeIndexValue) Qt.QObject.disconnect(self, Qt.SIGNAL("applied()"), self.writeValue)
def updateStyle(self): TaurusBaseWritableWidget.updateStyle(self) if self.hasPendingOperations(): self.setStyleSheet( 'QWheelEdit {border: 2px solid; border-radius: 4px; border-color: blue}') else: self.setStyleSheet( 'QWheelEdit {border: 2px solid; border-radius: 4px; border-color: rgba(0,0,255,0)}')
def __init__(self, parent=None, designMode=False): name = self.__class__.__name__ MAXQArrayLineEdit.__init__(self, parent) TaurusBaseWritableWidget.__init__(self, name, designMode=designMode) self.textChanged.connect(self.valueChanged) self.returnPressed.connect(self.writeValue) self.editingFinished.connect(self._onEditingFinished) self.connect(self, Qt.SIGNAL('valueChanged'), self.updatePendingOperations)
def handleEvent(self, src, evt_type, evt_value): if hasattr(evt_value, 'rvalue'): self._my_debug("received from %s: %s" % (src, evt_value.rvalue)) if self.isResetCheckBox(): if self.getValue() and not evt_value.rvalue: self.setValue(False) # else: # self.setChecked(evt_value.w_value) TaurusBaseWritableWidget.handleEvent(self, src, evt_type, evt_value)
def postDetach(self): '''reimplemented from :class:`TaurusBaseWritableWidget`''' TaurusBaseWritableWidget.postDetach(self) try: self.currentIndexChanged.disconnect(self.writeIndexValue) except TypeError: # In new style-signal if a signal is disconnected without # previously was connected it, it raises a TypeError pass
def handleEvent(self, evt_src, evt_type, evt_value): """ Adding the validator from here, also if config event, fix the number of elements displayed """ if evt_type == TaurusEventType.Config: self._fixnumberofelements() self._updateValidator(evt_value) TaurusBaseWritableWidget.handleEvent(self, evt_src, evt_type, evt_value)
def notifyValueChanged(self, *args): self._my_debug("notifyValueChanged(*args=%s) isChecked=%s" % (args, self.isChecked())) if not self.isChecked() and self.isResetCheckBox(): # when it's a reset checkbox, ignore when is unchecked because # it is cause by handleEvent() and the write to the attr must be # avoided. return TaurusBaseWritableWidget.notifyValueChanged(self, *args)
def postDetach(self): '''reimplemented from :class:`TaurusBaseWritableWidget`''' TaurusBaseWritableWidget.postDetach(self) try: self.currentIndexChanged.disconnect(self.writeIndexValue) self.applied.disconnect(self.writeValue) except TypeError: # In new style-signal if a signal is disconnected without # previously was connected it, it raises a TypeError pass
def updateStyle(self): """ Removed validators that only work for scalar numerics """ TaurusBaseWritableWidget.updateStyle(self) color, weight = 'black', 'normal' #default case: the value is in normal range with no pending changes if self.hasPendingOperations( ): #the value is in valid range with pending changes color, weight = 'blue', 'bold' self.setStyleSheet('QLineEdit {color: %s; font-weight: %s}' % (color, weight))
def handleEvent(self, evt_src, evt_type, evt_value): if evt_type == TaurusEventType.Config or not self._configured: if evt_value is not None: obj = self.getModelObj() # set decimal digits self.setDigitCount(int_nb=None, dec_nb=obj.precision) # set min and max values min_, max_ = obj.getRange() if min_ is not None: self.setMinValue(min_.magnitude) if max_ is not None: self.setMaxValue(max_.magnitude) self._configured = True TaurusBaseWritableWidget.handleEvent(self, evt_src, evt_type, evt_value)
def setModel(self, m): '''Reimplemented from :meth:`TaurusBaseWritableWidget.setModel` ''' if isinstance(m, Qt.QAbstractItemModel): self.warning( "Deprecation warning: use setQModel() if you want to set a Qt Item Model. The setModel() method is reserved for Taurus models") return Qt.QComboBox.setModel(self, m) ret = TaurusBaseWritableWidget.setModel(self, m) self.emitValueChanged() return ret
def __init__(self, parent=None, designMode=False): QtGui.QWidget.__init__(self, parent) TaurusBaseWritableWidget.__init__(self, "fisk", taurus_parent=parent, designMode=designMode) self._enableWheelEvent = True self.w_value = None self._setup_ui() # self._localModelName = None self._throttle_timer = QtCore.QTimer() self._throttle_timer.setInterval(200) self._throttle_timer.setSingleShot(True) self.connect(self._throttle_timer, QtCore.SIGNAL("timeout()"), self._writeValue)
def updateStyle(self): TaurusBaseWritableWidget.updateStyle(self) # Show text only if it is not specifically hidden if self._showText: try: self.setText(str(self.getModelObj().getConfig().getLabel())) except: self.setText('----') else: self.setText('') # Update pending operations style if self.hasPendingOperations(): txt = str(self.text()).strip() if len(txt) == 0: self.setText("!") self.setStyleSheet('TaurusValueCheckBox {color: blue;}') else: if str(self.text()) == "!": self.setText(" ") self.setStyleSheet('TaurusValueCheckBox {}') self.update()
def handleEvent(self, evt_src, evt_type, evt_value): # handle the case in which the line edit is not yet initialized if self._last_value is None: try: value = self.getModelObj().read(cache=True) self._updateValidator(value) self.setValue(value.wvalue) except Exception as e: self.info('Failed attempt to initialize value: %r', e) self.setEnabled(evt_type != TaurusEventType.Error) if evt_type in (TaurusEventType.Change, TaurusEventType.Periodic): self._updateValidator(evt_value) TaurusBaseWritableWidget.handleEvent(self, evt_src, evt_type, evt_value) if evt_type == TaurusEventType.Error: self.updateStyle()
def updateStyle(self): self._my_debug("updateStyle()") try: TaurusBaseWritableWidget.updateStyle(self) if self.isResetCheckBox(): return else: # If it is not a resetCheckBox, # proceed like the TaurusValueCheckBox if self.hasPendingOperations(): txt = str(self.text()).strip() if len(txt) == 0: self.setText("!") self.setStyleSheet('LinacValueCheckBox {color: blue;}') else: if str(self.text()) == "!": self.setText(" ") self.setStyleSheet('LinacValueCheckBox {}') self.update() except Exception as e: self.error("Cannot updateStyle: %s" % (e))
def handleEvent(self, evt_src, evt_type, evt_value): if evt_type == TaurusEventType.Config and evt_value is not None: import re # match the format string to "%[width][.precision][f_type]" obj = self.getModelObj() m = re.match(r'%([0-9]+)?(\.([0-9]+))?([df])', obj.format) if m is None: raise ValueError("'%s' format unsupported" % obj.format) width, _, precision, f_type = m.groups() if width is None: width = self.DefaultIntDigitCount + \ self.DefaultDecDigitCount + 1 else: width = int(width) if precision is None: precision = self.DefaultDecDigitCount else: precision = int(precision) dec_nb = precision if dec_nb == 0 or f_type == 'd': int_nb = width else: int_nb = width - dec_nb - 1 # account for decimal sep self.setDigitCount(int_nb=int_nb, dec_nb=dec_nb) try: self.setMinValue(float(obj.min_value)) except: pass try: self.setMaxValue(float(obj.max_value)) except: pass TaurusBaseWritableWidget.handleEvent( self, evt_src, evt_type, evt_value)
def handleEvent(self, evt_src, evt_type, evt_value): if evt_type == TaurusEventType.Config and evt_value is not None: import re # match the format string to "%[width][.precision][f_type]" obj = self.getModelObj() m = re.match(r'%([0-9]+)?(\.([0-9]+))?([df])', obj.format) if m is None: raise ValueError("'%s' format unsupported" % obj.format) width, _, precision, f_type = m.groups() if width is None: width = self.DefaultIntDigitCount + \ self.DefaultDecDigitCount + 1 else: width = int(width) if precision is None: precision = self.DefaultDecDigitCount else: precision = int(precision) dec_nb = precision if dec_nb == 0 or f_type == 'd': int_nb = width else: int_nb = width - dec_nb - 1 # account for decimal sep self.setDigitCount(int_nb=int_nb, dec_nb=dec_nb) try: self.setMinValue(float(obj.min_value)) except: pass try: self.setMaxValue(float(obj.max_value)) except: pass TaurusBaseWritableWidget.handleEvent(self, evt_src, evt_type, evt_value)
def updateStyle(self): TaurusBaseWritableWidget.updateStyle(self) value = self.getValue() if value is None: # invalid value color, weight = 'gray', 'normal' else: # check if there are pending operations if self.hasPendingOperations(): color, weight = 'blue', 'bold' else: color, weight = 'black', 'normal' # also check alarms (if applicable) modelObj = self.getModelObj() if modelObj and modelObj.type in [DataType.Integer, DataType.Float]: min_, max_ = modelObj.alarms if value < min_ or value > max_: color = 'orange' # apply style style = 'TaurusValueLineEdit {color: %s; font-weight: %s}' %\ (color, weight) self.setStyleSheet(style)
def writeValue(self, forceApply=False): self._my_debug("writeValue(forceApply=%s)" % (forceApply)) # TaurusValueCheckBox.writeValue(self, forceApply) TaurusBaseWritableWidget.writeValue(self, forceApply)
def getQtDesignerPluginInfo(cls): ret = TaurusBaseWritableWidget.getQtDesignerPluginInfo() ret['module'] = 'taurus.qt.qtgui.input' ret['icon'] = "designer:lineedit.png" return ret
def handleEvent(self, evt_src, evt_type, evt_value): if evt_type in (TaurusEventType.Change, TaurusEventType.Periodic): self._updateValidator(evt_value) TaurusBaseWritableWidget.handleEvent( self, evt_src, evt_type, evt_value)
def setModel(self, model): TaurusBaseWritableWidget.setModel(self, model) self.notifyValueChanged()
def preAttach(self): '''reimplemented from :class:`TaurusBaseWritableWidget`''' TaurusBaseWritableWidget.preAttach(self) self.currentIndexChanged.connect(self.writeIndexValue) self.applied.connect(self.writeValue)
def setModel(self, model): """ Set model and fix number of elements displayed. """ TaurusBaseWritableWidget.setModel(self, model) self._fixnumberofelements()
def getQtDesignerPluginInfo(cls): ret = TaurusBaseWritableWidget.getQtDesignerPluginInfo() ret['module'] = 'linacvaluecheckbox' ret['group'] = 'Taurus Linac Widgets' ret['icon'] = ":/designer/checkbox.png" return ret
def setModel(self, model): TaurusBaseWritableWidget.setModel(self, model) self.valueChanged()
def getQtDesignerPluginInfo(cls): '''reimplemented from :class:`TaurusBaseWritableWidget`''' ret = TaurusBaseWritableWidget.getQtDesignerPluginInfo() ret['module'] = 'taurus.qt.qtgui.input' ret['icon'] = "designer:combobox.png" return ret
def preAttach(self): '''reimplemented from :class:`TaurusBaseWritableWidget`''' TaurusBaseWritableWidget.preAttach(self) self.currentIndexChanged.connect(self.writeIndexValue)
def getQtDesignerPluginInfo(cls): ret = TaurusBaseWritableWidget.getQtDesignerPluginInfo() ret['module'] = 'taurus.qt.qtgui.input' ret['icon'] = ":/designer/lineedit.png" return ret
def emitValueChanged(self, *args): self._my_debug("emitValueChanged(args=%s)" % (str(args))) TaurusBaseWritableWidget.emitValueChanged(self, *args)