Example #1
0
    def __showBarBnClicked(self):
        style = Qt.QApplication.style()

        optionsBase = self.__optionsBase
        optionsBaseB = self.__optionsBaseB
        geom = self.centralWidget().geometry()

        hiddenGeom = Qt.QPoint(0 - optionsBaseB.width(),
                               geom.height() - optionsBaseB.height())
        visibleGeom = Qt.QPoint(0, geom.height() - optionsBaseB.height())

        if self.__hidden:
            icon = Qt.QStyle.SP_ArrowLeft
            startVal = hiddenGeom
            endVal = visibleGeom
        else:
            icon = Qt.QStyle.SP_ArrowRight
            startVal = visibleGeom
            endVal = hiddenGeom

        icon = style.standardIcon(icon)
        self.sender().setIcon(icon)

        self.__hidden = not self.__hidden

        animation = Qt.QPropertyAnimation(optionsBase, 'pos', self)
        animation.setDuration(300)
        animation.setStartValue(startVal)
        animation.setEndValue(endVal)
        animation.start(Qt.QAbstractAnimation.DeleteWhenStopped)
Example #2
0
    def setProfile(self, x, y, colormap):
        """

        :param profile: a 1D numpy array
        :param colormap: an XsocsPlot2DColormap instance
        :param nColors: number of colors
        :return:
        """
        assert x.ndim == 1
        assert y.ndim == 1

        self.__colormap = colormap
        self.__pixmap = pixmap = Qt.QPixmap(Qt.QSize(x.size,
                                                     self._pimapHeight))
        pixmap.fill()

        xMin = x.min()
        xMax = x.max()

        colors = _applyColormap(colormap, x)
        profileValues = (y * (1.0 * self._pimapHeight / y.max()))
        points = [Qt.QPointF(0, 0)]
        points.extend(
            [Qt.QPointF(idx, val) for idx, val in enumerate(profileValues)])
        points.extend([Qt.QPointF(colormap.nColors - 1, 0)])
        poly = Qt.QPolygonF(points)

        if colormap.minVal is not None:
            lineMin = ((colormap.minVal - xMin) * (pixmap.width() - 1) /
                       (xMax - xMin))
        else:
            lineMin = None

        if colormap.maxVal is not None:
            lineMax = ((colormap.maxVal - xMin) * (pixmap.width() - 1) /
                       (xMax - xMin))
        else:
            lineMax = None

        self.__lineMin = lineMin
        self.__lineMax = lineMax

        gradient = Qt.QLinearGradient(Qt.QPoint(0, 0),
                                      Qt.QPoint(colormap.nColors - 1, 0))
        for idx, color in enumerate(colors):
            qColor = Qt.QColor.fromRgbF(*color)
            gradient.setColorAt(idx / (1.0 * (colormap.nColors - 1)), qColor)

        painter = Qt.QPainter(pixmap)
        painter.save()
        painter.scale(1, -1.)
        painter.translate(Qt.QPointF(0., -1.0 * self._pimapHeight))
        brush = Qt.QBrush(gradient)
        painter.setBrush(brush)
        painter.setPen(Qt.QPen(Qt.Qt.NoPen))
        painter.drawPolygon(poly)
        painter.restore()
        painter.end()
        self.update()
Example #3
0
    def mouseMove(self, widget, pos=None, delay=-1):
        """Simulate moving the mouse.

        See QTest.mouseMove for details.
        """
        pos = qt.QPoint(pos[0], pos[1]) if pos is not None else qt.QPoint()
        QTest.mouseMove(widget, pos, delay)
        self.qWait(20)
Example #4
0
    def mouseRelease(self, widget, button, modifier=None, pos=None, delay=-1):
        """Simulate releasing a mouse button.

        See QTest.mouseRelease for details.
        """
        if modifier is None:
            modifier = qt.Qt.KeyboardModifiers()
        pos = qt.QPoint(pos[0], pos[1]) if pos is not None else qt.QPoint()
        QTest.mouseRelease(widget, button, modifier, pos, delay)
        self.qWait(20)
    def mouseDClick(self, widget, button, modifier=None, pos=None, delay=-1):
        """Simulate double clicking a mouse button.

        See QTest.mouseDClick for details.
        """
        if modifier is None:
            modifier = qt.Qt.KeyboardModifiers()
        pos = qt.QPoint(int(pos[0]), int(
            pos[1])) if pos is not None else qt.QPoint()
        QTest.mouseDClick(widget, button, modifier, pos, delay)
        self.qWait(20)
