コード例 #1
0
ファイル: OglText.py プロジェクト: hasii2011/PyUt
    def Draw(self, dc: DC, withChildren: bool = False):
        """
        Paint handler, draws the content of the shape.

        Args:
            dc:     device context to draw to
            withChildren:   Redraw children or not
        """
        OglObject.Draw(self, dc)
        dc.SetFont(self._textFont)

        w, h = self.GetSize()

        baseX, baseY = self.GetPosition()

        dc.SetClippingRegion(baseX, baseY, w, h)

        noteContent = cast(PyutText, self.getPyutObject()).content
        lines = LineSplitter().split(noteContent, dc, w - 2 * OglText.MARGIN)

        x = baseX + OglText.MARGIN
        y = baseY + OglText.MARGIN

        for line in range(len(lines)):
            dc.DrawText(lines[line], x, y + line * (dc.GetCharHeight() + 5))

        dc.DestroyClippingRegion()
コード例 #2
0
    def Draw(self, dc: DC, withChildren: bool = True):
        """
        Draw the text on the dc.

        Args:
            dc
            withChildren
        """
        if self._visible:
            RectangleShape.Draw(self, dc, False)
            dc.SetTextForeground(self._color)
            dc.SetBackgroundMode(PENSTYLE_SOLID)
            dc.SetTextBackground(self._textBack)
            x, y = self.GetPosition()

            # to draw the text shape with its own font size
            saveFont: Font = dc.GetFont()
            if self.GetFont() is not None:
                dc.SetFont(self.GetFont())

            dc.DrawText(self._text, x, y)
            dc.SetFont(saveFont)

            if withChildren:
                self.DrawChildren(dc)
コード例 #3
0
    def _drawSourceCardinality(self, dc: DC, sp: OglPosition, dp: OglPosition):

        dx, dy = self._computeDxDy(srcPosition=sp, destPosition=dp)

        linkLength: float = self._computeLinkLength(srcPosition=sp,
                                                    destPosition=dp)

        srcLblX: int = round((20 * dx / linkLength - dx * 5 / linkLength) +
                             sp.x)
        srcLblY: int = round((20 * dy / linkLength + dy * 5 / linkLength) +
                             sp.y)

        if OglAssociation.clsLogger.isEnabledFor(INFO):
            info = (f'{sp=} '
                    f'{dp=} '
                    f'{dx=} '
                    f'{dy=} '
                    f'linkLength={linkLength:.2f} '
                    f'srcLblX={srcLblX:.2f} '
                    f'srcLblY={srcLblY:.2f}')
            OglAssociation.clsLogger.info(info)
        saveFont: Font = dc.GetFont()
        dc.SetFont(self._defaultFont)

        sourceCardinalityText: str = self._link.sourceCardinality
        dc.DrawText(sourceCardinalityText, srcLblX, srcLblY)
        dc.SetFont(saveFont)
        self._sourceCardinality = self.__updateAssociationLabel(
            self._sourceCardinality,
            x=srcLblX,
            y=srcLblY,
            text=sourceCardinalityText)
コード例 #4
0
    def Draw(self, dc: DC, withChildren: bool = False):
        """
        Paint handler, draws the content of the shape.

        Args:
            dc:     device context to draw to
            withChildren:   Redraw children or not
        """
        OglObject.Draw(self, dc)
        dc.SetFont(self._defaultFont)

        w, h = self.GetSize()

        try:
            # lines = LineSplitter().split(self.getPyutObject().getName(), dc, w - 2 * MARGIN)
            # noteName = self.getPyutObject().getName()
            noteContent = self.getPyutObject().content
            lines = LineSplitter().split(noteContent, dc, w - 2 * OglNote.MARGIN)
        except (ValueError, Exception) as e:
            self.logger.error(f"Unable to display note - {e}")
            return

        baseX, baseY = self.GetPosition()

        dc.SetClippingRegion(baseX, baseY, w, h)

        x = baseX + OglNote.MARGIN
        y = baseY + OglNote.MARGIN

        for line in range(len(lines)):
            dc.DrawText(lines[line], x, y + line * (dc.GetCharHeight() + 5))

        dc.DrawLine(baseX + w - OglNote.MARGIN, baseY, baseX + w, baseY + OglNote.MARGIN)

        dc.DestroyClippingRegion()
