Ejemplo n.º 1
0
 def __init__(self, parent=None):
     QTabBar.__init__(self, parent)
     self.setAcceptDrops(True)
     self.setElideMode(Qt.ElideRight)
     self.setSelectionBehaviorOnRemove(QTabBar.SelectLeftTab)
     self.setMovable(False)
     self._dragInitiated = False
     self._dragDroppedPos = QPoint()
     self._dragStartPos = QPoint()
Ejemplo n.º 2
0
 def __init__(self, x, y, size=40, parent=None, scene=None):
     self._origin = QPoint(x, y)
     self._size = size
     self._radius = size / 2
     if not self._color:
         self._color = QColor('white')
     QGraphicsEllipseItem.__init__(self, QRectF(-QPoint(size, size),
                                   QSizeF(2 * size, 2 * size)), parent)
     if not parent and scene:
         scene.addItem(self)
     self.setPos(x, y)
     self.setBrush(QBrush(self._color))
Ejemplo n.º 3
0
 def paintEvent(self, event):
     painter = QPainter(self)
     mode = QIcon.Active if self.isDown() else QIcon.Normal
     pixmap = self.icon.pixmap(self._size, mode)
     painter.drawPixmap(
         QPoint(0, 0), pixmap.scaled(event.rect().size(),
                                     Qt.KeepAspectRatio))
Ejemplo n.º 4
0
 def __init__(self, x, y, size=60, width=10, parent=None, scene=None):
     self._width = width
     s = size + width / 2
     QGraphicsEllipseItem.__init__(self, QRectF(-QPoint(s, s),
                                   QSizeF(2 * s, 2 * s)), parent)
     self.setBrush(QBrush(statuscolor[status.OK]))
     if not parent and scene:
         scene.addItem(self)
     self.setPos(x, y)
     self.setState(status.OK)
Ejemplo n.º 5
0
    def mouseMoveEvent(self, event):
        if not (event.buttons() & Qt.LeftButton):
            return
        if not self._dragStartPos.isNull() and \
           self.tabAt(self._dragStartPos) != -1 and \
           (event.pos() - self._dragStartPos).manhattanLength() \
           < QApplication.startDragDistance():
            self._dragInitiated = True
        if (event.buttons() == Qt.LeftButton) and self._dragInitiated and \
           not self.geometry().contains(event.pos()):
            finishMoveEvent = QMouseEvent(QEvent.MouseMove, event.pos(),
                                          Qt.NoButton, Qt.NoButton,
                                          Qt.NoModifier)
            QTabBar.mouseMoveEvent(self, finishMoveEvent)

            drag = QDrag(self)
            mimedata = QMimeData()
            mimedata.setData('action', b'application/tab-detach')
            drag.setMimeData(mimedata)

            if QT_VER == 4:
                pixmap = QPixmap.grabWidget(self.parentWidget().currentWidget())
            else:
                pixmap = self.parentWidget().currentWidget().grab()
            pixmap = pixmap.scaled(640, 480, Qt.KeepAspectRatio)
            drag.setPixmap(pixmap)
            drag.setDragCursor(QPixmap(), Qt.LinkAction)

            dragged = drag.exec_(Qt.MoveAction)
            if dragged == Qt.IgnoreAction:
                # moved outside of tab widget
                event.accept()
                self.tabDetached.emit(self.tabAt(self._dragStartPos),
                                      QCursor.pos())
            elif dragged == Qt.MoveAction:
                # moved inside of tab widget
                if not self._dragDroppedPos.isNull():
                    event.accept()
                    self.tabMoved.emit(self.tabAt(self._dragStartPos),
                                       self.tabAt(self._dragDroppedPos))
                    self._dragDroppedPos = QPoint()
        else:
            QTabBar.mouseMoveEvent(self, event)
Ejemplo n.º 6
0
 def readWKT(self, astr):
     try:
         stp = "POLYGON"
         rings = astr.find(stp)
         oi = astr[rings + len(stp):]  #oi = outerinner
         mo1 = re.search(r'\(([^()]*)\)', oi)  # first object only which is outer ring
         strouter = oi[mo1.regs[1][0]:mo1.regs[1][1]]
         strpts = strouter.split(',')
         tmpouter = list()
         for strpt in strpts:
             strxy = strpt.split(' ')
             p = QPoint(int(strxy[0]), int(strxy[1]))
             tmpouter.append(p)
         self.outer = tmpouter
     except Exception:
         pass