Example #6
0
    def __moveOptionBar(self):
        optionsBase = self.__optionsBase
        optionsBaseB = self.__optionsBaseB
        geom = self.centralWidget().geometry()

        if self.__hidden:
            newPos = Qt.QPoint(0 - optionsBaseB.width(),
                               geom.height() - optionsBase.height())
        else:
            newPos = Qt.QPoint(0, geom.height() - optionsBase.height())

        if optionsBase.pos() != newPos:
            optionsBase.move(newPos)
Example #7
0
 def icon(self):
     pixmap = qt.QPixmap(2, 2)
     painter = qt.QPainter(pixmap)
     painter.setPen(qt.QColor(255, 0, 0))
     painter.drawPoint(qt.QPoint(0, 0))
     painter.setPen(qt.QColor(255, 255, 0))
     painter.drawPoint(qt.QPoint(1, 0))
     painter.setPen(qt.QColor(0, 255, 0))
     painter.drawPoint(qt.QPoint(0, 1))
     painter.setPen(qt.QColor(0, 255, 255))
     painter.drawPoint(qt.QPoint(1, 1))
     painter.end()
     pixmap = pixmap.scaled(32, 32, qt.Qt.IgnoreAspectRatio, qt.Qt.FastTransformation)
     return qt.QIcon(pixmap)
Example #8
0
    def restoreSettings(self, settings):
        """Restore the window settings using this settings object

        :param qt.QSettings settings: Initialized settings
        """
        settings.beginGroup("mainwindow")
        size = settings.value("size", qt.QSize(640, 480))
        pos = settings.value("pos", qt.QPoint())
        isFullScreen = settings.value("full-screen", False)
        if not isinstance(isFullScreen, bool):
            isFullScreen = False
        settings.endGroup()

        settings.beginGroup("mainlayout")
        try:
            data = settings.value("spliter")
            data = [int(d) for d in data]
            self.__spliter.setSizes(data)
        except Exception:
            _logger.debug("Backtrace", exc_info=True)
        settings.endGroup()

        if not pos.isNull():
            self.move(pos)
        if not size.isNull():
            self.resize(size)
        if isFullScreen:
            self.showFullScreen()
Example #9
0
 def __readSettings(self):
     settings = Qt.QSettings(_COMPANY_NAME, _APP_NAME)
     settings.beginGroup("gui")
     self.resize(settings.value("MainWindow/size", Qt.QSize(400, 400)))
     self.move(settings.value("MainWindow/pos", Qt.QPoint(200, 200)))
     self.restoreState(settings.value("MainWindow/state", Qt.QByteArray()))
     settings.endGroup()
Example #10
0
    def restoreWindowLocationSettings(self, groupName, window):
        """Restore the window settings using this settings object

        :param qt.QSettings settings: Initialized settings
        """
        settings = self.__settings
        if settings is None:
            _logger.debug("Settings not set")
            return

        settings.beginGroup(groupName)
        size = settings.value("size", qt.QSize())
        pos = settings.value("pos", qt.QPoint())
        isFullScreen = settings.value("full-screen", False)
        try:
            if not isinstance(isFullScreen, bool):
                isFullScreen = utils.stringToBool(isFullScreen)
        except ValueError:
            isFullScreen = False
        settings.endGroup()

        if not pos.isNull():
            window.move(pos)
        if not size.isNull():
            window.resize(size)
        if isFullScreen:
            window.showFullScreen()
Example #11
0
    def __createDropConstraint(self):
        popup = ConstraintsPopup(self.__quantity)
        popup.setWindowFlags(qt.Qt.Popup)
        popup.setAttribute(qt.Qt.WA_DeleteOnClose)
        eventutils.createCloseSignal(popup)
        popup.sigClosed.connect(self.__constraintsPopupClosed)
        self.__constraintPopup = popup

        popup.setLabel(self.__label)
        popup.fromConstaints(self.__constraintsModel)
        popup.setDefaultConstraints(self.__defaultConstraintsModel)
        popup.setUnits(*self.__units)

        popup.updateGeometry()
        # force the update of the geometry
        popup.show()

        popupParent = self.__quantity
        pos = popupParent.mapToGlobal(popupParent.rect().center())
        pos = pos - popup.labelCenter()

        # Make sure the popup is fully inside the screen
        # FIXME: It have to be tested with multi screen
        wid = self.__quantity.winId()
        window = qt.QWindow.fromWinId(wid)
        screen = window.screen()
        screen = screen.virtualGeometry()
        rect = popup.rect()
        rect.moveTopLeft(pos)
        if not screen.contains(rect):
            pos -= qt.QPoint(rect.right() - screen.right(), 0)

        popup.move(pos)
        popup.show()
        return popup
