def getSelectionMark(self,picture=None,w=10,h=10): if picture is None: if self.SelectionMark: SelectionMark = self.SelectionMark() else: SelectionMark = Qt.QGraphicsEllipseItem() color = Qt.QColor(self.selectionColor()) color.setAlphaF(.10) SelectionMark.setBrush(color) pen = Qt.QPen(Qt.Qt.CustomDashLine) pen.setWidth(4) pen.setColor(Qt.QColor(self.selectionColor())) SelectionMark.setPen(pen) SelectionMark.hide() #It's better to add it hidden to avoid resizings else: try: if isinstance(picture,Qt.QGraphicsItem): SelectionMark = picture SelectionMark.setRect(0,0,w,h) SelectionMark.hide() elif operator.isCallable(picture): SelectionMark = picture() else: if isinstance(picture,Qt.QPixmap): pixmap = picture elif isinstance(picture,basestring) or isinstance(picture,Qt.QString): picture = str(picture) pixmap = Qt.QPixmap(os.path.realpath(picture)) SelectionMark = Qt.QGraphicsPixmapItem() SelectionMark.setPixmap(pixmap.scaled(w,h)) SelectionMark.hide() except: self.debug('In setSelectionMark(%s): %s'%(picture,traceback.format_exc())) picture = None return SelectionMark
def setStateBackground(self, child, color): if not isinstance(color, Qt.QColor): if DEVICE_STATE_PALETTE.has(color): qc = Qt.QColor(*DEVICE_STATE_PALETTE.rgb(color)) else: qc = Qt.QColor( color) if not fandango.isSequence(color) else Qt.QColor( *color) child.setBackground(0, Qt.QBrush(qc))
def data(self, index, role=Qt.Qt.DisplayRole): if not index.isValid() or not (0 <= index.row() < self.rowCount()): return Qt.QVariant() row = index.row() column = index.column() # Display Role if role == Qt.Qt.DisplayRole: if column == X: return Qt.QVariant(str(self.curves[row].x.display)) elif column == Y: return Qt.QVariant(str(self.curves[row].y.display)) elif column == TITLE: return Qt.QVariant(str(self.curves[row].curveparam.label)) else: return Qt.QVariant() elif role == Qt.Qt.DecorationRole: if column == X: return Qt.QVariant(self.curves[row].x.icon) elif column == Y: return Qt.QVariant(self.curves[row].y.icon) else: return Qt.QVariant() elif role == Qt.Qt.TextColorRole: if column == X: Qt.QVariant( Qt.QColor(self.curves[row].x.ok and 'green' or 'red')) elif column == Y: Qt.QVariant( Qt.QColor(self.curves[row].y.ok and 'green' or 'red')) else: return Qt.QVariant() elif role == SRC_ROLE: if column == X: return Qt.QVariant(str(self.curves[row].taurusparam.xModel)) elif column == Y: return Qt.QVariant(str(self.curves[row].taurusparam.yModel)) else: return Qt.QVariant() elif role == Qt.Qt.ToolTipRole: if column == X: return Qt.QVariant(str(self.curves[row].taurusparam.xModel)) elif column == Y: return Qt.QVariant(str(self.curves[row].taurusparam.yModel)) else: return Qt.QVariant() if role == Qt.Qt.EditRole: if column == X: return Qt.QVariant(str(self.curves[row].taurusparam.xModel)) elif column == Y: return Qt.QVariant(str(self.curves[row].taurusparam.yModel)) elif column == TITLE: return Qt.QVariant(str(self.curves[row].curveparam.label)) else: return Qt.QVariant() return Qt.QVariant()
def data(self, index, role=Qt.Qt.DisplayRole): """Reimplemented from :class:`QAbstractTableModel`""" if not index.isValid() or not (0 <= index.row() < self.rowCount()): return None row = index.row() column = index.column() # Display Role if role == Qt.Qt.DisplayRole: if column == X: return str(self.taurusItems[row].x.display) elif column == Y: return str(self.taurusItems[row].y.display) elif column == TITLE: return str(self.taurusItems[row].curveLabel) else: return None elif role == Qt.Qt.DecorationRole: if column == X: return self.taurusItems[row].x.icon elif column == Y: return self.taurusItems[row].y.icon else: return None elif role == Qt.Qt.TextColorRole: if column == X: Qt.QColor(self.taurusItems[row].x.ok and "green" or "red") elif column == Y: Qt.QColor(self.taurusItems[row].y.ok and "green" or "red") else: return None elif role == SRC_ROLE: if column == X: return str(self.taurusItems[row].xModel) elif column == Y: return str(self.taurusItems[row].yModel) else: return None elif role == Qt.Qt.ToolTipRole: if column == X: return str(self.taurusItems[row].xModel) elif column == Y: return str(self.taurusItems[row].yModel) else: return None if role == Qt.Qt.EditRole: if column == X: return str(self.taurusItems[row].xModel) elif column == Y: return str(self.taurusItems[row].yModel) elif column == TITLE: return str(self.taurusItems[row].curveLabel) else: return None return None
def _displaySelectionAsOutline(self, items): def _outline(shapes): """"Compute the boolean union from a list of QGraphicsItem. """ shape = None # TODO we can use a stack instead of recursivity for s in shapes: # TODO we should skip text and things like that if isinstance(s, TaurusGroupItem): s = _outline(s.childItems()) if s == None: continue s = s.shape() if shape != None: shape = shape.united(s) else: shape = s if shape == None: return None return Qt.QGraphicsPathItem(shape) # TODO we can cache the outline instead of computing it again and again selectionShape = _outline(items) if selectionShape: # copy-paste from getSelectionMark color = Qt.QColor(self.selectionColor()) color.setAlphaF(.10) pen = Qt.QPen(Qt.Qt.SolidLine) pen.setWidth(4) pen.setColor(Qt.QColor(self.selectionColor())) selectionShape.setBrush(color) selectionShape.setPen(pen) for item in items: if item not in self._selectedItems: self._selectedItems.append(item) # TODO i dont think this function work... or i dont know how... #self.setSelectionMark(picture=selectionShape) # ... Then do it it with hands... # copy-paste from drawSelectionMark self._selection.append(selectionShape) # It's better to add it hidden to avoid resizings selectionShape.hide() self.addItem(selectionShape) # Put on Top selectionShape.setZValue(9999) selectionShape.show() self.updateSceneViews() return True return False
def data(self, index, role=Qt.Qt.DisplayRole): if not index.isValid() or not (0 <= index.row() < self.rowCount()): return None row = index.row() column = index.column() # Display Role if role == Qt.Qt.DisplayRole: if column == X: return str(self.taurusItems[row].x.display) elif column == Y: return str(self.taurusItems[row].y.display) elif column == TITLE: return str(self.taurusItems[row].curveLabel) else: return None elif role == Qt.Qt.DecorationRole: if column == X: return self.taurusItems[row].x.icon elif column == Y: return self.taurusItems[row].y.icon else: return None elif role == Qt.Qt.TextColorRole: if column == X: Qt.QColor(self.taurusItems[row].x.ok and 'green' or 'red') elif column == Y: Qt.QColor(self.taurusItems[row].y.ok and 'green' or 'red') else: return None elif role == SRC_ROLE: if column == X: return str(self.taurusItems[row].xModel) elif column == Y: return str(self.taurusItems[row].yModel) else: return None elif role == Qt.Qt.ToolTipRole: if column == X: return str(self.taurusItems[row].xModel) elif column == Y: return str(self.taurusItems[row].yModel) else: return None if role == Qt.Qt.EditRole: if column == X: return str(self.taurusItems[row].xModel) elif column == Y: return str(self.taurusItems[row].yModel) elif column == TITLE: return str(self.taurusItems[row].curveLabel) else: return None return None
def qcolor(self, stoq): """Returns the color for the specified state or quality""" name = self._decoder(stoq) f = self._qcolor_cache_fg b = self._qcolor_cache_bg if not f.has_key(name): f[name] = Qt.QColor(self.number(name, True)) if not b.has_key(name): b[name] = Qt.QColor(self.number(name)) return (b[name], f[name])
def update_node(node, key, dct): if hasattr(node, 'CustomForeground'): node.setForeground( 0, Qt.QBrush(Qt.QColor(node.CustomForeground))) if hasattr(node, 'CustomBackground'): node.setBackground( 0, Qt.QBrush(Qt.QColor(node.CustomBackground))) elif hasattr(node, 'StateBackground'): node.setBackground(0, Qt.QBrush(state2color(dct[key]))) if hasattr(node, 'CustomIcon'): node.setIcon(0, Qt.QIcon(node.CustomIcon)) else: if key.count('/') == 2: self.setStateIcon(node, dct and dct[key] or '') return
def __init__(self, name, parent=None, designMode=False): # self.newValue - is used as a flag to indicate whether a controlUp controlDown actions are used to iterate existing element or put new one # self.disableEditMode - flag, used to disable edition, when user enters name of the macro which is not valid (not allowed to edit in the yellow line) # switches off validation # disableSpockCommandUpdate - flag, it disables updates of the model # when macro is edited by macroEditor Qt.QLineEdit.__init__(self, parent) TaurusBaseContainer.__init__(self, name, parent, designMode) self._model = None self.setFont(Qt.QFont("Courier", 9)) palette = Qt.QPalette() palette.setColor(Qt.QPalette.Base, Qt.QColor('yellow')) self.setPalette(palette) self.currentIndex = Qt.QModelIndex() self.newValue = False self.disableSpockCommandUpdate = False self.disableEditMode = True self.setEnabled(False) self.setActions() self.connect(self, Qt.SIGNAL("textChanged(const QString &)"), self.textChanged) self.connect(self, Qt.SIGNAL("returnPressed()"), self.returnPressed)
def readSimpleScalarViewerObj(self, item, params): self.readLabelObj(item, params) ext = params.get('extensions') c = ext.get('validBackground') c = [int(x) for x in c.split(",")] if c: print "c2: ", c validBackground = Qt.QColor(*c) item.setValidBackground(validBackground) invalidText = ext.get('invalidText', "---KK--") item.setNoneValue(invalidText) alarmEnabled = ext.get('alarmEnabled', True) alarmEnabled = alarmEnabled.lower().strip() in ["yes", "true", "1"] item.setShowQuality(alarmEnabled) unitVisible = ext.get('unitVisible', True) unitVisible = unitVisible.lower().strip() in ["yes", "true", "1"] item.setUnitVisible(unitVisible) userFormat = ext.get('userFormat', None) item.setUserFormat(userFormat)
def __init__(self, plot): Qt.QGraphicsScene.__init__(self, Qt.QGraphicsScene()) gv = self self.plot = plot gv.setBackgroundBrush(Qt.QBrush(Qt.QColor('white'))) self.legend = pg.LegendItem(None, offset=(0, 0)) gv.scene().addItem(self.legend)
def getShownProperties(self): """Returns a copy of the currently shown properties :return: (CurveAppearanceProperties) """ prop = CurveAppearanceProperties() # get the values from the Style comboboxes. Note that the empty string # ("") translates into None prop.sStyle = ReverseNamedSymbolStyles[str( self.ui.sStyleCB.currentText())] prop.lStyle = ReverseNamedLineStyles[str( self.ui.lStyleCB.currentText())] prop.cStyle = ReverseNamedCurveStyles[str( self.ui.cStyleCB.currentText())] # get sSize and lWidth from the spinboxes prop.sSize = self.ui.sSizeSB.value() prop.lWidth = self.ui.lWidthSB.value() if prop.sSize < 0: prop.sSize = None if prop.lWidth < 0: prop.lWidth = None # Get the Color combo boxes. The item at index 0 is the empty one in # the comboboxes index = self.ui.sColorCB.currentIndex() if index == 0: prop.sColor = None else: prop.sColor = Qt.QColor(self.ui.sColorCB.itemData(index)) index = self.ui.lColorCB.currentIndex() if index == 0: prop.lColor = None else: prop.lColor = Qt.QColor(self.ui.lColorCB.itemData(index)) # get the sFill from the Checkbox. checkState = self.ui.sFillCB.checkState() if checkState == Qt.Qt.PartiallyChecked: prop.sFill = None else: prop.sFill = bool(checkState) # get the cFill from the Checkbox. checkState = self.ui.cFillCB.checkState() if checkState == Qt.Qt.PartiallyChecked: prop.cFill = None else: prop.cFill = bool(checkState) # store the props return copy.deepcopy(prop)
def __init__(self, parent=None, curvePropDict={}, showButtons=False, autoApply=False, designMode=False): # try: super(CurvesAppearanceChooser, self).__init__(parent) self.loadUi() self.autoApply = autoApply self.sStyleCB.insertItems(0, sorted(NamedSymbolStyles.values())) self.lStyleCB.insertItems(0, list(NamedLineStyles.values())) self.cStyleCB.insertItems(0, list(NamedCurveStyles.values())) self.sColorCB.addItem("") self.lColorCB.addItem("") if not showButtons: self.applyBT.hide() self.resetBT.hide() for color in NamedColors: icon = self._colorIcon(color) self.sColorCB.addItem(icon, "", Qt.QColor(color)) self.lColorCB.addItem(icon, "", Qt.QColor(color)) self.__itemsDict = CaselessDict() self.setCurves(curvePropDict) # set the icon for the background button (stupid designer limitations # forces to do it programatically) self.bckgndBT.setIcon(Qt.QIcon(":color-fill.svg")) # connections. # Note: The assignToY1BT and assignToY2BT buttons are not connected to anything # Their signals are handled by the Config dialog because we haven't got # access to the curve objects here self.curvesLW.itemSelectionChanged.connect(self.onSelectedCurveChanged) self.curvesLW.itemChanged.connect(self.onItemChanged) self.applyBT.clicked.connect(self.onApply) self.resetBT.clicked.connect(self.onReset) self.sStyleCB.currentIndexChanged.connect(self._onSymbolStyleChanged) self.sStyleCB.currentIndexChanged.connect(self.onControlChanged) self.lStyleCB.currentIndexChanged.connect(self.onControlChanged) self.sColorCB.currentIndexChanged.connect(self.onControlChanged) self.lColorCB.currentIndexChanged.connect(self.onControlChanged) self.cStyleCB.currentIndexChanged.connect(self.onControlChanged) self.sSizeSB.valueChanged.connect(self.onControlChanged) self.lWidthSB.valueChanged.connect(self.onControlChanged) self.sFillCB.stateChanged.connect(self.onControlChanged) self.cFillCB.stateChanged.connect(self.onControlChanged)
def set_common_params(self, item, params): if not item: return item._params = params name = params.get('name') if name.lower() == "ignorerepaint": name = "" if not 'extensions' in params: params['extensions'] = {} params.get('extensions')["ignoreRepaint"] = "true" if self.alias: for k, v in self.alias.items(): name = str(name).replace(k, v) print "\n\n name w alias: ", name #Forcing not-Taurus items to have a name and be able to trigger events setattr(item, '_name', name) if name and not self._delayed: if isinstance(item, TaurusGraphicsItem): #self.debug('TaurusJDrawGraphicsFactory.set_common_params(): %s.setModel(%s)'%(item,name)) item.setModel(name) else: self.debug( 'TaurusJDrawGraphicsFactory.set_common_params(%s): %s is not a TaurusGraphicsItem' % (name, type(item).__name__)) visibilitymapper = params.get('visibilitymapper') if not visibilitymapper is None: mapping_type = visibilitymapper['mapping_type'] mode = visibilitymapper['mode'] default = visibilitymapper['default'] item._default = default item._map = visibilitymapper['map'] visible = params.get('visible') if not visible is None: item.setVisible(visible) extensions = params.get('extensions') if extensions: item._extensions = extensions try: getattr(item, 'setPen') fg = params.get("foreground", (0, 0, 0)) lineWidth = params.get("lineWidth", 1) if lineWidth == 0: pen = Qt.QPen(Qt.Qt.NoPen) else: pen = Qt.QPen(Qt.QColor(fg[0], fg[1], fg[2])) pen.setWidth(lineWidth) pen.setStyle(LINESTYLE_JDW2QT[params.get("lineStyle", 0)]) item.setPen(pen) except AttributeError, ae: #pass print "\n\n Atribute error", ae
def updateLabelBackground(ctrl, widget): """Helper method to setup background of taurus labels and lcds""" bgRole = widget.bgRole if ctrl.usePalette(): widget.setAutoFillBackground(True) if bgRole in ('', 'none', 'None'): transparentBrush = Qt.QBrush(Qt.Qt.transparent) frameBrush = transparentBrush bgBrush, fgBrush = transparentBrush, Qt.QBrush(Qt.Qt.black) else: frameBrush = Qt.QBrush(Qt.QColor(255, 255, 255, 128)) bgItem, palette = None, QT_DEVICE_STATE_PALETTE if bgRole == 'quality': palette = QT_ATTRIBUTE_QUALITY_PALETTE bgItem = ctrl.quality() elif bgRole == 'state': try: bgItem = ctrl.state() except AttributeError: pass # protect against calls with state not instantiated elif bgRole == 'value': bgItem = ctrl.value() else: # TODO: this is an *experimental* extension of the bgRole API # added in v 4.1.2-alpha. It may change in future versions modelObj = widget.getModelObj() try: bgItem = modelObj.getFragmentObj(bgRole) except: widget.warning('Invalid bgRole "%s"', bgRole) bgBrush, fgBrush = palette.qbrush(bgItem) _updatePaletteColors(widget, bgBrush, fgBrush, frameBrush) else: if bgRole in ('', 'none', 'None'): ss = StyleSheetTemplate.format("rgba(0,0,0,0)", "") else: bgItem, palette = None, QT_DEVICE_STATE_PALETTE if bgRole == 'quality': palette = QT_ATTRIBUTE_QUALITY_PALETTE bgItem = ctrl.quality() elif bgRole == 'state': bgItem = ctrl.state() elif bgRole == 'value': bgItem = ctrl.value() else: # TODO: this is an *experimental* extension of the bgRole API # added in v 4.1.2-alpha. It may change in future versions modelObj = widget.getModelObj() try: bgItem = modelObj.getFragmentObj(bgRole) except: widget.warning('Invalid bgRole "%s"', bgRole) color_ss = palette.qtStyleSheet(bgItem) ss = StyleSheetTemplate.format("rgba(255,255,255,128)", color_ss) widget.setStyleSheet(ss) widget.update() # necessary in pyqt <= 4.4
def __init__(self, parent=None, designMode=False): super(CurvePropertiesView, self).__init__(parent) self.loadUi() self.ui.sStyleCB.insertItems(0, sorted(NamedSymbolStyles.values())) self.ui.lStyleCB.insertItems(0, NamedLineStyles.values()) self.ui.cStyleCB.insertItems(0, NamedCurveStyles.values()) self.ui.sColorCB.addItem("") self.ui.lColorCB.addItem("") for color in NamedColors: icon = self._colorIcon(color) self.ui.sColorCB.addItem(icon, "", Qt.QVariant(Qt.QColor(color))) self.ui.lColorCB.addItem(icon, "", Qt.QVariant(Qt.QColor(color))) self._emptyProps = CurveAppearanceProperties() self.showProperties(self._emptyProps) # Connections self.connect(self.ui.sStyleCB, Qt.SIGNAL("currentIndexChanged(const QString&)"), self._onSymbolStyleChanged) self.connect(self.ui.sStyleCB, Qt.SIGNAL("currentIndexChanged(int)"), self.onPropertyControlChanged) self.connect(self.ui.lStyleCB, Qt.SIGNAL("currentIndexChanged(int)"), self.onPropertyControlChanged) self.connect(self.ui.lStyleCB, Qt.SIGNAL("currentIndexChanged(int)"), self.onPropertyControlChanged) self.connect(self.ui.lColorCB, Qt.SIGNAL("currentIndexChanged(int)"), self.onPropertyControlChanged) self.connect(self.ui.sColorCB, Qt.SIGNAL("currentIndexChanged(int)"), self.onPropertyControlChanged) self.connect(self.ui.cStyleCB, Qt.SIGNAL("currentIndexChanged(int)"), self.onPropertyControlChanged) self.connect(self.ui.sSizeSB, Qt.SIGNAL("valueChanged(int)"), self.onPropertyControlChanged) self.connect(self.ui.lWidthSB, Qt.SIGNAL("valueChanged(int)"), self.onPropertyControlChanged) self.connect(self.ui.sFillCB, Qt.SIGNAL("stateChanged(int)"), self.onPropertyControlChanged) self.connect(self.ui.cFillCB, Qt.SIGNAL("stateChanged(int)"), self.onPropertyControlChanged)
def data(self, index, role=Qt.Qt.DisplayRole): '''reimplemented from :class:`Qt.QAbstractListModel`''' if not index.isValid() or not (0 <= index.row() < self.rowCount()): return None row = index.row() # Display Role if role == Qt.Qt.DisplayRole: return str(self.items[row].display) elif role == Qt.Qt.DecorationRole: return self.items[row].icon elif role == Qt.Qt.TextColorRole: if not self.items[row].src: return Qt.QColor('gray') return Qt.QColor(self.items[row].ok and 'green' or 'red') elif role == SRC_ROLE: return str(self.items[row].src) elif role == Qt.Qt.ToolTipRole: return str(self.items[row].src) if role == Qt.Qt.EditRole: return str(self.items[row].src) return None
def showProperties(self, prop=None): '''Updates the dialog to show the given properties. :param prop: (CurveAppearanceProperties) the properties object containing what should be shown. If a given property is set to None, the corresponding widget will show a "neutral" display ''' if prop is None: prop = self._shownProp # set the Style comboboxes self.sStyleCB.setCurrentIndex( self.sStyleCB.findText(NamedSymbolStyles[prop.sStyle])) self.lStyleCB.setCurrentIndex( self.lStyleCB.findText(NamedLineStyles[prop.lStyle])) self.cStyleCB.setCurrentIndex( self.cStyleCB.findText(NamedCurveStyles[prop.cStyle])) # set sSize and lWidth spinboxes. if prop.sSize is None, it puts -1 # (which is the special value for these switchhboxes) self.sSizeSB.setValue(max(prop.sSize, -1)) self.lWidthSB.setValue(max(prop.lWidth, -1)) # Set the Color combo boxes. The item at index 0 is the empty one in # the comboboxes Manage unknown colors by including them if prop.sColor is None: index = 0 else: index = self.sColorCB.findData(Qt.QVariant(Qt.QColor(prop.sColor))) if index == -1: # if the color is not one of the supported colors, add it to the combobox index = self.sColorCB.count( ) # set the index to what will be the added one self.sColorCB.addItem(self._colorIcon(Qt.QColor(prop.sColor)), "", Qt.QVariant(Qt.QColor(prop.sColor))) self.sColorCB.setCurrentIndex(index) if prop.lColor is None: index = 0 else: index = self.lColorCB.findData(Qt.QVariant(Qt.QColor(prop.lColor))) if index == -1: # if the color is not one of the supported colors, add it to the combobox index = self.lColorCB.count( ) # set the index to what will be the added one self.lColorCB.addItem(self._colorIcon(Qt.QColor(prop.lColor)), "", Qt.QVariant(Qt.QColor(prop.lColor))) self.lColorCB.setCurrentIndex(index) # set the Fill Checkbox. The prop.sFill value can be in 3 states: True, # False and None if prop.sFill is None: checkState = Qt.Qt.PartiallyChecked elif prop.sFill: checkState = Qt.Qt.Checked else: checkState = Qt.Qt.Unchecked # set the Area Fill Checkbox. The prop.cFill value can be in 3 states: # True, False and None if prop.cFill is None: checkState = Qt.Qt.PartiallyChecked elif prop.cFill: checkState = Qt.Qt.Checked else: checkState = Qt.Qt.Unchecked self.cFillCB.setCheckState(checkState)
def get_White_palette(): palette = Qt.QPalette() brush = Qt.QBrush(Qt.QColor(255, 255, 255)) brush.setStyle(Qt.Qt.SolidPattern) palette.setBrush(Qt.QPalette.Active, Qt.QPalette.Base, brush) brush = Qt.QBrush(Qt.QColor(255, 255, 255)) brush.setStyle(Qt.Qt.SolidPattern) palette.setBrush(Qt.QPalette.Active, Qt.QPalette.Window, brush) brush = Qt.QBrush(Qt.QColor(255, 255, 255)) brush.setStyle(Qt.Qt.SolidPattern) palette.setBrush(Qt.QPalette.Inactive, Qt.QPalette.Base, brush) brush = Qt.QBrush(Qt.QColor(255, 255, 255)) brush.setStyle(Qt.Qt.SolidPattern) palette.setBrush(Qt.QPalette.Inactive, Qt.QPalette.Window, brush) brush = Qt.QBrush(Qt.QColor(255, 255, 255)) brush.setStyle(Qt.Qt.SolidPattern) palette.setBrush(Qt.QPalette.Disabled, Qt.QPalette.Base, brush) brush = Qt.QBrush(Qt.QColor(255, 255, 255)) brush.setStyle(Qt.Qt.SolidPattern) palette.setBrush(Qt.QPalette.Disabled, Qt.QPalette.Window, brush) return palette
def _colorIcon(self, color, w=10, h=10): '''returns an icon consisting of a rectangle of the given color :param color: (QColor or something accepted by QColor creator) The color for the icon :param w: (int) width of the icon :param h: (int) height of the icon :return: (QIcon) ''' # to do: create a border pixmap = Qt.QPixmap(w, h) pixmap.fill(Qt.QColor(color)) return Qt.QIcon(pixmap)
def setIcons(self, dct={}, root_name=None, regexps=True): ''' This method change the icons depending of the status of the devices Dict is a dictionary with name of device and colors such as {name_device:color,name_device2:color2} An alternative may be an icon name! ''' try: state2color = lambda state: Qt.QColor( DEVICE_STATE_PALETTE.number(state)) self.node_colors = getattr(self, 'node_colors', {}) dct = dict((k, v) for k, v in dct.items() if v != self.node_colors.get(k, None)) def update_node(node, key, dct): if hasattr(node, 'CustomForeground'): node.setForeground( 0, Qt.QBrush(Qt.QColor(node.CustomForeground))) if hasattr(node, 'CustomBackground'): node.setBackground( 0, Qt.QBrush(Qt.QColor(node.CustomBackground))) elif hasattr(node, 'StateBackground'): node.setBackground(0, Qt.QBrush(state2color(dct[key]))) if hasattr(node, 'CustomIcon'): node.setIcon(0, Qt.QIcon(node.CustomIcon)) else: if key.count('/') == 2: self.setStateIcon(node, dct and dct[key] or '') return nodes = self.getAllNodes() for name, node in nodes.iteritems(): name = str(name).split()[0] if node.isHidden(): continue if regexps: matches = [ v for k, v in dct.items() if re.match(k.lower(), name.lower()) ] if matches: update_node(node, name, {name: matches[0]}) elif name in dct: update_node(node, name, dct or {name: ''}) self.node_colors.update(dct) except: self.warning('setIcons(): \n%s' % traceback.format_exc())
def readLabelObj(self, item, params): origin = params.get('origin') item.setPos(origin[0], origin[1]) summit = params.get('summit') x, y = summit[0] - origin[0], summit[1] - origin[1] width, height = summit[2] - summit[0], summit[3] - summit[1] item.setRect(x, y, width, height) # it is parsed as a float vAlignment = int(params.get('vAlignment', 0)) hAlignment = int(params.get('hAlignment', 0)) assert (vAlignment in VALIGNMENT.keys()) assert (hAlignment in ALIGNMENT.keys()) vAlignment = VALIGNMENT[vAlignment] hAlignment = ALIGNMENT[hAlignment] item.setAlignment(hAlignment | vAlignment) fnt = params.get('font', None) if fnt: family, style, size = fnt f = Qt.QFont(family, int(.85 * size), Qt.QFont.Light, False) f.setStyleHint(TEXTHINT_JDW2QT.get(family, Qt.QFont.AnyStyle)) f.setStyleStrategy(Qt.QFont.PreferMatch) if style == 1: f.setWeight(Qt.QFont.DemiBold) elif style == 2: f.setItalic(True) elif style == 3: f.setWeight(Qt.QFont.DemiBold) f.setItalic(True) #TODO: Improve code in order to be able to set a suitable font item.setFont(f) fg = params.get("foreground", (0, 0, 0)) color = Qt.QColor(fg[0], fg[1], fg[2]) item.setDefaultTextColor(color) txt = params.get('text') print "\n TEXT: ", txt if txt: if any(isinstance(txt, t) for t in (list, tuple, set)): #Parsing several lines of text txt = '\n'.join(txt) print "TEXT po parsowaniu: ", txt item.setPlainText(Qt.QString(txt)) item._currText = txt
def updateLabelBackground(ctrl, widget): """Helper method to setup background of taurus labels and lcds""" bgRole = widget.bgRole if ctrl.usePalette(): widget.setAutoFillBackground(True) if bgRole in ('', 'none'): transparentBrush = Qt.QBrush(Qt.Qt.transparent) frameBrush = transparentBrush bgBrush, fgBrush = transparentBrush, Qt.QBrush(Qt.Qt.black) else: frameBrush = Qt.QBrush(Qt.QColor(255, 255, 255, 128)) bgItem, palette = None, QT_DEVICE_STATE_PALETTE if bgRole == 'quality': palette = QT_ATTRIBUTE_QUALITY_PALETTE bgItem = ctrl.quality() elif bgRole == 'state': bgItem = ctrl.state() elif bgRole == 'value': bgItem = ctrl.value() bgBrush, fgBrush = palette.qbrush(bgItem) _updatePaletteColors(widget, bgBrush, fgBrush, frameBrush) else: if bgRole in ('', 'none'): ss = StyleSheetTemplate.format("rgba(0,0,0,0)", "") else: bgItem, palette = None, QT_DEVICE_STATE_PALETTE if bgRole == 'quality': palette = QT_ATTRIBUTE_QUALITY_PALETTE bgItem = ctrl.quality() elif bgRole == 'state': bgItem = ctrl.state() elif bgRole == 'value': bgItem = ctrl.value() color_ss = palette.qtStyleSheet(bgItem) ss = StyleSheetTemplate.format("rgba(255,255,255,128)", color_ss) widget.setStyleSheet(ss) widget.update() # necessary in pyqt <= 4.4
def readVoidVoidCommandViewerObj(self, item, params): self.readButtonObj(item, params) print "III" ext = params.get('extensions') txt = ext.get('text') print "Text value: ", txt #item.setPlainText(c) #txt = params.get('text') if txt: if any(isinstance(txt, t) for t in (list, tuple, set)): #Parsing several lines of text txt = '\n'.join(txt) item.setPlainText(Qt.QString(txt)) item._currText = txt c = params.get('background') print "c: ", c if c: validBackground = Qt.QColor(*c) print "vb: ", validBackground item.setValidBackground(validBackground)
model='tango:' + DEV_NAME + '/double_scalar#rvalue', fgRole='label', expected='double_scalar') @insertTest(helper_name='text', model='tango:' + DEV_NAME + '/double_scalar', fgRole='label', expected='double_scalar') @insertTest(helper_name='text', model='tango:' + DEV_NAME + '/double_scalar#label', expected='double_scalar') # ------------------------------------------------------------------------------ # Check bck-compat with pre-tep14 BgRoles: state, quality, none @insertTest(helper_name='bgRole', model='tango:' + DEV_NAME + '/float_scalar_ro', bgRole='none', expected=Qt.QColor(Qt.Qt.transparent).getRgb()[:3]) @insertTest(helper_name='bgRole', model='tango:' + DEV_NAME + '/float_scalar_ro', bgRole='state', expected=DEVICE_STATE_DATA["TaurusDevState.Ready"][1:4]) @insertTest(helper_name='bgRole', model='tango:' + DEV_NAME + '/float_scalar_ro', bgRole='quality', expected=ATTRIBUTE_QUALITY_DATA["ATTR_VALID"][1:4]) @insertTest(helper_name='bgRole', model='tango:' + DEV_NAME + '/float_scalar_ro', expected=ATTRIBUTE_QUALITY_DATA["ATTR_VALID"][1:4]) class TaurusLabelTest2(TangoSchemeTestLauncher, BaseWidgetTestCase, unittest.TestCase): ''' Specific tests for TaurusLabel
class Q7SegDigit(Qt.QWidget): """ A widget representing a single seven segment digit. The style can be configured through the widget properties. For example, a typical LCD would have the following style: - bgColor 170, 170, 127 - ledOnPenColor 30,30,30 - ledOnBgColor 0,0,0 - ledOffPenColor 160, 160, 120 - ledOffbgColor 150, 150, 112 """ Leds = ( (1, 1, 1, 0, 1, 1, 1), # 0 (0, 0, 1, 0, 0, 1, 0), # 1 (1, 0, 1, 1, 1, 0, 1), # 2 (1, 0, 1, 1, 0, 1, 1), # 3 (0, 1, 1, 1, 0, 1, 0), # 4 (1, 1, 0, 1, 0, 1, 1), # 5 (1, 1, 0, 1, 1, 1, 1), # 6 (1, 0, 1, 0, 0, 1, 0), # 7 (1, 1, 1, 1, 1, 1, 1), # 8 (1, 1, 1, 1, 0, 1, 0), # 9 (0, 0, 0, 0, 0, 0, 0), # 10 'nothing' (0, 0, 0, 1, 0, 0, 0), # 11 - (1, 0, 1, 1, 1, 1, 1), # 12 a (0, 0, 0, 1, 1, 1, 0), # 13 n ) # LedGeometries = ( # POLY([P(67, 60), P(283, 60), P(253, 90), P(97, 90), P(67, 60)]), # POLY([P(60, 67), P(90, 97), P(90, 178), P(60, 193), P(60, 67)]), # POLY([P(290, 67), P(260, 97), P(260, 178), P(290, 193), P(290, 67)]), # POLY([P(67, 200), P(97, 185), P(253, 185), P(283, 200), P(253, 215), P(97, 215), P(67, 200)]), # POLY([P(60, 207), P(90, 222), P(90, 303), P(60, 333), P(60, 207)]), # POLY([P(290, 207), P(260, 222), P(260, 303), P(290, 333), P(290, 207)]), # POLY([P(67, 340), P(283, 340), P(253, 310), P(97, 310), P(67, 340)]), # ) LedGeometriesWithFrame300x400 = ( POLY([P(37, 30), P(263, 30), P(233, 60), P(67, 60), P(37, 30)]), POLY([P(30, 37), P(60, 67), P(60, 178), P(30, 193), P(30, 37)]), POLY([P(270, 37), P(240, 67), P(240, 178), P(270, 193), P(270, 37)]), POLY([ P(37, 200), P(67, 185), P(233, 185), P(263, 200), P(233, 215), P(67, 215), P(37, 200) ]), POLY([P(30, 207), P(60, 222), P(60, 333), P(30, 363), P(30, 207)]), POLY([P(270, 207), P(240, 222), P(240, 333), P(270, 363), P(270, 207)]), POLY([P(37, 370), P(263, 370), P(233, 340), P(67, 340), P(37, 370)]), ) LedGeometriesWithoutFrame300x400 = ( POLY([P(7, 0), P(293, 0), P(263, 30), P(37, 30), P(7, 0)]), POLY([P(0, 7), P(30, 37), P(30, 178), P(0, 193), P(0, 7)]), POLY([P(300, 7), P(270, 37), P(270, 178), P(300, 193), P(300, 7)]), POLY([ P(7, 200), P(37, 185), P(263, 185), P(293, 200), P(263, 215), P(37, 215), P(7, 200) ]), POLY([P(0, 207), P(30, 222), P(30, 363), P(0, 393), P(0, 207)]), POLY([P(300, 207), P(270, 222), P(270, 363), P(300, 393), P(300, 207)]), POLY([P(7, 400), P(293, 400), P(263, 370), P(37, 370), P(7, 400)]), ) LedGeometriesWithFrame300x300 = ( POLY([P(37, 30), P(263, 30), P(233, 60), P(67, 60), P(37, 30)]), POLY([P(30, 37), P(60, 67), P(60, 128), P(30, 143), P(30, 37)]), POLY([P(270, 37), P(240, 67), P(240, 128), P(270, 143), P(270, 37)]), POLY([ P(37, 150), P(67, 135), P(233, 135), P(263, 150), P(233, 165), P(67, 165), P(37, 150) ]), POLY([P(30, 157), P(60, 172), P(60, 233), P(30, 263), P(30, 157)]), POLY([P(270, 157), P(240, 172), P(240, 233), P(270, 263), P(270, 157)]), POLY([P(37, 270), P(263, 270), P(233, 240), P(67, 240), P(37, 270)]), ) LedGeometriesWithoutFrame300x300 = ( POLY([P(7, 0), P(293, 0), P(263, 30), P(37, 30), P(7, 0)]), POLY([P(0, 7), P(30, 37), P(30, 128), P(0, 143), P(0, 7)]), POLY([P(300, 7), P(270, 37), P(270, 128), P(300, 143), P(300, 7)]), POLY([ P(7, 150), P(37, 135), P(263, 135), P(293, 150), P(263, 165), P(37, 165), P(7, 150) ]), POLY([P(0, 157), P(30, 172), P(30, 263), P(0, 293), P(0, 157)]), POLY([P(300, 157), P(270, 172), P(270, 263), P(300, 293), P(300, 157)]), POLY([P(7, 300), P(293, 300), P(263, 270), P(37, 270), P(7, 300)]), ) DftLedOnPenColor = Qt.QColor(193, 0, 0, 255) DftLedOnBgColor = Qt.Qt.red DftLedOffPenColor = Qt.QColor(30, 30, 30, 255) DftLedOffBgColor = Qt.QColor(40, 40, 40, 255) DftBgBrush = Qt.QBrush(Qt.Qt.black, Qt.Qt.SolidPattern) DftLedPenWidth = 5 DftValue = '' DftWidth = 300 DftHeight = 300 DftAspectRatio = DftWidth / DftHeight DftUseFrame = True def __init__(self, parent=None, **kwargs): Qt.QWidget.__init__(self, parent) self._setLedPenWidth(Q7SegDigit.DftLedPenWidth) self._setValue(Q7SegDigit.DftValue) self._setLedOnPenColor(Q7SegDigit.DftLedOnPenColor) self._setLedOnBgColor(Q7SegDigit.DftLedOnBgColor) self._setLedOffPenColor(Q7SegDigit.DftLedOffPenColor) self._setLedOffBgColor(Q7SegDigit.DftLedOffBgColor) self._setBgBrush(Q7SegDigit.DftBgBrush) self._setAspectRatio(Q7SegDigit.DftAspectRatio) self._setUseFrame(Q7SegDigit.DftUseFrame) self._updatePensAndBrushes() def minimumSizeHint(self): return Qt.QSize(4, 5.9) def sizeHint(self): # return Qt.QSize(Q7SegDigit.DftWidth, Q7SegDigit.DftHeight) return Qt.QSize(40, 50) def _updatePensAndBrushes(self): pon = Qt.QPen(self._ledOnPenColor, self._ledPenWidth, Qt.Qt.SolidLine, Qt.Qt.RoundCap, Qt.Qt.RoundJoin) poff = Qt.QPen(self._ledOffPenColor, self._ledPenWidth, Qt.Qt.SolidLine, Qt.Qt.RoundCap, Qt.Qt.RoundJoin) bon = Qt.QBrush(self._ledOnBgColor, Qt.Qt.SolidPattern) boff = Qt.QBrush(self._ledOffBgColor, Qt.Qt.SolidPattern) pens, brushes = [], [] for nLeds in Q7SegDigit.Leds: nPens = [] nBrushes = [] for onoff in nLeds: if onoff: pen, brush = pon, bon else: pen, brush = poff, boff nPens.append(pen) nBrushes.append(brush) pens.append(nPens) brushes.append(nBrushes) self._pens, self._brushes = pens, brushes self.update() def __valueStrToLedIndex(self, s): if s is None: s = 10 elif s == '-': s = 11 elif s == 'a': s = 12 elif s == 'n': s = 13 else: try: s = int(s) except: s = 10 return s def paintEvent(self, evt): painter = Qt.QPainter(self) painter.setRenderHint(Qt.QPainter.Antialiasing) painter.setWindow(0, 0, self.DftWidth, self.DftHeight) w, h = float(self.width()), float(self.height()) aspect = w / h if aspect > 0.75: w = h * aspect else: h = w / aspect painter.setViewport(0, 0, w, h) self._paintBorder(painter) self._paintSegment(painter) def _paintBorder(self, painter): if self.getUseFrame(): painter.setPen( Qt.QPen(Qt.Qt.black, 2, Qt.Qt.SolidLine, Qt.Qt.RoundCap, Qt.Qt.RoundJoin)) linGrad = Qt.QLinearGradient(30, 200, 200, 150) linGrad.setColorAt(0, Qt.Qt.darkGray) linGrad.setColorAt(1, Qt.Qt.white) linGrad.setSpread(Qt.QGradient.ReflectSpread) painter.setBrush(linGrad) border2 = Qt.QRectF(0, 0, self.DftWidth, self.DftHeight) painter.drawRoundRect(border2, 10, 10) painter.setBrush(self.getBgBrush()) dist = 20 border1 = Qt.QRectF(dist, dist, self.DftWidth - 2 * dist, self.DftHeight - 2 * dist) painter.drawRoundRect(border1, 5, 5) else: painter.setBrush(self.getBgBrush()) border1 = Qt.QRectF(0, 0, self.DftWidth, self.DftHeight) painter.drawRect(border1) def _paintSegment(self, painter): idx = self.__valueStrToLedIndex(self._value) if self.getUseFrame(): if self.DftHeight == 300: geom = self.LedGeometriesWithFrame300x300 else: geom = self.LedGeometriesWithFrame300x400 else: if self.DftHeight == 300: geom = self.LedGeometriesWithoutFrame300x300 else: geom = self.LedGeometriesWithoutFrame300x400 pens, brushes = self._pens[idx], self._brushes[idx] for i in xrange(7): seg = Qt.QPainterPath() seg.addPolygon(geom[i]) painter.setPen(pens[i]) painter.setBrush(brushes[i]) painter.drawPath(seg) def __str__(self): _, idx = '', self.__valueStrToLedIndex(self._value) leds = self.Leds[idx] # line 0 c = ' ' if leds[0]: c = '_' ret = ' %c \n' % c # line 1 c1, c2, c3 = ' ', ' ', ' ' if leds[1]: c1 = '|' if leds[3]: c2 = '_' if leds[2]: c3 = '|' ret += '%c%c%c\n' % (c1, c2, c3) # line 2 c1, c2, c3 = ' ', ' ', ' ' if leds[4]: c1 = '|' if leds[6]: c2 = '_' if leds[5]: c3 = '|' ret += '%c%c%c' % (c1, c2, c3) return ret def _setValue(self, n): if n is None: self._value = n else: self._value = str(n) def _setLedPenWidth(self, w): self._ledPenWidth = w def _setLedOnPenColor(self, penColor): self._ledOnPenColor = penColor def _setLedOnBgColor(self, bgColor): self._ledOnBgColor = bgColor def _setLedOffPenColor(self, penColor): self._ledOffPenColor = penColor def _setLedOffBgColor(self, bgColor): self._ledOffBgColor = bgColor def _setAspectRatio(self, aspectRatio): self._aspectRatio = aspectRatio def _setBgBrush(self, bgBrush): if isinstance(bgBrush, Qt.QColor): bgBrush = Qt.QBrush(bgBrush, Qt.Qt.SolidPattern) self._bgBrush = bgBrush def _setUseFrame(self, useFrame): self._useFrame = useFrame def getLedOnPenColor(self): return self._ledOnPenColor def setLedOnPenColor(self, penColor): self._setLedOnPenColor(penColor) self._updatePensAndBrushes() def resetLedOnPenColor(self): self.setLenOnPenColor(Q7SegDigit.DftLedOnPenColor) def getLedOnBgColor(self): return self._ledOnBgColor def setLedOnBgColor(self, bgColor): self._setLedOnBgColor(bgColor) self._updatePensAndBrushes() def resetLedOnBgColor(self): self.setLedOnBgColor(Q7SegDigit.DftLedOnBgColor) def getLedOffPenColor(self): return self._ledOffPenColor def setLedOffPenColor(self, penColor): self._setLedOffPenColor(penColor) self._updatePensAndBrushes() def resetLedOffPenColor(self): self.setLenOffPenColor(Q7SegDigit.DftLedOffPenColor) def getLedOffBgColor(self): return self._ledOffBgColor def setLedOffBgColor(self, bgColor): self._setLedOffBgColor(bgColor) self._updatePensAndBrushes() def resetLedOffBgColor(self): self.setLedOffBgColor(Q7SegDigit.DftLedOffBgColor) def getBgBrush(self): return self._bgBrush def setBgBrush(self, bgBrush): self._setBgBrush(bgBrush) self.update() def resetBgBrush(self): self.setBgBrush(Q7SegDigit.DftBgBrush) def setValue(self, n): self._setValue(n) self.update() def getValue(self): return self._value def resetValue(self): self.setValue(Q7SegDigit.DftValue) def setLedPenWidth(self, w): self._setLedPenWidth(w) self._updatePensAndBrushes() def getLedPenWidth(self): return self._ledPenWidth def resetLedPenWidth(self): self.setLedPenWidth(Q7SegDigit.DftLenPenWidth) def setAspectRatio(self, apectRatio): self._setAspectRatio(apectRatio) self.update() def getAspectRatio(self): return self._aspectRatio def resetAspectRatio(self): self.setAspectRatio(Q7SegDigit.DftAspectRatio) def setUseFrame(self, useFrame): self._setUseFrame(useFrame) def getUseFrame(self): return self._useFrame def resetUseFrame(self): self.setUseFrame(Q7SegDigit.DftUseFrame) #: This property holds the led pen color when the led is light ON #: #: **Access functions:** #: #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.getLedOnPenColor` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.setLedOnPenColor` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.resetLedOnPenColor` #: ledOnPenColor = Qt.pyqtProperty("QColor", getLedOnPenColor, setLedOnPenColor, resetLedOnPenColor) #: This property holds the led background color when the led is light ON #: #: **Access functions:** #: #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.getLedOnBgColor` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.setLedOnBgColor` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.resetLedOnBgColor` #: ledOnBgColor = Qt.pyqtProperty("QColor", getLedOnBgColor, setLedOnBgColor, resetLedOnBgColor) #: This property holds the led pen color when the led is light OFF #: #: **Access functions:** #: #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.getLedOffPenColor` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.setLedOffPenColor` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.resetLedOffPenColor` #: ledOffPenColor = Qt.pyqtProperty("QColor", getLedOffPenColor, setLedOffPenColor, resetLedOffPenColor) #: This property holds the led background color when the led is light OFF #: #: **Access functions:** #: #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.getLedOffBgColor` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.setLedOffBgColor` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.resetLedOffBgColor` #: ledOffBgColor = Qt.pyqtProperty("QColor", getLedOffBgColor, setLedOffBgColor, resetLedOffBgColor) #: This property holds the background brush #: #: **Access functions:** #: #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.getBgBrush` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.setBgBrush` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.resetBgBrush` #: bgBrush = Qt.pyqtProperty("QBrush", getBgBrush, setBgBrush, resetBgBrush) #: This property holds the pen width #: #: **Access functions:** #: #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.getLedPenWidth` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.setLedPenWidth` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.resetLedPenWidth` #: ledPenWidth = Qt.pyqtProperty("int", getLedPenWidth, setLedPenWidth, resetLedPenWidth) #: This property holds wheater of not to draw a frame #: #: **Access functions:** #: #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.getUseFrame` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.setUseFrame` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.resetUseFrame` #: useFrame = Qt.pyqtProperty("bool", getUseFrame, setUseFrame, resetUseFrame) #: This property holds the widget value #: #: **Access functions:** #: #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.getValue` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.setValue` #: * :meth:`taurus.qt.qtgui.display.Q7SegDigit.resetValue` #: value = Qt.pyqtProperty("QString", getValue, setValue, resetValue)
def _colorIcon(self, color, w=10, h=10): # to do: create a border pixmap = Qt.QPixmap(w, h) pixmap.fill(Qt.QColor(color)) return Qt.QIcon(pixmap)
def showProperties(self, prop, blockSignals=True): '''Updates the control widgets to show the given properties. ..note:: that the signals of the controls may be temporally blocked to prevent loops. See the `blockSignals` parameter. :param prop: (CurveAppearanceProperties) the properties object containing what should be shown. If a given property is set to None, the corresponding widget will show a "neutral" display :param blockSignals: (bool) If True (default) the signals of the control widgets are blocked while updating them to avoid loops. ''' if blockSignals: self.blockControlsSignals(True) # set the Style comboboxes self.ui.sStyleCB.setCurrentIndex( self.ui.sStyleCB.findText(NamedSymbolStyles[prop.sStyle])) self.ui.lStyleCB.setCurrentIndex( self.ui.lStyleCB.findText(NamedLineStyles[prop.lStyle])) self.ui.cStyleCB.setCurrentIndex( self.ui.cStyleCB.findText(NamedCurveStyles[prop.cStyle])) # set sSize and lWidth spinboxes. if prop.sSize is None, it puts -1 # (which is the special value for these switchhboxes) self.ui.sSizeSB.setValue(max(prop.sSize, -1)) self.ui.lWidthSB.setValue(max(prop.lWidth, -1)) # Set the Color combo boxes. The item at index 0 is the empty one in # the comboboxes Manage unknown colors by including them if prop.sColor is None: index = 0 else: index = self.ui.sColorCB.findData( Qt.QVariant(Qt.QColor(prop.sColor))) if index == -1: # if the color is not one of the supported colors, add it to the combobox index = self.ui.sColorCB.count( ) # set the index to what will be the added one self.ui.sColorCB.addItem(self._colorIcon(Qt.QColor(prop.sColor)), "", Qt.QVariant(Qt.QColor(prop.sColor))) self.ui.sColorCB.setCurrentIndex(index) if prop.lColor is None: index = 0 else: index = self.ui.lColorCB.findData( Qt.QVariant(Qt.QColor(prop.lColor))) if index == -1: # if the color is not one of the supported colors, add it to the combobox index = self.ui.lColorCB.count( ) # set the index to what will be the added one self.ui.lColorCB.addItem(self._colorIcon(Qt.QColor(prop.lColor)), "", Qt.QVariant(Qt.QColor(prop.lColor))) self.ui.lColorCB.setCurrentIndex(index) # set the Fill Checkbox. The prop.sFill value can be in 3 states: True, # False and None if prop.sFill is None: checkState = Qt.Qt.PartiallyChecked elif prop.sFill: checkState = Qt.Qt.Checked else: checkState = Qt.Qt.Unchecked self.ui.sFillCB.setCheckState(checkState) # set the Area Fill Checkbox. The prop.cFill value can be in 3 states: # True, False and None if prop.cFill is None: checkState = Qt.Qt.PartiallyChecked elif prop.cFill: checkState = Qt.Qt.Checked else: checkState = Qt.Qt.Unchecked self.ui.cFillCB.setCheckState(checkState) if blockSignals: self.blockControlsSignals(False)
from taurus.external.qt import Qt from taurus.qt.qtgui.model import FilterToolBar from taurus.qt.qtgui.util import ActionFactory from taurus.qt.qtgui.resource import getThemeIcon from qtable import QBaseTableWidget LEVEL, TIME, MSG, NAME, ORIGIN = range(5) HORIZ_HEADER = 'Level', 'Time', 'Message', 'By', 'Origin' __LEVEL_BRUSH = { taurus.Trace: (Qt.Qt.lightGray, Qt.Qt.black), taurus.Debug: (Qt.Qt.green, Qt.Qt.black), taurus.Info: (Qt.Qt.blue, Qt.Qt.white), taurus.Warning: (Qt.QColor(255, 165, 0), Qt.Qt.black), taurus.Error: (Qt.Qt.red, Qt.Qt.black), taurus.Critical: (Qt.QColor(160, 32, 240), Qt.Qt.white), } def getBrushForLevel(level): elevel = taurus.Trace if level <= taurus.Trace: elevel = taurus.Trace elif level <= taurus.Debug: elevel = taurus.Debug elif level <= taurus.Info: elevel = taurus.Info elif level <= taurus.Warning: elevel = taurus.Warning
def data(self, index, role=Qt.Qt.DisplayRole): if not index.isValid() or not (0 <= index.row() < self.rowCount()): return Qt.QVariant() row = index.row() column = index.column() # Display Role if role == Qt.Qt.DisplayRole: if column == X: return Qt.QVariant(Qt.QString(self.curves[row].x.display)) elif column == Y: return Qt.QVariant(Qt.QString(self.curves[row].y.display)) elif column == TITLE: return Qt.QVariant(Qt.QString(self.curves[row].title)) elif column == VIS: return Qt.QVariant(Qt.QString(self.curves[row].vis)) else: return Qt.QVariant() elif role == Qt.Qt.DecorationRole: if column == X: return Qt.QVariant(self.curves[row].x.icon) elif column == Y: return Qt.QVariant(self.curves[row].y.icon) elif column == TITLE: return Qt.QVariant( Qt.QColor(self.curves[row].properties.lColor or 'black')) else: return Qt.QVariant() elif role == Qt.Qt.TextColorRole: if column == X: Qt.QVariant( Qt.QColor(self.curves[row].x.ok and 'green' or 'red')) elif column == Y: Qt.QVariant( Qt.QColor(self.curves[row].y.ok and 'green' or 'red')) else: return Qt.QVariant() elif role == SRC_ROLE: if column == X: return Qt.QVariant(Qt.QString(self.curves[row].x.src)) elif column == Y: return Qt.QVariant(Qt.QString(self.curves[row].y.src)) else: return Qt.QVariant() elif role == PROPS_ROLE: return self.curves[row].properties elif role == Qt.Qt.ToolTipRole: if column == X: return Qt.QVariant(Qt.QString(self.curves[row].x.src)) elif column == Y: return Qt.QVariant(Qt.QString(self.curves[row].y.src)) else: return Qt.QVariant() if role == Qt.Qt.EditRole: if column == X: return Qt.QVariant(Qt.QString(self.curves[row].x.src)) elif column == Y: return Qt.QVariant(Qt.QString(self.curves[row].y.src)) elif column == TITLE: return Qt.QVariant(Qt.QString(self.curves[row].title)) else: return Qt.QVariant() # Alignment # elif role == Qt.Qt.TextAlignmentRole: # return QVariant(int(Qt.AlignHCenter|Qt.AlignVCenter)) # Text Color # elif role == Qt.Qt.TextColorRole: # return Qt.QVariant(Qt.QColor(self.curves[row].properties.lColor or # 'black')) return Qt.QVariant()