How to use the silx.gui.qt.QIcon function in silx

To help you get started, we’ve selected a few silx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github silx-kit / silx / examples / icons.py View on Github external
for i, icon_info in enumerate(icons):
            icon_name, icon_kind = icon_info
            col, line = i // 10, i % 10
            if icon_kind == "anim":
                tool = AnimatedToolButton(panel)
                try:
                    icon = silx.gui.icons.getAnimatedIcon(icon_name)
                except ValueError:
                    icon = qt.QIcon()
                tool.setToolTip("Animated icon '%s'" % icon_name)
            else:
                tool = qt.QToolButton(panel)
                try:
                    icon = silx.gui.icons.getQIcon(icon_name)
                except ValueError:
                    icon = qt.QIcon()
                tool.setToolTip("Icon '%s'" % icon_name)
            tool.setIcon(icon)
            tool.setIconSize(qt.QSize(32, 32))
            layout.addWidget(tool, col, line)
            self.tools.append(tool)

        return panel
github silx-kit / silx / silx / gui / dialog / ColormapDialog.py View on Github external
lut = lut[indexes]
        if lut is None or len(lut) == 0:
            return qt.QIcon()

        pixmap = qt.QPixmap(size, size)
        painter = qt.QPainter(pixmap)
        for i in range(size):
            rgb = lut[i]
            r, g, b = rgb[0], rgb[1], rgb[2]
            painter.setPen(qt.QColor(r, g, b))
            painter.drawPoint(qt.QPoint(i, 0))

        painter.drawPixmap(0, 1, size, size - 1, pixmap, 0, 0, size, 1)
        painter.end()

        return qt.QIcon(pixmap)
github silx-kit / silx / silx / gui / widgets / WaitingPushButton.py View on Github external
def __updateVisibleIcon(self):
        """Update the visible icon according to the state of the widget."""
        if not self.isWaiting():
            icon = self.__icon
        else:
            animated_icon = icons.getWaitIcon()
            icon = animated_icon.currentIcon()
        if icon is None:
            icon = qt.QIcon()
        qt.QPushButton.setIcon(self, icon)
github silx-kit / silx / silx / gui / plot / actions / PlotAction.py View on Github external
def __init__(self, plot, icon, text, tooltip=None,
                 triggered=None, checkable=False, parent=None):
        assert plot is not None
        self._plotRef = weakref.ref(plot)

        if not isinstance(icon, qt.QIcon):
            # Try with icon as a string and load corresponding icon
            icon = icons.getQIcon(icon)

        super(PlotAction, self).__init__(icon, text, parent)

        if tooltip is not None:
            self.setToolTip(tooltip)

        self.setCheckable(checkable)

        if triggered is not None:
            self.triggered[bool].connect(triggered)
github silx-kit / silx / examples / animatedicons.py View on Github external
def _setAnimatedIcon(self, icon):
        if self.__animatedIcon is not None:
            self.__animatedIcon.unregister(self)
            self.__animatedIcon.iconChanged.disconnect(self.__updateIcon)
        self.__animatedIcon = icon
        if self.__animatedIcon is not None:
            self.__animatedIcon.register(self)
            self.__animatedIcon.iconChanged.connect(self.__updateIcon)
            i = self.__animatedIcon.currentIcon()
        else:
            i = qt.QIcon()
        super(AnimatedToolButton, self).setIcon(i)
github silx-kit / silx / silx / gui / dialog / ColormapDialog.py View on Github external
size = 32
        if name is not None:
            lut = colormap.getNColors(size)
        else:
            lut = colors
            if len(lut) > size:
                # Down sample
                step = int(len(lut) / size)
                lut = lut[::step]
            elif len(lut) < size:
                # Over sample
                indexes = numpy.arange(size) / float(size) * (len(lut) - 1)
                indexes = indexes.astype("int")
                lut = lut[indexes]
        if lut is None or len(lut) == 0:
            return qt.QIcon()

        pixmap = qt.QPixmap(size, size)
        painter = qt.QPainter(pixmap)
        for i in range(size):
            rgb = lut[i]
            r, g, b = rgb[0], rgb[1], rgb[2]
            painter.setPen(qt.QColor(r, g, b))
            painter.drawPoint(qt.QPoint(i, 0))

        painter.drawPixmap(0, 1, size, size - 1, pixmap, 0, 0, size, 1)
        painter.end()

        return qt.QIcon(pixmap)
github silx-kit / silx / silx / gui / plot / ColormapDialog.py View on Github external
def createIconPreview(self, colormapName):
        """Create and return an icon preview from a LUT name.

        This icons are cached into a global structure.

        :param str colormapName: Name of the LUT
        :rtype: qt.QIcon
        """
        colormap = Colormap(colormapName)
        size = 32
        lut = colormap.getNColors(size)
        if lut is None or len(lut) == 0:
            return qt.QIcon()

        pixmap = qt.QPixmap(size, size)
        painter = qt.QPainter(pixmap)
        for i in range(size):
            rgb = lut[i]
            r, g, b = rgb[0], rgb[1], rgb[2]
            painter.setPen(qt.QColor(r, g, b))
            painter.drawPoint(qt.QPoint(i, 0))

        painter.drawPixmap(0, 1, size, size - 1, pixmap, 0, 0, size, 1)
        painter.end()

        return qt.QIcon(pixmap)
github silx-kit / silx / silx / gui / plot / ImageStack.py View on Github external
def _setButtonIcon(self, show):
        style = qt.QApplication.instance().style()
        # return a QIcon
        icon = style.standardIcon(self._BUTTON_ICON)
        if show is False:
            pixmap = icon.pixmap(32, 32).transformed(qt.QTransform().scale(-1, 1))
            icon = qt.QIcon(pixmap)
        self._toggleButton.setIcon(icon)
github silx-kit / pyFAI / pyFAI / gui / tasks / PeakPickingTask.py View on Github external
def createIcon(identifiyers):
            for i in identifiyers:
                if isinstance(i, six.string_types):
                    if qt.QIcon.hasThemeIcon(i):
                        return qt.QIcon.fromTheme(i)
                elif isinstance(i, qt.QIcon):
                    return i
                else:
                    return style.standardIcon(i)
            return qt.QIcon()