Ejemplo n.º 7
0
 def on_roiItemClicked(self, event):
     if event.getButtons() & MouseEvent.RIGHT_BUTTON:
         if isinstance(event.roi.reference, FitResult):
             menu = QMenu(self)
             actionClipboard = QAction("Copy fit values to clipboard", menu)
             menu.addAction(actionClipboard)
             p0dc = event.getDC()
             selectedItem = menu.exec_(
                 self.mapToGlobal(QPoint(p0dc.x, p0dc.y)))
             if selectedItem == actionClipboard:
                 res = event.roi.reference
                 text = '\n'.join(
                     (n + '\t' if n else '\t') +
                     (v + '\t' if isinstance(v, string_types) else '%g\t' %
                      v) +
                     (dv if isinstance(dv, string_types) else '%g' % dv)
                     for (n, v, dv) in res.label_contents)
                 QApplication.clipboard().setText(text)
Ejemplo n.º 8
0
 def on_actionUser_triggered(self):
     w = self.toolBarRight.widgetForAction(self.actionUser)
     self.dropdown.popup(w.mapToGlobal(QPoint(0, w.height())))
Ejemplo n.º 9
0
 def on_actionROI_triggered(self):
     w = self.toolbar.widgetForAction(self.actionROI)
     self.actionROI.menu().popup(w.mapToGlobal(QPoint(0, w.height())))
Ejemplo n.º 10
0
 def on_actionColormap_triggered(self):
     w = self.toolbar.widgetForAction(self.actionColormap)
     m = self.actionColormap.menu()
     if m:
         m.popup(w.mapToGlobal(QPoint(0, w.height())))
