How to use silx - 10 common examples

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 / AbstractDataFileDialog.py View on Github external
the same direction)
        """
        style = qt.QApplication.style()
        baseIcon = style.standardIcon(qt.QStyle.SP_FileDialogToParent)
        backgroundIcon = style.standardIcon(standardPixmap)
        icon = qt.QIcon()

        sizes = baseIcon.availableSizes()
        sizes = sorted(sizes, key=lambda s: s.height())
        sizes = filter(lambda s: s.height() < 100, sizes)
        sizes = list(sizes)
        if len(sizes) > 0:
            baseSize = sizes[-1]
        else:
            baseSize = baseIcon.availableSizes()[0]
        size = qt.QSize(baseSize.width(), baseSize.height() * 3 // 2)

        modes = [qt.QIcon.Normal, qt.QIcon.Disabled]
        for mode in modes:
            pixmap = qt.QPixmap(size)
            pixmap.fill(qt.Qt.transparent)
            painter = qt.QPainter(pixmap)
            painter.drawPixmap(0, 0, backgroundIcon.pixmap(baseSize, mode=mode))
            painter.drawPixmap(0, size.height() // 3, baseIcon.pixmap(baseSize, mode=mode))
            painter.end()
            icon.addPixmap(pixmap, mode=mode)

        return icon
github silx-kit / pyFAI / pyFAI / gui / dialog / Detector3dDialog.py View on Github external
pixelValues = pixelValues.astype(numpy.float)
            pixelValues[mask != 0] = numpy.float("nan")

        values = numpy.empty(shape=(vertices.shape[0]))
        values[0::4] = pixelValues
        values[1::4] = pixelValues
        values[2::4] = pixelValues
        values[3::4] = pixelValues

        plus = numpy.array([0, 1, 2, 2, 3, 0], dtype=numpy.uint32)
        indexes = (numpy.atleast_2d(4 * numpy.arange(vertices.shape[0] // 4, dtype=numpy.uint32)).T + plus).ravel()
        indexes = indexes.astype(numpy.uint32)

        colormap = self.__colormap
        if colormap is None:
            colormap = colors.Colormap(name="inferno", normalization=colors.Colormap.LOGARITHM)

        item = mesh.ColormapMesh()
        item.moveToThread(qt.QApplication.instance().thread())
        item.setData(mode="triangles",
                     position=vertices,
                     value=values,
                     indices=indexes,
                     copy=False)
        item.setColormap(colormap)
        self.__detectorItem = item
        return True
github silx-kit / silx / examples / icons.py View on Github external
# Sort together animated and non animated icons
        fix_icons = self.getAllAvailableIcons()
        animated_icons = self.getAllAvailableAnimatedIcons()
        icons = []
        icons.extend([(i, "_") for i in fix_icons])
        icons.extend([(i, "anim") for i in animated_icons])
        icons = sorted(icons)

        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 / examples / icons.py View on Github external
icons = sorted(icons)

        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 / test / colorbar.py View on Github external
legend='image5',
                           colormap=self.colormap3)
        self.plot.addImage(data=image6,
                           origin=(100, 200),
                           legend='image6',
                           colormap=self.colormap3)

    def _buildColormapEditors(self):
        self._cmpEditor = qt.QWidget(parent=self)
        self._cmpEditor.setLayout(qt.QVBoxLayout())
        self._cmpEditor.layout().addWidget(_ColormapEditor(self.colormap3))
        self._cmpEditor.layout().addWidget(_ColormapEditor(self.colormap2))
        self._cmpEditor.layout().addWidget(_ColormapEditor(self.colormap1))


class _ColormapEditor(qt.QWidget):
    """Simple colormap editor"""

    def __init__(self, colormap):
        qt.QWidget.__init__(self)
        self.setLayout(qt.QVBoxLayout())
        self._colormap = colormap
        self._buildGUI()

        self.setColormap(colormap)

        # connect GUI and colormap
        self._qcbName.currentIndexChanged.connect(self._nameChanged)
        self._qgbNorm._qrbLinear.toggled.connect(self._normalizationHaschanged)
        self._qgbNorm._qrbLog.toggled.connect(self._normalizationHaschanged)
        self._vminWidget.sigValueChanged.connect(self._vminHasChanged)
        self._vmaxWidget.sigValueChanged.connect(self._vmaxHasChanged)
github silx-kit / silx / test / colorbar.py View on Github external
self.colormap1 = Colormap.Colormap(name='green',
                                           normalization='log',
                                           vmin=None,
                                           vmax=None)
        self.plot = PlotWidget(parent=self)
        self.plot.addImage(data=image1,
                           origin=(0, 0),
                           legend='image1',
                           colormap=self.colormap1)
        self.plot.addImage(data=image2,
                           origin=(100, 0),
                           legend='image2',
                           colormap=self.colormap1)

        # red colormap
        self.colormap2 = Colormap.Colormap(name='red',
                                           normalization='linear',
                                           vmin=None,
                                           vmax=None)
        self.plot.addImage(data=image3,
                           origin=(0, 100),
                           legend='image3',
                           colormap=self.colormap2)
        self.plot.addImage(data=image4,
                           origin=(100, 100),
                           legend='image4',
                           colormap=self.colormap2)
        # gray colormap
        self.colormap3 = Colormap.Colormap(name='gray',
                                           normalization='linear',
                                           vmin=1.0,
                                           vmax=20.0)
github silx-kit / silx / silx / gui / plot / tools / roi.py View on Github external
def eventFilter(self, obj, event):
        if event.type() == qt.QEvent.Hide:
            self.quit()

        if event.type() == qt.QEvent.KeyPress:
            key = event.key()
            if (key in (qt.Qt.Key_Return, qt.Qt.Key_Enter) and
                    self.getValidationMode() in (
                        self.ValidationMode.ENTER,
                        self.ValidationMode.AUTO_ENTER)):
                # Stop on return key pressed
                self.quit()
                return True  # Stop further handling of this keys

            if (key in (qt.Qt.Key_Delete, qt.Qt.Key_Backspace) or (
                    key == qt.Qt.Key_Z and
                    event.modifiers() & qt.Qt.ControlModifier)):
                rois = self.getRois()
                if rois:  # Something to undo
                    self.removeRoi(rois[-1])
                    # Stop further handling of keys if something was undone
                    return True

        return super(InteractiveRegionOfInterestManager, self).eventFilter(obj, event)
github silx-kit / silx / examples / hdf5widget.py View on Github external
"""
        :param files_: List of HDF5 or Spec files (pathes or
            :class:`silx.io.spech5.SpecH5` or :class:`h5py.File`
            instances)
        """
        qt.QMainWindow.__init__(self)
        self.setWindowTitle("Silx HDF5 widget example")

        self.__asyncload = False
        self.__treeview = silx.gui.hdf5.Hdf5TreeView(self)
        """Silx HDF5 TreeView"""
        self.__text = qt.QTextEdit(self)
        """Widget displaying information"""

        self.__dataViewer = DataViewerFrame(self)
        vSpliter = qt.QSplitter(qt.Qt.Vertical)
        vSpliter.addWidget(self.__dataViewer)
        vSpliter.addWidget(self.__text)
        vSpliter.setSizes([10, 0])

        spliter = qt.QSplitter(self)
        spliter.addWidget(self.__treeview)
        spliter.addWidget(vSpliter)
        spliter.setStretchFactor(1, 1)

        main_panel = qt.QWidget(self)
        layout = qt.QVBoxLayout()
        layout.addWidget(spliter)
        layout.addWidget(self.createTreeViewConfigurationPanel(self, self.__treeview))
        layout.setStretchFactor(spliter, 1)
        main_panel.setLayout(layout)
github silx-kit / silx / silx / gui / widgets / FrameBrowser.py View on Github external
self.mainLayout.setContentsMargins(0, 0, 0, 0)
        self.mainLayout.setSpacing(0)
        self.firstButton = qt.QPushButton(self)
        self.firstButton.setIcon(icons.getQIcon("first"))
        self.firstButton.setIconSize(iconSize)
        self.previousButton = qt.QPushButton(self)
        self.previousButton.setIcon(icons.getQIcon("previous"))
        self.previousButton.setIconSize(iconSize)
        self._lineEdit = qt.QLineEdit(self)

        self._label = qt.QLabel(self)
        self.nextButton = qt.QPushButton(self)
        self.nextButton.setIcon(icons.getQIcon("next"))
        self.nextButton.setIconSize(iconSize)
        self.lastButton = qt.QPushButton(self)
        self.lastButton.setIcon(icons.getQIcon("last"))
        self.lastButton.setIconSize(iconSize)

        self.mainLayout.addWidget(self.firstButton)
        self.mainLayout.addWidget(self.previousButton)
        self.mainLayout.addWidget(self._lineEdit)
        self.mainLayout.addWidget(self._label)
        self.mainLayout.addWidget(self.nextButton)
        self.mainLayout.addWidget(self.lastButton)

        if n is None:
            first = qt.QSlider().minimum()
            last = qt.QSlider().maximum()
        else:
            first, last = 0, n

        self._lineEdit.setFixedWidth(self._lineEdit.fontMetrics().boundingRect('%05d' % last).width())