BlockPreviewDialog.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:beremiz 作者: nucleron 项目源码 文件源码
def RefreshPreview(self):
        """
        Refresh preview panel of graphic element
        May be overridden by inherited classes
        """
        # Init preview panel paint device context
        dc = wx.ClientDC(self.Preview)
        dc.SetFont(self.Preview.GetFont())
        dc.Clear()

        # Return immediately if no graphic element defined
        if self.Element is None:
            return

        # Calculate block size according to graphic element min size due to its
        # parameters and graphic element min size defined
        min_width, min_height = self.GetMinElementSize()
        width = max(self.MinElementSize[0], min_width)
        height = max(self.MinElementSize[1], min_height)
        self.Element.SetSize(width, height)

        # Get element position and bounding box to center in preview
        posx, posy = self.Element.GetPosition()
        bbox = self.Element.GetBoundingBox()

        # Get Preview panel size
        client_size = self.Preview.GetClientSize()

        # If graphic element is too big to be displayed in preview panel,
        # calculate preview panel scale so that graphic element fit inside
        k = 1.1 if (bbox.width * 1.1 > client_size.width or
                    bbox.height * 1.1 > client_size.height) \
            else 1.0
        scale = (max(float(bbox.width) / client_size.width,
                     float(bbox.height) / client_size.height) * k)
        dc.SetUserScale(1.0 / scale, 1.0 / scale)

        # Center graphic element in preview panel
        x = int(client_size.width * scale - bbox.width) / 2 + posx - bbox.x
        y = int(client_size.height * scale - bbox.height) / 2 + posy - bbox.y
        self.Element.SetPosition(x, y)

        # Draw graphic element
        self.Element.Draw(dc)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号