Ejemplo n.º 11
0
    def paintEvent(self, event):
        s = self.size()
        w, h = s.width(), s.height()
        # calculate the maximum length if all elements in a line
        maxL = self.values['Lms'] + self.values['Lsa'] + self.values['Lad']
        # add the size of the Monochromator and detector
        scale = min((w / 2 - anaradius) / float(maxL),
                    (h - monoradius - anaradius) / float(maxL))

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        painter.setPen(QColor('black'))
        painter.setBrush(_white)
        painter.drawRect(0, 0, w, h)

        # determine positions

        # incoming beam
        if self.values['mth'] < 0:
            bx, by = 3, h - (2 + monoradius)
        else:
            bx, by = 3, 2 + monoradius
        # monochromator
        mx, my = w / 2., by

        # sample
        L = self.values['Lms'] * scale  # length is in mm -- scale down a bit
        mttangle = self.values['mtt'] * deg2rad
        mttangle_t = self.targets['mtt'] * deg2rad
        if self.values['mth'] < 0:
            mttangle = -mttangle
            mttangle_t = -mttangle_t

        sx, sy = mx + L * cos(mttangle), my - L * sin(mttangle)
        sx_t, sy_t = mx + L * cos(mttangle_t), my - L * sin(mttangle_t)

        # analyzer
        L = self.values['Lsa'] * scale  # length is in mm -- scale down a bit
        sttangle = self.values['stt'] * deg2rad
        sttangle_t = self.targets['stt'] * deg2rad
        if self.values['sth'] < 0:
            sttangle = mttangle - sttangle
            sttangle_t = mttangle_t - sttangle_t
        else:
            sttangle = mttangle + sttangle
            sttangle_t = mttangle_t + sttangle_t
        ax, ay = sx + L * cos(sttangle), sy - L * sin(sttangle)
        ax_t, ay_t = sx_t + L * cos(sttangle_t), sy_t - L * sin(sttangle_t)

        # detector
        L = self.values['Lad'] * scale  # length is in mm -- scale down a bit
        attangle = self.values['att'] * deg2rad
        attangle_t = self.targets['att'] * deg2rad
        if self.values['ath'] < 0:
            attangle = sttangle - attangle
            attangle_t = sttangle_t - attangle_t
        else:
            attangle = sttangle + attangle
            attangle_t = sttangle_t + attangle_t

        dx, dy = ax + L * cos(attangle), ay - L * sin(attangle)
        dx_t, dy_t = ax_t + L * cos(attangle_t), ay_t - L * sin(attangle_t)

        # draw table "halos"
        painter.setPen(nopen)
        if self.status['mth'] != OK:
            painter.setBrush(statusbrush[self.status['mth']])
            painter.drawEllipse(QPoint(mx, my), monoradius + halowidth,
                                monoradius + halowidth)
        elif self.status['mtt'] != OK:
            painter.setBrush(statusbrush[self.status['mtt']])
            painter.drawEllipse(QPoint(mx, my), monoradius + halowidth,
                                monoradius + halowidth)
        if self.status['sth'] != OK:
            painter.setBrush(statusbrush[self.status['sth']])
            painter.drawEllipse(QPoint(sx, sy), sampleradius + halowidth,
                                sampleradius + halowidth)
        elif self.status['stt'] != OK:
            painter.setBrush(statusbrush[self.status['stt']])
            painter.drawEllipse(QPoint(sx, sy), sampleradius + halowidth,
                                sampleradius + halowidth)
        if self.status['ath'] != OK:
            painter.setBrush(statusbrush[self.status['ath']])
            painter.drawEllipse(QPoint(ax, ay), anaradius + halowidth,
                                anaradius + halowidth)
        elif self.status['att'] != OK:
            painter.setBrush(statusbrush[self.status['att']])
            painter.drawEllipse(QPoint(ax, ay), anaradius + halowidth,
                                anaradius + halowidth)

        # draw table targets
        painter.setPen(targetpen)
        painter.setBrush(_nobrush)
        painter.drawEllipse(QPoint(sx_t, sy_t), sampleradius - .5,
                            sampleradius - .5)
        painter.drawEllipse(QPoint(ax_t, ay_t), anaradius - .5, anaradius - .5)
        painter.drawEllipse(QPoint(dx_t, dy_t), detradius - .5, detradius - .5)

        # draw the tables
        painter.setPen(defaultpen)
        painter.setBrush(monotablebrush)
        painter.drawEllipse(QPoint(mx, my), monoradius, monoradius)
        painter.setBrush(sampletablebrush)
        painter.drawEllipse(QPoint(sx, sy), sampleradius, sampleradius)
        painter.setBrush(anatablebrush)
        painter.drawEllipse(QPoint(ax, ay), anaradius, anaradius)
        painter.setBrush(dettablebrush)
        painter.drawEllipse(QPoint(dx, dy), detradius, detradius)
        painter.setBrush(_white)
        painter.setPen(nopen)
        painter.drawEllipse(QPoint(mx, my), monoradius / 2, monoradius / 2)
        # painter.drawEllipse(QPoint(sx, sy), 20, 20)
        painter.drawEllipse(QPoint(ax, ay), anaradius / 2, anaradius / 2)
        # painter.drawEllipse(QPoint(dx, dy), 20, 20)

        beam = QPolygonF([
            QPointF(bx, by),
            QPointF(mx, my),
            QPointF(sx, sy),
            QPointF(ax, ay),
            QPointF(dx, dy)
        ])
        painter.setPen(beambackgroundpen)
        painter.drawPolyline(beam)

        # draw mono crystals
        painter.setPen(monopen)
        mthangle = -self.values['mth'] * deg2rad
        painter.drawLine(mx + 10 * cos(mthangle), my - 10 * sin(mthangle),
                         mx - 10 * cos(mthangle), my + 10 * sin(mthangle))

        # draw ana crystals
        athangle = -self.values['ath'] * deg2rad
        alpha = athangle + sttangle
        # TODO if the angle is too small then it could be that the ath value
        # must be turned by 90 deg (PANDA: chair setup) ??
        if attangle < 0 and alpha < attangle:
            alpha += pi_2
        painter.drawLine(ax + 10 * cos(alpha), ay - 10 * sin(alpha),
                         ax - 10 * cos(alpha), ay + 10 * sin(alpha))

        # draw sample
        painter.setPen(samplepen)
        painter.setBrush(samplebrush)
        sthangle = self.values['sth'] * deg2rad
        alpha = sthangle + mttangle + pi_4
        # painter.drawRect(sx - 5, sy - 5, 10, 10)
        sz = 10
        painter.drawPolygon(
            QPolygonF([
                QPointF(sx + sz * cos(alpha), sy - sz * sin(alpha)),
                QPointF(sx + sz * cos(alpha + pi_2),
                        sy - sz * sin(alpha + pi_2)),
                QPointF(sx - sz * cos(alpha), sy + sz * sin(alpha)),
                QPointF(sx - sz * cos(alpha + pi_2),
                        sy + sz * sin(alpha + pi_2)),
                QPointF(sx + sz * cos(alpha), sy - sz * sin(alpha))
            ]))

        painter.setPen(samplecoordpen)
        sr = sampleradius
        for angle in [alpha - pi_4, alpha - 3 * pi_4]:
            painter.drawLine(sx - sr * cos(angle), sy + sr * sin(angle),
                             sx + sr * cos(angle), sy - sr * sin(angle))

        # draw detector
        painter.setPen(monopen)
        painter.setBrush(_white)
        painter.drawEllipse(QPoint(dx, dy), 4, 4)

        # draw beam
        painter.setPen(beampen)
        painter.drawPolyline(beam)
