Exemplo n.º 1
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setBrush(QBrush(self.color))
        painter.setRenderHint(QPainter.Antialiasing)

        fontscale = float(self._scale)
        h = self.props['height'] * fontscale
        w = self.props['width'] * fontscale
        posscale = (w - 120) / self.props['posscale']

        if self.props['name']:
            painter.setFont(self.font())
            painter.drawText(5, 0, w, fontscale * 2.5, Qt.AlignCenter,
                             self.props['name'])
            yoff = fontscale * 2.5
        else:
            yoff = 0

        painter.setPen(self.color)
        painter.drawEllipse(5, 5 + yoff, 50, h)
        painter.drawRect(30, 5 + yoff, w - 50, h)
        painter.setPen(QColor('black'))
        painter.drawArc(5, 5 + yoff, 50, h, 1440, 2880)
        painter.drawLine(30, 5 + yoff, w - 25, 5 + yoff)
        painter.drawLine(30, 5 + yoff + h, w - 25, 5 + yoff + h)
        painter.drawEllipse(w - 45, 5 + yoff, 50, h)

        # draw Detector 1
        minx = 0
        pos_val = self._curval[0]
        if pos_val is not None:
            pos_status = self._curstatus[0]
            pos_str = self._curstr[0]
            shift_val = self._curval[1]
            shift_status = self._curstatus[1]
            shift_str = self._curstr[1]
            if shift_val > 0:
                shift_str += ' ↓'
            elif shift_val < 0:
                shift_str += ' ↑'
            # Not used at the moment, prepared for later use
            tilt_val = self._curval[2]
            tilt_status = self._curstatus[2]
            tilt_str = self._curstr[2]
            if tilt_str.endswith('deg'):
                tilt_str = tilt_str[:-3] + '°'

            stat = max(pos_status, shift_status, tilt_status)
            painter.setBrush(statusbrush[stat])
            # tf = QTransform()
            # tf.rotate(tilt_val)
            painter.resetTransform()
            painter.translate(60 + pos_val * posscale + fontscale / 2.,
                              15 + yoff + shift_val * posscale + (h - 20) / 2.)
            painter.rotate(-tilt_val)
            painter.drawRect(-fontscale / 2., -(h - 20) / 2., fontscale,
                             h - 20)  # XXX tilt ???
            painter.resetTransform()
            painter.setFont(self.valueFont)
            painter.drawText(
                60 + pos_val * posscale - 10.5 * fontscale,
                -5 + yoff + h - fontscale,  # + (shift_val - 4) * posscale,
                9.5 * fontscale,
                2 * fontscale,
                Qt.AlignRight,
                tilt_str)
            painter.drawText(
                60 + pos_val * posscale - 6.5 * fontscale,
                yoff + fontscale,  # + (shift_val - 4) * posscale,
                9.5 * fontscale,
                2 * fontscale,
                Qt.AlignLeft,
                shift_str)
            minx = max(minx, 60 + pos_val * posscale + 5 - 4 * fontscale)
            painter.drawText(minx, h + 10 + yoff, 8 * fontscale, 30,
                             Qt.AlignCenter, pos_str)
            minx = minx + 8 * fontscale
Exemplo n.º 2
0
    def paintEvent(self, event):
        painter = QPainter(self)
        rect = painter.window()
        dia = min(rect.width(), rect.height()) - 40
        if dia <= 0:
            return
        dia_in = int(dia * 4/9.)

        painter.setPen(self.p_black)
        painter.setWindow(-dia/2, -dia/2, dia, dia)
        v = painter.viewport()
        painter.setViewport(v.left() + (v.width() - dia)/2,
                            v.top() + (v.height() - dia)/2,
                            dia, dia)

        # outer circle
        painter.setBrush(self.br_back)
        painter.drawEllipse(-dia/2, -dia/2, dia, dia)
        # incoming beam
        painter.setBrush(self.br_empty)
        painter.drawPie(-dia/2, -dia/2, dia, dia,
                        16*(90 - IN_WIDTH/2), 16*IN_WIDTH)

        painter.setBrush(self.br_seg)
        start = IN_WIDTH / 2 + 90
        for _ in range(MAX_SEGS - self.values[4]):
            painter.drawPie(-dia/2, -dia/2, dia, dia, 16*start, 16*SEG_ANGLE)
            start += SEG_ANGLE

        painter.setBrush(self.br_empty)
        painter.drawPie(-dia/2, -dia/2, dia, dia, 16*start, 16*OUT_WIDTH)

        painter.setBrush(self.br_seg)
        start = -IN_WIDTH / 2 + 90
        for _ in range(self.values[4]):
            painter.drawPie(-dia/2, -dia/2, dia, dia, 16*start, -16*SEG_ANGLE)
            start -= SEG_ANGLE

        # inner circle
        painter.drawEllipse(-dia_in/2, -dia_in/2, dia_in, dia_in)

        # outgoing beam (mtt angle)
        painter.drawLine(0, -dia/2, 0, 0)
        painter.rotate(self.values[3])
        painter.drawLine(0, 0, 0, dia/2)
        painter.rotate(-self.values[3])

        # mobil arm angle
        painter.setPen(self.p_red)
        painter.rotate(self.values[2])
        painter.drawLine(0, 0, 0, -(dia + dia_in)/4)
        painter.rotate(-self.values[2])
        painter.setPen(self.p_black)

        # switches
        swvals = self.values[0] | self.values[1] << 16
        for (bit, phi, r, talign, text) in SWITCHES:
            on = swvals & (1 << bit) != 0
            r = (r / 1800) * dia
            posx = r * cos(radians(phi - 90))
            posy = r * sin(radians(phi - 90))
            painter.setBrush(self.br_led[on])
            painter.drawEllipse(posx - 5, posy - 5, 10, 10)
            if talign == 1:
                painter.drawText(posx - 210, posy - 5, 200, 20,
                                 Qt.AlignRight | Qt.AlignTop, text)
            elif talign == 2:
                painter.drawText(posx + 10, posy - 5, 200, 20,
                                 Qt.AlignLeft | Qt.AlignTop, text)
            else:
                painter.drawText(posx - 100, posy - 20, 200, 20,
                                 Qt.AlignHCenter | Qt.AlignTop, text)