def data(self, index, role): """ @see http://doc.qt.io/qt-4.8/qt.html#ItemDataRole-enum """ item = self.itemAt(index) if not item: return None d = item.declaration if role == Qt.DisplayRole: return d.text elif role == Qt.ToolTipRole: return d.tool_tip elif role == Qt.CheckStateRole and d.checkable: return d.checked and Qt.Checked or Qt.Unchecked elif role == Qt.DecorationRole and d.icon: return get_cached_qicon(d.icon) elif role == Qt.EditRole and d.editable: return d.text elif role == Qt.StatusTipRole: return d.status_tip elif role == Qt.TextAlignmentRole: h,v = d.text_alignment return TEXT_H_ALIGNMENTS[h] | TEXT_V_ALIGNMENTS[v] elif role == Qt.ForegroundRole and d.foreground: return get_cached_qcolor(d.foreground) elif role == Qt.BackgroundRole and d.background: return get_cached_qcolor(d.background) #elif role == Qt.SizeHintRole and (d.minimum_size): # return d.minimum_size return None
def data(self, index, role): """ @see http://doc.qt.io/qt-4.8/qt.html#ItemDataRole-enum """ item = self.itemAt(index) if not item: return None d = item.declaration if role == Qt.DisplayRole: return d.text elif role == Qt.ToolTipRole: return d.tool_tip elif role == Qt.CheckStateRole and d.checkable: return d.checked and Qt.Checked or Qt.Unchecked elif role == Qt.DecorationRole and d.icon: return get_cached_qicon(d.icon) elif role == Qt.EditRole and d.editable: return d.text elif role == Qt.StatusTipRole: return d.status_tip elif role == Qt.TextAlignmentRole: h, v = d.text_alignment return TEXT_H_ALIGNMENTS[h] | TEXT_V_ALIGNMENTS[v] elif role == Qt.ForegroundRole and d.foreground: return get_cached_qcolor(d.foreground) elif role == Qt.BackgroundRole and d.background: return get_cached_qcolor(d.background) #elif role == Qt.SizeHintRole and (d.minimum_size): # return d.minimum_size return None
def data(self, index, role): """ Retrieve the data for the item at the given index """ item = self.itemAt(index) if not item: return None d = item.declaration if role == Qt.DisplayRole: return d.text elif role == Qt.ToolTipRole: return d.tool_tip elif role == Qt.CheckStateRole and d.checkable: return d.checked and Qt.Checked or Qt.Unchecked elif role == Qt.DecorationRole and d.icon: return get_cached_qicon(d.icon) elif role == Qt.EditRole and d.editable: return d.text elif role == Qt.StatusTipRole: return d.status_tip elif role == Qt.TextAlignmentRole: h, v = d.text_alignment return TEXT_H_ALIGNMENTS[h] | TEXT_V_ALIGNMENTS[v] elif role == Qt.ForegroundRole and d.foreground: return get_cached_qcolor(d.foreground) elif role == Qt.BackgroundRole and d.background: return get_cached_qcolor(d.background) #elif role == Qt.SizeHintRole and d.minimum_size: # return d.minimum_size return None
def test_color_initialization(): """Test the different initialization format supported by Color. """ components = [1, 2, 3, 4] c = Color(*components) for name, value in zip(['red', 'green', 'blue', 'alpha'], components): assert getattr(c, name) == value c = Color(alpha=-1) for name in ['red', 'green', 'blue', 'alpha']: assert getattr(c, name) == 0 assert c._tkdata is None get_cached_qcolor(c) assert c._tkdata is not None
def color_icon(color): pixmap = QPixmap(12, 12) if color is None: color = Color(0, 0, 0, 0) pixmap.fill(get_cached_qcolor(color)) icg = IconImage(image=Image(_tkdata=pixmap.toImage())) return Icon(images=[icg])
def set_color_default(self, color_default): self.color_default = get_cached_qcolor(color_default) self.pen_default = QtGui.QPen(self.color_default) self.pen_default.setWidthF(self.line_width) self.pen_dragging = QtGui.QPen(self.color_default) self.pen_dragging.setStyle(QtCore.Qt.DashLine) self.pen_dragging.setWidthF(self.line_width)
def QBrush_from_Brush(brush): qbrush = QBrush() if brush.color: qbrush.setColor(get_cached_qcolor(brush.color)) if brush.image: qbrush.setTextureImage(get_cached_qimage(brush.image)) qbrush.setStyle(Qt.TexturePattern) else: qbrush.setStyle(BRUSH_STYLES.get(brush.style)) return qbrush
def QPen_from_Pen(pen): qpen = QPen() if pen.color: qpen.setColor(get_cached_qcolor(pen.color)) qpen.setWidth(pen.width) qpen.setStyle(PEN_STYLES.get(pen.line_style)) qpen.setCapStyle(CAP_STYLES.get(pen.cap_style)) qpen.setJoinStyle(JOIN_STYLES.get(pen.join_style)) if pen.line_style == "custom": qpen.setDashPattern(*pen.dash_pattern) return qpen
def test_color_initialization(): """Test the different initialization format supported by Color. """ components = [1, 2, 3, 4] c = Color(*components) for name, value in zip(['red', 'green', 'blue', 'alpha'], components): assert getattr(c, name) == value c = Color(alpha=-1) for name in ['red', 'green', 'blue', 'alpha']: assert getattr(c, name) == 0 assert c._tkdata is None try: from enaml.qt.q_resource_helpers import get_cached_qcolor except Exception: return get_cached_qcolor(c) assert c._tkdata is not None
def data(self, index, role=Qt.DisplayRole): if not (index.isValid() and (0 <= index.row() < self.rowCount())): return None if role == Qt.TextAlignmentRole: return int(Qt.AlignRight | Qt.AlignVCenter) elif role == Qt.DecorationRole: row = self.map_to_row(index.row()) col = self.map_to_col(index.column()) value = self.get_value(index.row(), index.column()) data = self.decoration(row, col, value) if isinstance(data, Color): return get_cached_qcolor(data) elif isinstance(data, Icon): return get_cached_qicon(data) else: return None elif role == Qt.DisplayRole: return self.format_value( self.get_value(index.row(), index.column())) return None
def set_color_default(self, color_default): self.color_default = get_cached_qcolor(color_default)
def set_background(self, background): color = get_cached_qcolor(background) if background else None if isinstance(self.parent(), AbstractQtPlotItem): self.parent().parent_widget().setBackground(color) else: self.parent_widget().setBackground(color)
def set_color_selected(self, color_selected): self.color_selected = get_cached_qcolor(color_selected) self.pen_selected = QtGui.QPen(self.color_selected) self.pen_selected.setWidthF(2.0)
def set_color_label(self, color_label): self.color_label = get_cached_qcolor(color_label)
def set_color_outline(self, color_outline): self.color_outline = get_cached_qcolor(color_outline)
def set_color_background(self, color_background): self.color_background = get_cached_qcolor(color_background)
def set_color_title(self, color_title): self.widget.title_item.setDefaultTextColor( get_cached_qcolor(color_title))
def set_color_selected(self, color_selected): self.color_selected = get_cached_qcolor(color_selected)