Ejemplo n.º 12
0
 def mousePressEvent(self, event):
     if event.button() == Qt.LeftButton:
         self._dragStartPos = event.pos()
     self._dragInitiated = False
     self._dragDroppedPos = QPoint()
     QTabBar.mousePressEvent(self, event)
Ejemplo n.º 13
0
class TearOffTabBar(QTabBar):

    tabDetached = pyqtSignal(object, object)
    tabMoved = pyqtSignal(object, object)

    def __init__(self, parent=None):
        QTabBar.__init__(self, parent)
        self.setAcceptDrops(True)
        self.setElideMode(Qt.ElideRight)
        self.setSelectionBehaviorOnRemove(QTabBar.SelectLeftTab)
        self.setMovable(False)
        self._dragInitiated = False
        self._dragDroppedPos = QPoint()
        self._dragStartPos = QPoint()

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self._dragStartPos = event.pos()
        self._dragInitiated = False
        self._dragDroppedPos = QPoint()
        QTabBar.mousePressEvent(self, event)

    def mouseMoveEvent(self, event):
        if not (event.buttons() & Qt.LeftButton):
            return
        if not self._dragStartPos.isNull() and \
           self.tabAt(self._dragStartPos) != -1 and \
           (event.pos() - self._dragStartPos).manhattanLength() \
           < QApplication.startDragDistance():
            self._dragInitiated = True
        if (event.buttons() == Qt.LeftButton) and self._dragInitiated and \
           not self.geometry().contains(event.pos()):
            finishMoveEvent = QMouseEvent(QEvent.MouseMove, event.pos(),
                                          Qt.NoButton, Qt.NoButton,
                                          Qt.NoModifier)
            QTabBar.mouseMoveEvent(self, finishMoveEvent)

            drag = QDrag(self)
            mimedata = QMimeData()
            mimedata.setData('action', b'application/tab-detach')
            drag.setMimeData(mimedata)

            pixmap = self.parentWidget().currentWidget().grab()
            pixmap = pixmap.scaled(640, 480, Qt.KeepAspectRatio)
            drag.setPixmap(pixmap)
            drag.setDragCursor(QPixmap(), Qt.LinkAction)

            dragged = drag.exec_(Qt.MoveAction)
            if dragged == Qt.IgnoreAction:
                # moved outside of tab widget
                event.accept()
                self.tabDetached.emit(self.tabAt(self._dragStartPos),
                                      QCursor.pos())
            elif dragged == Qt.MoveAction:
                # moved inside of tab widget
                if not self._dragDroppedPos.isNull():
                    event.accept()
                    self.tabMoved.emit(self.tabAt(self._dragStartPos),
                                       self.tabAt(self._dragDroppedPos))
                    self._dragDroppedPos = QPoint()
        else:
            QTabBar.mouseMoveEvent(self, event)

    def dragEnterEvent(self, event):
        mimedata = event.mimeData()
        formats = mimedata.formats()
        if 'action' in formats and \
           mimedata.data('action') == 'application/tab-detach':
            event.acceptProposedAction()
        QTabBar.dragEnterEvent(self, event)

    def dropEvent(self, event):
        self._dragDroppedPos = event.pos()
        event.acceptProposedAction()
        QTabBar.dropEvent(self, event)