Beispiel #1
0
    def drawLosange(self, dc: DC, filled: bool = False):
        """
        Draw an arrow at the beginning of the line.

        Args:
            dc:         The device context
            filled:     True if the losange must be filled, False otherwise

        Note:  Losange is French for 'diamond'
        """
        pi_6 = pi / 6
        points = []
        line = self.GetSegments()
        x1, y1 = line[1]
        x2, y2 = line[0]
        a = x2 - x1
        b = y2 - y1
        if abs(a) < 0.01:  # vertical segment
            if b > 0:
                alpha = -pi / 2
            else:
                alpha = pi / 2
        else:
            if a == 0:
                if b > 0:
                    alpha = pi / 2
                else:
                    alpha = 3 * pi / 2
            else:
                alpha = atan(b / a)
        if a > 0:
            alpha += pi
        alpha1 = alpha + pi_6
        alpha2 = alpha - pi_6
        size = 8
        points.append((x2 + size * cos(alpha1), y2 + size * sin(alpha1)))
        points.append((x2, y2))
        points.append((x2 + size * cos(alpha2), y2 + size * sin(alpha2)))
        points.append((x2 + 2 * size * cos(alpha), y2 + 2 * size * sin(alpha)))
        dc.SetPen(BLACK_PEN)
        if filled:
            dc.SetBrush(BLACK_BRUSH)
        else:
            dc.SetBrush(WHITE_BRUSH)
        dc.DrawPolygon(points)
        dc.SetBrush(WHITE_BRUSH)
Beispiel #2
0
    def Draw(self, dc: DC, withChildren: bool = True):
        """
        Draw the shape.
        For a shape, only the anchors are drawn. Nothing is drawn if the
        shape is set invisible.
        For children classes, the main classes would normally call it's
        parent's Draw method, passing withChildren = False, and finally
        calling itself the DrawChildren method.

        Args:
            dc:             wxPython device context
            withChildren:   draw the children or not
        """

        if self._visible:
            dc.SetPen(self._pen)
            dc.SetBrush(self._brush)
            if withChildren:
                self.DrawChildren(dc)

        if self._selected:
            dc.SetPen(RED_PEN)
            self.DrawHandles(dc)
Beispiel #3
0
    def PaintHandle(self, dc: wx.DC, y_offset, value, left_edge, right_edge):
        pos = (value - self.min_value) * self._px_per_value + self.X_OFFSET
        dc.SetBrush(wx.BLACK_BRUSH)
        dc.DrawPolygon((
            wx.Point(pos, y_offset),
            wx.Point(pos - self.HANDLE_WIDTH / 2, y_offset + self.HANDLE_HEIGHT),
            wx.Point(pos + self.HANDLE_WIDTH / 2, y_offset + self.HANDLE_HEIGHT),
        ))

        label = "{:.3f}".format(value)
        label_width = dc.GetTextExtent(label).GetWidth()
        label_pos = pos - label_width / 2
        width = self.GetSize().x
        label_pos = max(min(width - label_width, label_pos), 0)

        if left_edge != -1:
            label_pos = max(left_edge, label_pos)
            edge = label_pos + label_width
        elif right_edge != -1:
            label_pos = min(right_edge - label_width, label_pos)
            edge = label_pos

        dc.DrawText(label, label_pos, y_offset + self.HANDLE_HEIGHT + self.LABEL_PADDING)
        return edge