Ejemplo n.º 1
0
    def split(self, text: str, dc: DC, textWidth: int) -> List[str]:
        """
        Split the `text` into lines that fit into `textWidth` pixels.

        Args:
            text:       The text to split
            dc:         Device Context
            textWidth:  The width of the text in pixels

        Returns:
            A list of strings that are no wider than the input pixel `width`
        """
        splitLines: List[str] = text.splitlines()
        newLines:   List[str] = []

        for line in splitLines:
            words:     List[str] = line.split()
            lineWidth: int       = 0
            newLine:   str       = ""
            for word in words:
                word: str = f'{word} '

                extentSize: Tuple[int, int] = dc.GetTextExtent(word)        # width, height
                wordWidth:  int             = extentSize[0]
                if lineWidth + wordWidth <= textWidth:
                    newLine = f'{newLine}{word}'
                    lineWidth += wordWidth
                else:
                    newLines.append(newLine[:-1])   # remove last space
                    newLine = word
                    lineWidth = wordWidth

            newLines.append(newLine[:-1])

        return newLines
Ejemplo n.º 2
0
    def Draw(self, dc: DC, withChildren: bool = False):
        """
        Draw the actor.
        @param  dc : Device context
        @param withChildren Draw the children or not

        @since 1.0
        @author Philippe Waelti <*****@*****.**>
        """
        OglObject.Draw(self, dc)
        # Get current font
        dc.SetFont(self._defaultFont)

        # Gets the minimum bounding box for the shape
        width, height = self.GetSize()

        # Calculate the top center of the shape
        x, y = self.GetPosition()

        # drawing is restricted in the specified region of the device
        dc.SetClippingRegion(x, y, width, height)

        # Our sweet actor size
        actorWidth = width
        actorHeight = 0.8 * (height - 2.0 * MARGIN)  # 80 % of total height
        sizer = min(actorHeight, actorWidth)

        # Draw our actor head
        centerX = x + width // 2
        centerY = y + height // 2

        x = centerX - 0.2 * sizer
        y += MARGIN
        dc.DrawEllipse(x, y, 0.4 * sizer, 0.4 * sizer)

        # Draw body and arms
        x = centerX
        y += 0.4 * sizer
        dc.DrawLine(x, y, x, y + 0.3 * actorHeight)
        dc.DrawLine(x - 0.25 * actorWidth, y + 0.15 * actorHeight,
                    x + 0.25 * actorWidth, y + 0.15 * actorHeight)

        # And the feet
        y += 0.3 * actorHeight
        dc.DrawLine(x, y, x - 0.25 * actorWidth, y + 0.3 * actorHeight)
        dc.DrawLine(x, y, x + 0.25 * actorWidth, y + 0.3 * actorHeight)

        # Draw our buddy name
        textWidth, textHeight = dc.GetTextExtent(
            self.getPyutObject().getName())
        y = centerY + 0.5 * height - MARGIN - 0.1 * actorHeight
        dc.DrawText(self.getPyutObject().getName(), x - 0.5 * textWidth, y)
        dc.DestroyClippingRegion()
Ejemplo n.º 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
Ejemplo n.º 4
0
    def Draw(self, dc: DC, withChildren: bool = False):
        """
        Draw an actor

        Args:
            dc:     The device context to draw on
            withChildren:   Draw the children or not

        """
        OglObject.Draw(self, dc)
        # Get current font
        dc.SetFont(self._defaultFont)

        # Gets the minimum bounding box for the shape
        width, height = self.GetSize()

        # Calculate the top center of the shape
        x, y = self.GetPosition()

        # drawing is restricted in the specified region of the device
        dc.SetClippingRegion(x, y, width, height)

        # Our sweet actor size
        actorWidth = width
        actorHeight = int(0.8 *
                          (height - 2.0 * MARGIN))  # 80 % of total height
        sizer = min(actorHeight, actorWidth)

        # Draw our actor head
        centerX = x + width // 2
        centerY = y + height // 2

        x = int(centerX - 0.2 * sizer)
        y += MARGIN
        percentageSizer: int = int(0.4 * sizer)
        # dc.DrawEllipse(x, y, 0.4 * sizer, 0.4 * sizer)
        dc.DrawEllipse(x, y, percentageSizer, percentageSizer)

        # Draw body and arms
        x = centerX
        y += round(0.4 * sizer)
        # dc.DrawLine(x, y, x, y + 0.3 * actorHeight)
        # dc.DrawLine(x - 0.25 * actorWidth, y + 0.15 * actorHeight,
        #             x + 0.25 * actorWidth, y + 0.15 * actorHeight)
        dc.DrawLine(x, y, x, y + round(0.3 * actorHeight))
        dc.DrawLine(round(x - 0.25 * actorWidth),
                    round(y + 0.15 * actorHeight),
                    round(x + 0.25 * actorWidth),
                    round(y + 0.15 * actorHeight))

        # And the feet
        # y += round(0.3 * actorHeight)
        # dc.DrawLine(x, y, x - 0.25 * actorWidth, y + 0.3 * actorHeight)
        # dc.DrawLine(x, y, x + 0.25 * actorWidth, y + 0.3 * actorHeight)

        actorFeetPercentage: int = round(0.3 * actorHeight)
        y += round(actorFeetPercentage)
        # dc.DrawLine(x, y, x - 0.25 * actorWidth, y + actorFeetPercentage)
        # dc.DrawLine(x, y, x + 0.25 * actorWidth, y + actorFeetPercentage)
        dc.DrawLine(x, y, x - round(0.25 * actorWidth),
                    y + actorFeetPercentage)
        dc.DrawLine(x, y, x + round(0.25 * actorWidth),
                    y + actorFeetPercentage)

        # Draw our buddy name
        textWidth, textHeight = dc.GetTextExtent(self.pyutObject.getName())

        # y = centerY + 0.5 * height - MARGIN - 0.1 * actorHeight
        y = round(centerY + 0.5 * height - MARGIN - 0.1 * actorHeight)

        # dc.DrawText(self.getPyutObject().getName(), x - 0.5 * textWidth, y)
        dc.DrawText(self.pyutObject.getName(), round(x - 0.5 * textWidth), y)
        dc.DestroyClippingRegion()