Example #1
0
    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)
Example #2
0
    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_qt4_color(color)
                return QtGui.QBrush(color)
Example #3
0
    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)
Example #4
0
    def _rerender_table(self, *args, **kwargs):
        colors = [[] for i in range(self._main_data.shape[0])]
        for sub in self._main_data.subsets:
            mask = sub.to_mask()
            sub.style.color
            for i in range(len(mask)):
                if mask[i]:
                    colors[i].append(sub.style.color)

        styles = []
        for i, c in enumerate(colors):
            if len(c) > 0:
                color = alpha_blend_colors(c, additional_alpha=0.5)
                style = {'backgroundColor': "rgba({}, {}, {}, {})".format(*color)}
            else:
                style = {}
            styles.append(style)

        for i, s in enumerate(styles):
            self.rows[i].style = s