Example #12
0
 def _checkMouseMove(self, widget, pos):
     """Returns true if the position differe from the current position of
     the cursor"""
     pos = qt.QPoint(pos[0], pos[1])
     pos = widget.mapTo(widget.window(), pos)
     willMove = pos != self.__mousePos
     self.__mousePos = pos
     return willMove
Example #13
0
    def restoreSettings(self, settings):
        """Restore the window settings using this settings object

        :param qt.QSettings settings: Initialized settings
        """
        settings.beginGroup("mainwindow")
        size = settings.value("size", qt.QSize(640, 480))
        pos = settings.value("pos", qt.QPoint())
        isFullScreen = settings.value("full-screen", False)
        try:
            if not isinstance(isFullScreen, bool):
                isFullScreen = utils.stringToBool(isFullScreen)
        except ValueError:
            isFullScreen = False
        settings.endGroup()

        settings.beginGroup("mainlayout")
        try:
            data = settings.value("spliter")
            data = [int(d) for d in data]
            self.__splitter.setSizes(data)
        except Exception:
            _logger.debug("Backtrace", exc_info=True)
        try:
            data = settings.value("spliter2")
            data = [int(d) for d in data]
            self.__splitter2.setSizes(data)
        except Exception:
            _logger.debug("Backtrace", exc_info=True)
        isVisible = settings.value("custom-nxdata-window-visible", False)
        try:
            if not isinstance(isVisible, bool):
                isVisible = utils.stringToBool(isVisible)
        except ValueError:
            isVisible = False
        self.__customNxdataWindow.setVisible(isVisible)
        self._displayCustomNxdataWindow.setChecked(isVisible)

        settings.endGroup()

        settings.beginGroup("content")
        isSorted = settings.value("is-sorted", True)
        try:
            if not isinstance(isSorted, bool):
                isSorted = utils.stringToBool(isSorted)
        except ValueError:
            isSorted = True
        self.setContentSorted(isSorted)
        settings.endGroup()

        if not pos.isNull():
            self.move(pos)
        if not size.isNull():
            self.resize(size)
        if isFullScreen:
            self.showFullScreen()
Example #14
0
    def _haveMplEvent(self, widget, pos):
        """Check if the widget at this position is a matplotlib widget."""
        if isinstance(pos, qt.QPoint):
            pass
        else:
            pos = qt.QPoint(pos[0], pos[1])
        pos = widget.mapTo(widget.window(), pos)
        target = widget.window().childAt(pos)

        # Check if the target is a MPL container
        backend = target
        if hasattr(target, "_backend"):
            backend = target._backend
        haveEvent = isinstance(backend, BackendMatplotlibQt)
        return haveEvent
Example #15
0
def createProcessingWidgetOverlay(parent):
    """Create a widget overlay to show that the application is processing data
    to update the plot.

    :param qt.QWidget widget: Widget containing the overlay
    :rtype: qt.QWidget
    """
    if hasattr(parent, "centralWidget"):
        parent = parent.centralWidget()
    button = WaitingPushButton(parent)
    button.setWaiting(True)
    button.setText("Processing...")
    button.setDown(True)
    position = parent.size()
    size = button.sizeHint()
    position = (position - size) / 2
    rect = qt.QRect(qt.QPoint(position.width(), position.height()), size)
    button.setGeometry(rect)
    button.setVisible(True)
    return button
Example #16
0
 def moveCenterTo(window, center):
     half = window.size() * 0.5
     half = qt.QPoint(half.width(), half.height())
     corner = center - half
     window.move(corner)
Example #17
0
 def testContextMenu(self):
     view = hdf5.Hdf5TreeView()
     view._createContextMenu(qt.QPoint(0, 0))