def get_painter(self, canvas): p = QtGui.QPainter(canvas) facecolor = mpl_to_qt_color(self.plot_opts['facecolor'], self.plot_opts['alpha']) edgecolor = mpl_to_qt_color(self.plot_opts['edgecolor'], self.plot_opts['alpha']) pen = QtGui.QPen(edgecolor) pen.setWidth(self.plot_opts.get('edgewidth', 0)) p.setPen(pen) p.setBrush(QtGui.QBrush(facecolor)) return p
def _setup_widgets(self): self.layout = QtWidgets.QFormLayout() self.size_widget = QtWidgets.QSpinBox() self.size_widget.setMinimum(1) self.size_widget.setMaximum(40) self.size_widget.setValue(self.layer.style.markersize) self.label_widget = QtWidgets.QLineEdit() self.label_widget.setText(self.layer.label) self.label_widget.selectAll() self.color_widget = ColorWidget() self.color_widget.setStyleSheet('ColorWidget {border: 1px solid;}') color = self.layer.style.color color = mpl_to_qt_color(color, alpha=self.layer.style.alpha) self.set_color(color) self.okcancel = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel) if self._edit_label: self.layout.addRow("Label", self.label_widget) self.layout.addRow("Color", self.color_widget) self.layout.addRow("Size", self.size_widget) self.layout.addWidget(self.okcancel) self.setLayout(self.layout) self.layout.setContentsMargins(6, 6, 6, 6)
def layer_icon(layer): """Create a QtGui.QIcon for a Data or Subset instance :type layer: :class:`~glue.core.data.Data`, :class:`~glue.core.subset.Subset`, or object with a .style attribute :rtype: QtGui.QIcon """ icon = POINT_ICONS.get(layer.style.marker, 'circle_point') bm = QtGui.QBitmap(icon_path(icon)) color = mpl_to_qt_color(layer.style.color) pm = tint_pixmap(bm, color) return QtGui.QIcon(pm)
def layer_icon(layer): """Create a QtGui.QIcon for a Data or Subset instance :type layer: :class:`~glue.core.data.Data`, :class:`~glue.core.subset.Subset`, or object with a .style attribute :rtype: QtGui.QIcon """ icon = POINT_ICONS.get(layer.style.marker, 'circle_point') bm = QtGui.QBitmap(icon_path(icon)) color = mpl_to_qt_color(layer.style.color) pm = tint_pixmap(bm, color) return QtGui.QIcon(pm)
def data_by_row_and_column(self, row, column, role): if role == Qt.DisplayRole: c = self.columns[column] idx = self.order_visible[row] comp = self._data[c] value = comp[idx] if isinstance(value, bytes): return value.decode('ascii') else: if DASK_INSTALLED and isinstance(value, da.Array): return str(value.compute()) else: return str(comp[idx]) elif role == Qt.BackgroundRole: idx = self.order_visible[row] # Find all subsets that this index is part of colors = [] for layer_artist in self._table_viewer.layers[::-1]: if isinstance(layer_artist.layer, BaseData): continue if layer_artist.visible: subset = layer_artist.layer try: if subset.to_mask(view=slice(idx, idx + 1))[0]: colors.append(subset.style.color) except IncompatibleAttribute as exc: # Only disable the layer if enabled, as otherwise we # will recursively call clear and _refresh, causing # an infinite loop and performance issues. if layer_artist.enabled: layer_artist.disable_invalid_attributes(*exc.args) else: layer_artist.enabled = True # Blend the colors using alpha blending if len(colors) > 0: color = alpha_blend_colors(colors, additional_alpha=0.5) color = mpl_to_qt_color(color) return QtGui.QBrush(color)
def data(self, index, role): if not index.isValid(): return None if role == Qt.DisplayRole: c = self.columns[index.column()] idx = self.order[index.row()] comp = self._data.get_component(c) if comp.categorical: comp = comp.labels else: comp = comp.data if isinstance(comp[idx], bytes): return comp[idx].decode('ascii') else: return str(comp[idx]) elif role == Qt.BackgroundRole: idx = self.order[index.row()] # Find all subsets that this index is part of colors = [] for layer_artist in self._table_viewer.layers[::-1]: if isinstance(layer_artist.layer, Data): continue if layer_artist.visible: subset = layer_artist.layer try: if subset.to_mask(view=slice(idx, idx + 1))[0]: colors.append(subset.style.color) except IncompatibleAttribute as exc: layer_artist.disable_invalid_attributes(*exc.args) else: layer_artist.enabled = True # Blend the colors using alpha blending if len(colors) > 0: color = alpha_blend_colors(colors, additional_alpha=0.5) color = mpl_to_qt_color(color) return QtGui.QBrush(color)
def data(self, index, role): if not index.isValid(): return None if role == Qt.DisplayRole: c = self.columns[index.column()] idx = self.order[index.row()] comp = self._data.get_component(c) if comp.categorical: comp = comp.labels else: comp = comp.data if isinstance(comp[idx], bytes): return comp[idx].decode('ascii') else: return str(comp[idx]) elif role == Qt.BackgroundRole: idx = self.order[index.row()] # Find all subsets that this index is part of colors = [] for layer_artist in self._table_viewer.layers[::-1]: if isinstance(layer_artist.layer, Data): continue if layer_artist.visible: subset = layer_artist.layer try: if subset.to_mask(view=slice(idx, idx + 1))[0]: colors.append(subset.style.color) except IncompatibleAttribute as exc: layer_artist.disable_invalid_attributes(*exc.args) else: layer_artist.enabled = True # Blend the colors using alpha blending if len(colors) > 0: color = alpha_blend_colors(colors, additional_alpha=0.5) color = mpl_to_qt_color(color) return QtGui.QBrush(color)
def layer_artist_icon(artist): """Create a QtGui.QIcon for a LayerArtist instance""" # TODO: need a test for this from glue.viewers.scatter.layer_artist import ScatterLayerArtist color = artist.get_layer_color() if isinstance(color, Colormap): pm = cmap2pixmap(color) else: if isinstance(artist, ScatterLayerArtist): bm = QtGui.QBitmap(icon_path(POINT_ICONS.get(artist.layer.style.marker, 'glue_circle_point'))) else: bm = QtGui.QBitmap(icon_path('glue_box_point')) color = mpl_to_qt_color(color) pm = tint_pixmap(bm, color) return QtGui.QIcon(pm)
def layer_artist_icon(artist): """Create a QtGui.QIcon for a LayerArtist instance""" # TODO: need a test for this from glue.viewers.scatter.layer_artist import ScatterLayerArtist color = artist.get_layer_color() if isinstance(color, Colormap): pm = cmap2pixmap(color) else: if isinstance(artist, ScatterLayerArtist): bm = QtGui.QBitmap(icon_path(POINT_ICONS.get(artist.layer.style.marker, 'glue_circle_point'))) else: bm = QtGui.QBitmap(icon_path('glue_box_point')) color = mpl_to_qt_color(color) pm = tint_pixmap(bm, color) return QtGui.QIcon(pm)
def get_pen(color, linewidth=1): color = mpl_to_qt_color(color) return QPen(color, linewidth, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
def color(self, value): self.node.setBrush(mpl_to_qt_color(value))
def get_pen(color, linewidth=1): color = mpl_to_qt_color(color) return QPen(color, linewidth, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
def color(self, value): self.node.setBrush(mpl_to_qt_color(value))