コード例 #5
0
ファイル: OglActor.py プロジェクト: curiousTauseef/PyUt
    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()
コード例 #6
0
    def _drawCenterLabel(self, dc: DC, sp: OglPosition, dp: OglPosition):

        midPoint: OglPosition = OglUtils.computeMidPoint(srcPosition=sp,
                                                         destPosition=dp)

        saveFont: Font = dc.GetFont()
        dc.SetFont(self._defaultFont)

        centerText: str = self._link.getName()
        dc.DrawText(centerText, midPoint.x, midPoint.y)
        dc.SetFont(saveFont)
        self._centerLabel = self.__updateAssociationLabel(self._centerLabel,
                                                          x=midPoint.x,
                                                          y=midPoint.y,
                                                          text=centerText)
コード例 #7
0
ファイル: OglClass.py プロジェクト: hasii2011/PyUt
    def __drawMethodSignature(self, dc: DC, pyutMethod: PyutMethod,
                              pyutClass: PyutClass, x: float, y: float,
                              h: float):
        """
        If preference is not set at individual class level defer to global; Otherwise,
        respect the class level preference

        Args:
            dc:
            pyutMethod:
            pyutClass:
            x:
            y:
            h:
        """
        if pyutClass.displayParameters == PyutDisplayParameters.UNSPECIFIED:
            dc.DrawText(str(pyutMethod), x + MARGIN, y + h)
        elif pyutClass.displayParameters == PyutDisplayParameters.DISPLAY:
            dc.DrawText(pyutMethod.methodWithParameters(), x + MARGIN, y + h)
        elif pyutClass.displayParameters == PyutDisplayParameters.DO_NOT_DISPLAY:
            dc.DrawText(pyutMethod.methodWithoutParameters(), x + MARGIN,
                        y + h)
        else:
            assert False, 'Internal error unknown pyutMethod parameter display type'
コード例 #8
0
    def Draw(self, dc: DC, withChildren=False):
        """
        Draw the actor.
        @param dc : Device context
        @param withChildren

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

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

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

        # Draw ellipse
        dc.DrawEllipse(x + 1, y + 1, width - 2, height - 2)

        # Draw text
        x += round(0.25 * width)
        y += round(0.25 * height)

        textWidth: int = round(0.6 * width)  # Text area width
        space: int = round(1.1 * dc.GetCharHeight())  # Space between lines

        # Drawing is restricted in the specified region of the device
        dc.SetClippingRegion(x, y, textWidth, round(0.6 * height))

        # Split lines
        lines = LineSplitter().split(self.pyutObject.getName(), dc, textWidth)

        # Draw text
        for line in lines:
            dc.DrawText(line, x, y)
            y += space

        dc.DestroyClippingRegion()
コード例 #9
0
    def _drawDestinationCardinality(self, dc: DC, sp: OglPosition,
                                    dp: OglPosition):

        dx, dy = self._computeDxDy(srcPosition=sp, destPosition=dp)

        linkLength: float = self._computeLinkLength(srcPosition=sp,
                                                    destPosition=dp)

        dstLblX: int = round((-20 * dx / linkLength + dy * 5 / linkLength) +
                             dp.x)
        dstLblY: int = round((-20 * dy / linkLength - dy * 5 / linkLength) +
                             dp.y)

        saveFont: Font = dc.GetFont()
        dc.SetFont(self._defaultFont)

        destinationCardinalityText: str = self._link.destinationCardinality
        dc.DrawText(destinationCardinalityText, dstLblX, dstLblY)
        self._destinationCardinality = self.__updateAssociationLabel(
            self._destinationCardinality,
            x=dstLblX,
            y=dstLblY,
            text=destinationCardinalityText)
        dc.SetFont(saveFont)
コード例 #10
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
コード例 #11
0
ファイル: OglActor.py プロジェクト: hasii2011/PyUt
    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()