Python wx 模块,Rect() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用wx.Rect()

项目:fmc-dialer    作者:sguron    | 项目源码 | 文件源码
def __init__(self, strCaption="", imageIndex=-1, enabled=True):
        """
        Default class constructor.

        :param `strCaption`: the tab caption;
        :param `imageIndex`: the tab image index based on the assigned (set)
         :class:`ImageList` (if any);
        :param `enabled`: sets the tab as enabled or disabled.
        """

        self._pos = wx.Point()
        self._size = wx.Size()
        self._strCaption = strCaption
        self._ImageIndex = imageIndex
        self._captionRect = wx.Rect()
        self._bEnabled = enabled
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def SaveTabLayout(self, notebook):
        tabs = []
        for child in notebook.GetChildren():
            if isinstance(child, wx.aui.AuiTabCtrl):
                if child.GetPageCount() > 0:
                    pos = child.GetPosition()
                    tab = {"pos": (pos.x, pos.y), "pages": []}
                    tab_size = child.GetSize()
                    for page_idx in xrange(child.GetPageCount()):
                        page = child.GetWindowFromIdx(page_idx)
                        if "size" not in tab:
                            tab["size"] = (tab_size[0], tab_size[1] + page.GetSize()[1])
                        tab_infos = self.GetTabInfos(page)
                        if tab_infos is not None:
                            tab["pages"].append((tab_infos, page_idx == child.GetActivePage()))
                    tabs.append(tab)
        tabs.sort(lambda x, y: cmp(x["pos"], y["pos"]))
        size = notebook.GetSize()
        return ComputeTabsLayout(tabs, wx.Rect(1, 1, size[0] - NOTEBOOK_BORDER, size[1] - NOTEBOOK_BORDER))
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetBitmapRect(self):
        client_size = self.GetClientSize()
        bitmap_size = self.BackgroundBitmap.GetSize()

        if self.BackgroundAlign & wx.ALIGN_RIGHT:
            x = client_size[0] - bitmap_size[0]
        elif self.BackgroundAlign & wx.ALIGN_CENTER_HORIZONTAL:
            x = (client_size[0] - bitmap_size[0]) / 2
        else:
            x = 0

        if self.BackgroundAlign & wx.ALIGN_BOTTOM:
            y = client_size[1] - bitmap_size[1]
        elif self.BackgroundAlign & wx.ALIGN_CENTER_VERTICAL:
            y = (client_size[1] - bitmap_size[1]) / 2
        else:
            y = 0

        return wx.Rect(x, y, bitmap_size[0], bitmap_size[1])
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetAxesBoundingBox(self, parent_coordinate=False):
        """
        Return figure bounding box in wx coordinate
        @param parent_coordinate: True if use parent coordinate (default False)
        """
        # Calculate figure bounding box. Y coordinate is inverted in matplotlib
        # figure comparing to wx panel
        width, height = self.GetSize()
        ax, ay, aw, ah = self.figure.gca().get_position().bounds
        bbox = wx.Rect(ax * width, height - (ay + ah) * height - 1,
                       aw * width + 2, ah * height + 1)

        # If parent_coordinate, add Viewer position in parent
        if parent_coordinate:
            xw, yw = self.GetPosition()
            bbox.x += xw
            bbox.y += yw

        return bbox
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def HitTest(self, x, y):
        """
        Test if point is inside button
        @param x: X coordinate of point
        @param y: Y coordinate of point
        @return: True if button is active and displayed and point is inside
        button
        """
        # Return immediately if button is hidden or inactive
        if not (self.IsShown() and self.IsEnabled()):
            return False

        # Test if point is inside button
        w, h = self.Bitmap.GetSize()
        rect = wx.Rect(self.Position.x, self.Position.y, w, h)
        return rect.InsideXY(x, y)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def Paste(self, bbx=None):
        if not self.Debug:
            element = self.ParentWindow.GetCopyBuffer()
            if bbx is None:
                mouse_pos = self.Editor.ScreenToClient(wx.GetMousePosition())
                middle = wx.Rect(0, 0, *self.Editor.GetClientSize()).InsideXY(mouse_pos.x, mouse_pos.y)
                if middle:
                    x, y = self.CalcUnscrolledPosition(mouse_pos.x, mouse_pos.y)
                else:
                    x, y = self.CalcUnscrolledPosition(0, 0)
                new_pos = [int(x / self.ViewScale[0]), int(y / self.ViewScale[1])]
            else:
                middle = True
                new_pos = [bbx.x, bbx.y]
            result = self.Controler.PasteEditedElementInstances(self.TagName, element, new_pos, middle, self.Debug)
            if not isinstance(result, (StringType, UnicodeType)):
                self.RefreshBuffer()
                self.RefreshView(selection=result)
                self.RefreshVariablePanel()
                self.ParentWindow.RefreshPouInstanceVariablesPanel()
            else:
                message = wx.MessageDialog(self.Editor, result, "Error", wx.OK | wx.ICON_ERROR)
                message.ShowModal()
                message.Destroy()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def OnLeftDown(self, event, dc, scaling):
        """
        Called when left mouse is pressed on Viewer. Starts to edit a new
        rubberband bounding box
        @param event: Mouse event
        @param dc: Device Context of Viewer
        @param scaling: PLCOpen scaling applied on Viewer
        """
        # Save the point where mouse was pressed in Viewer unit, position may
        # be modified by scroll and zoom applied on viewer
        self.StartPoint = GetScaledEventPosition(event, dc, scaling)

        # Initialize rubberband bounding box
        self.CurrentBBox = wx.Rect(self.StartPoint.x, self.StartPoint.y, 0, 0)

        # Change viewer mouse cursor to reflect a rubberband bounding box is
        # edited
        self.DrawingSurface.SetCursor(wx.StockCursor(wx.CURSOR_CROSS))

        self.Redraw()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshBoundingBox(self):
        # Calculate the bounding box size
        if self.Action:
            bbx_width = self.Size[0] + CONNECTOR_SIZE
        else:
            bbx_width = self.Size[0]
        if self.Initial:
            bbx_y = self.Pos.y
            bbx_height = self.Size[1]
            if self.Output:
                bbx_height += CONNECTOR_SIZE
        else:
            bbx_y = self.Pos.y - CONNECTOR_SIZE
            bbx_height = self.Size[1] + CONNECTOR_SIZE
            if self.Output:
                bbx_height += CONNECTOR_SIZE
        # self.BoundingBox = wx.Rect(self.Pos.x, bbx_y, bbx_width + 1, bbx_height + 1)
        self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)

    # Refresh the positions of the step connectors
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshBoundingBox(self):
        bbx_x, bbx_y, bbx_width, bbx_height = self.Pos.x, self.Pos.y, self.Size[0], self.Size[1]
        if self.Priority != 0:
            bbx_y = self.Pos.y - self.PrioritySize[1] - 2
            bbx_width = max(self.Size[0], self.PrioritySize[0])
            bbx_height = self.Size[1] + self.PrioritySize[1] + 2
        if self.Type == "connection":
            bbx_x = self.Pos.x - CONNECTOR_SIZE
            bbx_width = bbx_width + CONNECTOR_SIZE
        else:
            text_width, text_height = self.ConditionSize
            # Calculate the bounding box size
            bbx_width = max(bbx_width, self.Size[0] + 5 + text_width)
            bbx_y = min(bbx_y, self.Pos.y - max(0, (text_height - self.Size[1]) / 2))
            bbx_height = max(bbx_height, self.Pos.y - bbx_y + (self.Size[1] + text_height) / 2)
        self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)

    # Returns the connector connected to input
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshBoundingBox(self):
        if len(self.Elements) > 0:
            bbox = self.Elements[0].GetBoundingBox()
            minx, miny = bbox.x, bbox.y
            maxx = bbox.x + bbox.width
            maxy = bbox.y + bbox.height
            for element in self.Elements[1:]:
                bbox = element.GetBoundingBox()
                minx = min(minx, bbox.x)
                miny = min(miny, bbox.y)
                maxx = max(maxx, bbox.x + bbox.width)
                maxy = max(maxy, bbox.y + bbox.height)
            self.BoundingBox = wx.Rect(minx, miny, maxx - minx, maxy - miny)
        else:
            self.BoundingBox = wx.Rect(0, 0, 0, 0)
        self.Pos = wx.Point(self.BoundingBox.x, self.BoundingBox.y)
        self.Size = wx.Size(self.BoundingBox.width, self.BoundingBox.height)

    # Forbids to change the group position
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def TestPoint(self, pt, direction=None, exclude=True):
        inside = False
        check_point = (not exclude) and (direction is None or self.Direction == direction)

        if check_point:
            # Calculate a square around the end point of this connector
            parent_pos = self.ParentBlock.GetPosition()
            x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE - ANCHOR_DISTANCE
            y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE - ANCHOR_DISTANCE
            width = ANCHOR_DISTANCE * 2 + abs(self.Direction[0]) * CONNECTOR_SIZE
            height = ANCHOR_DISTANCE * 2 + abs(self.Direction[1]) * CONNECTOR_SIZE
            rect = wx.Rect(x, y, width, height)
            inside = rect.InsideXY(pt.x, pt.y)

        return inside

    # Draws the highlightment of this element if it is highlighted
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshBoundingBox(self):
        # Calculate the size of the name outside the contact
        text_width, text_height = self.Parent.GetTextExtent(self.Name)
        # Calculate the bounding box size
        if self.Name != "":
            bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2)
            bbx_width = max(self.Size[0], text_width)
            bbx_y = self.Pos.y - (text_height + 2)
            bbx_height = self.Size[1] + (text_height + 2)
        else:
            bbx_x = self.Pos.x
            bbx_width = self.Size[0]
            bbx_y = self.Pos.y
            bbx_height = self.Size[1]
        self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)

    # Returns the block minimum size
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshBoundingBox(self):
        if self.Type in (OUTPUT, INOUT):
            bbx_x = self.Pos.x - CONNECTOR_SIZE
        else:
            bbx_x = self.Pos.x
        if self.Type == INOUT:
            bbx_width = self.Size[0] + 2 * CONNECTOR_SIZE
        else:
            bbx_width = self.Size[0] + CONNECTOR_SIZE
        bbx_x = min(bbx_x, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2)
        bbx_width = max(bbx_width, self.NameSize[0])
        bbx_height = self.Size[1]
        if self.ExecutionOrder != 0:
            bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0])
            bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0])
            bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2)
        self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, bbx_height + 1)

    # Refresh the position of the variable connector
项目:Cognitive-Face-Python    作者:Microsoft    | 项目源码 | 文件源码
def __init__(self, res, path, size=util.MAX_THUMBNAIL_SIZE):
        super(Face, self).__init__()
        self.path = path
        img = util.rotate_image(path)
        self.bmp = img.ConvertToBitmap()
        self.name = None
        if res.get('faceId'):
            self.id = res['faceId']
        if res.get('persistedFaceId'):
            self.persisted_id = res['persistedFaceId']
        if res.get('faceRectangle'):
            self.rect = Rect(res['faceRectangle'])
            self.bmp = self.bmp.GetSubBitmap(wx.Rect(
                self.rect.left,
                self.rect.top,
                self.rect.width,
                self.rect.height,
            ))
        if res.get('faceAttributes'):
            self.attr = Attribute(res['faceAttributes'])
        self.bmp = util.scale_image(
            self.bmp.ConvertToImage(),
            size=size,
        ).ConvertToBitmap()
项目:Cognitive-Face-Python    作者:Microsoft    | 项目源码 | 文件源码
def OnDrawItem(self, dc, rect, index):
        """OnDrawItem for Layout."""
        face = self.faces[index]
        dc.DrawBitmap(face.bmp, rect.x + 2,
                      ((rect.height - face.bmp.GetHeight()) / 2) + rect.y)

        textx = rect.x + 2 + face.bmp.GetWidth() + 2
        label_rect = wx.Rect(textx, rect.y, rect.width - textx, rect.height)
        label = util.LABEL_FACE.format(
            face.attr.gender,
            face.attr.age,
            face.attr.hair,
            face.attr.facial_hair,
            face.attr.makeup,
            face.attr.emotion,
            face.attr.occlusion,
            face.attr.exposure,
            face.attr.head_pose,
            face.attr.accessories
        )
        dc.DrawLabel(label, label_rect, wx.ALIGN_LEFT | wx.ALIGN_TOP)
项目:GRIPy    作者:giruenf    | 项目源码 | 文件源码
def OnDrawItem(self, dc, rect, item, flags):
        if item == wx.NOT_FOUND:
            # painting the control, but there is no valid item selected yet
            return 
        font = wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, 'Segoe UI')             
        dc.SetFont(font)
        if flags == 3:
            margin = 3    
        else:
            margin = 1
        r = wx.Rect(*rect)  # make a copy
        r.Deflate(margin, margin)
        tam = self.OnMeasureItem(item)-2
        dc.SetPen(wx.Pen("grey", style=wx.TRANSPARENT))
        color_name = self.GetString(item)     
        color = self.colors.get(color_name)
        if not color:
            color = wx.NamedColour(color_name)
        dc.SetBrush(wx.Brush(color))
        dc.DrawRectangle(r.x, r.y, tam, tam)
        dc.DrawText(self.GetString(item), r.x + tam + 2, r.y)
项目:SpatialTool    作者:JRcard    | 项目源码 | 文件源码
def __init__(self, x, y, c): 
        self.x = x
        self.y = y
        self.c = c
        self.rect = wx.Rect(self.x-self.c,self.y-self.c,self.c*2,self.c*2)
项目:SpatialTool    作者:JRcard    | 项目源码 | 文件源码
def __init__(self, x, y, c): 
        self.x = x
        self.y = y
        self.c = c
        self.radius = INIT_SOUND_RADIUS
        self.rect = wx.Rect(self.x-self.c,self.y-self.c,self.c*2,self.c*2)
项目:fmc-dialer    作者:sguron    | 项目源码 | 文件源码
def SetTextRect(self, rect):
        """
        Sets the client rectangle available for the tab text.

        :param `rect`: the tab text client rectangle, an instance of :class:`Rect`.
        """

        self._captionRect = rect
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def ComputeTabsLayout(tabs, rect):
    if len(tabs) == 0:
        return tabs
    if len(tabs) == 1:
        return tabs[0]
    split = None
    for idx, tab in enumerate(tabs):
        if len(tab["pages"]) == 0:
            raise ValueError("Not possible")
        if tab["size"][0] == rect.width:
            if tab["pos"][1] == rect.y:
                split = (wx.TOP, float(tab["size"][1]) / float(rect.height))
                split_rect = wx.Rect(rect.x, rect.y + tab["size"][1] + TAB_BORDER,
                                     rect.width, rect.height - tab["size"][1] - TAB_BORDER)
            elif tab["pos"][1] == rect.height + 1 - tab["size"][1]:
                split = (wx.BOTTOM, 1.0 - float(tab["size"][1]) / float(rect.height))
                split_rect = wx.Rect(rect.x, rect.y,
                                     rect.width, rect.height - tab["size"][1] - TAB_BORDER)
            break
        elif tab["size"][1] == rect.height:
            if tab["pos"][0] == rect.x:
                split = (wx.LEFT, float(tab["size"][0]) / float(rect.width))
                split_rect = wx.Rect(rect.x + tab["size"][0] + TAB_BORDER, rect.y,
                                     rect.width - tab["size"][0] - TAB_BORDER, rect.height)
            elif tab["pos"][0] == rect.width + 1 - tab["size"][0]:
                split = (wx.RIGHT, 1.0 - float(tab["size"][0]) / float(rect.width))
                split_rect = wx.Rect(rect.x, rect.y,
                                     rect.width - tab["size"][0] - TAB_BORDER, rect.height)
            break
    if split is not None:
        split_tab = tabs.pop(idx)
        return {"split": split,
                "tab": split_tab,
                "others": ComputeTabsLayout(tabs, split_rect)}
    else:
        if SimplifyTabLayout(tabs, rect):
            return ComputeTabsLayout(tabs, rect)
    return tabs
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetRangeRect(self):
        width, height = self.GetClientSize()
        return wx.Rect(0, width, width, height - 2 * width)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetThumbRect(self):
        width, height = self.GetClientSize()
        range_rect = self.GetRangeRect()
        thumb_size = range_rect.height * THUMB_SIZE_RATIO
        thumb_range = range_rect.height - thumb_size
        thumb_center_position = (thumb_size + (self.ThumbPosition + 1) * thumb_range) / 2.
        thumb_start = int(thumb_center_position - thumb_size / 2.)
        thumb_end = int(thumb_center_position + thumb_size / 2.)
        return wx.Rect(0, range_rect.y + thumb_start, width, thumb_end - thumb_start)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def HitTest(self, x, y):
        rect = wx.Rect(self.Position.x, self.Position.y,
                       self.Size.width, self.Size.height)
        if rect.InsideXY(x, y):
            return True
        return False
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetItemRightImagesBBox(self, item):
        rightimages = item.GetRightImages()
        if len(rightimages) > 0:
            w, h = self.GetClientSize()
            total_h = self.GetLineHeight(item)
            r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])

            bbox_width = (r_image_w + 4) * len(rightimages) + 4
            bbox_height = r_image_h + 8
            bbox_x = w - bbox_width
            bbox_y = item.GetY() + ((total_h > r_image_h) and [(total_h-r_image_h)/2] or [0])[0]

            return wx.Rect(bbox_x, bbox_y, bbox_width, bbox_height)

        return None
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def IsOverItemRightImage(self, item, point):
        rightimages = item.GetRightImages()
        if len(rightimages) > 0:
            point = self.CalcUnscrolledPosition(point)
            r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
            images_bbx = self.GetItemRightImagesBBox(item)

            rect = wx.Rect(images_bbx.x + 4, images_bbx.y + 4,
                           r_image_w, r_image_h)
            for r_image in rightimages:
                if rect.Inside(point):
                    return r_image
                rect.x += r_image_w + 4

            return None
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshHighlight(self, x_mouse, y_mouse):
        for idx, panel in enumerate(self.GraphicPanels):
            x, y = panel.GetPosition()
            width, height = panel.GetSize()
            rect = wx.Rect(x, y, width, height)
            if rect.InsideXY(x_mouse, y_mouse) or \
               idx == 0 and y_mouse < 0 or \
               idx == len(self.GraphicPanels) - 1 and y_mouse > panel.GetPosition()[1]:
                panel.RefreshHighlight(x_mouse - x, y_mouse - y)
            else:
                panel.SetHighlight(HIGHLIGHT_NONE)
        if wx.Platform == "__WXMSW__":
            self.RefreshView()
        else:
            self.ForceRefresh()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetDraggingAxesClippingRegion(self, panel):
        x, y = panel.GetPosition()
        width, height = panel.GetSize()
        bbox = wx.Rect(x, y, width, height)
        bbox = bbox.Intersect(self.DraggingAxesBoundingBox)
        bbox.x -= x
        bbox.y -= y
        return bbox
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshHighlight(self, x, y):
        """
        Refresh Viewer highlight according to mouse position
        @param x: X coordinate of mouse pointer
        @param y: Y coordinate of mouse pointer
        """
        width, height = self.GetSize()

        # Mouse is over Viewer figure and graph is not 3D
        bbox = self.GetAxesBoundingBox()
        if bbox.InsideXY(x, y) and not self.Is3DCanvas():
            rect = wx.Rect(bbox.x, bbox.y, bbox.width / 2, bbox.height)
            # Mouse is over Viewer left part of figure
            if rect.InsideXY(x, y):
                self.SetHighlight(HIGHLIGHT_LEFT)

            # Mouse is over Viewer right part of figure
            else:
                self.SetHighlight(HIGHLIGHT_RIGHT)

        # Mouse is over upper part of Viewer
        elif y < height / 2:
            # Viewer is upper one in Debug Variable Panel, show highlight
            if self.ParentWindow.IsViewerFirst(self):
                self.SetHighlight(HIGHLIGHT_BEFORE)

            # Viewer is not the upper one, show highlight in previous one
            # It prevents highlight to move when mouse leave one Viewer to
            # another
            else:
                self.SetHighlight(HIGHLIGHT_NONE)
                self.ParentWindow.HighlightPreviousViewer(self)

        # Mouse is over lower part of Viewer
        else:
            self.SetHighlight(HIGHLIGHT_AFTER)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def OnLeftDown(self, event):
        """
        Function called when mouse left button is pressed
        @param event: wx.MouseEvent
        """
        # Get first item
        item = self.ItemsDict.values()[0]

        # Calculate item path bounding box
        width, height = self.GetSize()
        item_path = item.GetVariable(
                self.ParentWindow.GetVariableNameMask())
        w, h = self.GetTextExtent(item_path)

        # Test if mouse has been pressed in this bounding box. In that case
        # start a move drag'n drop of item variable
        x, y = event.GetPosition()
        item_path_bbox = wx.Rect(20, (height - h) / 2, w, h)
        if item_path_bbox.InsideXY(x, y):
            self.ShowButtons(False)
            data = wx.TextDataObject(str((item.GetVariable(), "debug", "move")))
            dragSource = wx.DropSource(self)
            dragSource.SetData(data)
            dragSource.DoDragDrop()

        # In other case handle event normally
        else:
            event.Skip()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def OnLeftDown(self, event):
        selected = self.ListBox.HitTest(wx.Point(event.GetX(), event.GetY()))
        parent_size = self.Parent.GetSize()
        parent_rect = wx.Rect(0, -parent_size[1], parent_size[0], parent_size[1])
        if selected != wx.NOT_FOUND:
            wx.CallAfter(self.Parent.SetValueFromSelected, self.ListBox.GetString(selected))
        elif parent_rect.InsideXY(event.GetX(), event.GetY()):
            result, x, y = self.Parent.HitTest(wx.Point(event.GetX(), event.GetY() + parent_size[1]))
            if result != wx.TE_HT_UNKNOWN:
                self.Parent.SetInsertionPoint(self.Parent.XYToPosition(x, y))
        else:
            wx.CallAfter(self.Parent.DismissListBox)
        event.Skip()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshVisibleElements(self, xp=None, yp=None):
        x, y = self.Editor.CalcUnscrolledPosition(0, 0)
        if xp is not None:
            x = xp * self.Editor.GetScrollPixelsPerUnit()[0]
        if yp is not None:
            y = yp * self.Editor.GetScrollPixelsPerUnit()[1]
        width, height = self.Editor.GetClientSize()
        screen = wx.Rect(int(x / self.ViewScale[0]), int(y / self.ViewScale[1]),
                         int(width / self.ViewScale[0]), int(height / self.ViewScale[1]))
        for comment in self.Comments.itervalues():
            comment.TestVisible(screen)
        for wire in self.Wires.iterkeys():
            wire.TestVisible(screen)
        for block in self.Blocks.itervalues():
            block.TestVisible(screen)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetAddToWireMenuCallBack(self, func, *args):
        args += (self.SelectedElement,)

        def AddToWireMenuCallBack(event):
            func(wx.Rect(0, 0, 0, 0), *args)
        return AddToWireMenuCallBack
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetCurrentExtent(self):
        """
        Return the rubberband bounding box
        @return: Rubberband bounding box (wx.Rect object)
        """
        # In case of rubberband not shown, return the last rubberband
        # bounding box
        if self.IsShown():
            return self.CurrentBBox
        return self.LastBBox
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def HitTest(self, pt, connectors=True):
        if self.Type != "connection":
            # Calculate the bounding box of the condition outside the transition
            text_width, text_height = self.ConditionSize
            text_bbx = wx.Rect(self.Pos.x + self.Size[0] + 5,
                               self.Pos.y + (self.Size[1] - text_height) / 2,
                               text_width,
                               text_height)
            test_text = text_bbx.InsideXY(pt.x, pt.y)
        else:
            test_text = False
        return test_text or Graphic_Element.HitTest(self, pt, connectors)

    # Refresh the transition bounding box
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshBoundingBox(self):
        if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
            self.BoundingBox = wx.Rect(self.Pos.x,       self.Pos.y,
                                       self.Size[0] + 1, self.Size[1] + 1)
        elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
            self.BoundingBox = wx.Rect(
                self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA,           self.Pos.y,
                self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + 1)

    # Refresh the position of wires connected to divergence
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def HitTest(self, pt, connectors=True):
        # Calculate the bounding box of the condition outside the transition
        text_width, text_height = self.TargetSize
        text_bbx = wx.Rect(self.Pos.x + self.Size[0] + 2,
                           self.Pos.y + (self.Size[1] - text_height) / 2,
                           text_width,
                           text_height)
        return text_bbx.InsideXY(pt.x, pt.y) or Graphic_Element.HitTest(self, pt, connectors)

    # Refresh the jump bounding box
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshBoundingBox(self):
        self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)

    # Refresh the position of wires connected to action block
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def __init__(self, parent, id=None):
        ToolTipProducer.__init__(self, parent)
        self.Parent = parent
        self.Id = id
        self.oldPos = None
        self.StartPos = None
        self.CurrentDrag = None
        self.Handle = (None, None)
        self.Dragging = False
        self.Selected = False
        self.Highlighted = False
        self.Pos = wx.Point(0, 0)
        self.Size = wx.Size(0, 0)
        self.BoundingBox = wx.Rect(0, 0, 0, 0)
        self.Visible = False
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshBoundingBox(self):
        self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1])

    # Refresh the element connectors position
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def HitTest(self, pt, connectors=True):
        if connectors:
            rect = self.BoundingBox
        else:
            rect = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1])
        return rect.InsideXY(pt.x, pt.y)

    # Returns if the point given is in the bounding box
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetRedrawRect(self, movex=0, movey=0):
        scalex, scaley = self.Parent.GetViewScale()
        rect = wx.Rect()
        rect.x = self.BoundingBox.x - int(HANDLE_SIZE / scalex) - 3 - abs(movex)
        rect.y = self.BoundingBox.y - int(HANDLE_SIZE / scaley) - 3 - abs(movey)
        rect.width = self.BoundingBox.width + 2 * (int(HANDLE_SIZE / scalex) + abs(movex) + 1) + 4
        rect.height = self.BoundingBox.height + 2 * (int(HANDLE_SIZE / scaley) + abs(movey) + 1) + 4
        return rect
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetRedrawRect(self, movex=0, movey=0):
        parent_pos = self.ParentBlock.GetPosition()
        x = min(parent_pos[0] + self.Pos.x, parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE)
        y = min(parent_pos[1] + self.Pos.y, parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE)
        has_modifier = self.Negated or self.Edge != "none"
        if self.Direction[0] == 0:
            width = 10 if has_modifier else 5
        else:
            width = CONNECTOR_SIZE
            if self.Edge == "rising" and self.Direction[0] == 1:
                x -= 5
                width += 5
        if self.Direction[1] == 0:
            height = 10 if has_modifier else 5
        else:
            height = CONNECTOR_SIZE
            if self.Edge == "rising" and self.Direction[1] == 1:
                y -= 5
                height += 5
        rect = wx.Rect(x - abs(movex), y - abs(movey), width + 2 * abs(movex), height + 2 * abs(movey))
        if self.ValueSize is None and isinstance(self.ComputedValue, (StringType, UnicodeType)):
            self.ValueSize = self.ParentBlock.Parent.GetMiniTextExtent(self.ComputedValue)
        if self.ValueSize is not None:
            width, height = self.ValueSize
            rect = rect.Union(
                wx.Rect(
                    parent_pos[0] + self.Pos.x + CONNECTOR_SIZE * self.Direction[0] +
                    width * (self.Direction[0] - 1) / 2,
                    parent_pos[1] + self.Pos.y + CONNECTOR_SIZE * self.Direction[1] +
                    height * (self.Direction[1] - 1),
                    width, height))
        return rect

    # Change the connector selection
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetRedrawRect(self, movex=0, movey=0):
        rect = Graphic_Element.GetRedrawRect(self, movex, movey)
        if self.StartConnected:
            rect = rect.Union(self.StartConnected.GetRedrawRect(movex, movey))
        if self.EndConnected:
            rect = rect.Union(self.EndConnected.GetRedrawRect(movex, movey))
        if self.ValueSize is None and isinstance(self.ComputedValue, (StringType, UnicodeType)):
            self.ValueSize = self.Parent.GetMiniTextExtent(self.ComputedValue)
        if self.ValueSize is not None:
            width, height = self.ValueSize
            if self.BoundingBox[2] > width * 4 or self.BoundingBox[3] > height * 4:
                x = self.Points[0].x + width * self.StartPoint[1][0] / 2
                y = self.Points[0].y + height * (self.StartPoint[1][1] - 1)
                rect = rect.Union(wx.Rect(x, y, width, height))
                x = self.Points[-1].x + width * self.EndPoint[1][0] / 2
                y = self.Points[-1].y + height * (self.EndPoint[1][1] - 1)
                rect = rect.Union(wx.Rect(x, y, width, height))
            else:
                middle = len(self.Segments) / 2 + len(self.Segments) % 2 - 1
                x = (self.Points[middle].x + self.Points[middle + 1].x - width) / 2
                if self.BoundingBox[3] > height and self.Segments[middle] in [NORTH, SOUTH]:
                    y = (self.Points[middle].y + self.Points[middle + 1].y - height) / 2
                else:
                    y = self.Points[middle].y - height
                rect = rect.Union(wx.Rect(x, y, width, height))
        return rect
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshBoundingBox(self):
        if len(self.Points) > 0:
            # If startpoint or endpoint is connected, save the point radius
            start_radius = end_radius = 0
            if not self.StartConnected:
                start_radius = POINT_RADIUS
            if not self.EndConnected:
                end_radius = POINT_RADIUS
            # Initialize minimum and maximum from the first point
            minx, minbbxx = self.Points[0].x, self.Points[0].x - start_radius
            maxx, maxbbxx = self.Points[0].x, self.Points[0].x + start_radius
            miny, minbbxy = self.Points[0].y, self.Points[0].y - start_radius
            maxy, maxbbxy = self.Points[0].y, self.Points[0].y + start_radius
            # Actualize minimum and maximum with the other points
            for point in self.Points[1:-1]:
                minx, minbbxx = min(minx, point.x), min(minbbxx, point.x)
                maxx, maxbbxx = max(maxx, point.x), max(maxbbxx, point.x)
                miny, minbbxy = min(miny, point.y), min(minbbxy, point.y)
                maxy, maxbbxy = max(maxy, point.y), max(maxbbxy, point.y)
            if len(self.Points) > 1:
                minx, minbbxx = min(minx, self.Points[-1].x), min(minbbxx, self.Points[-1].x - end_radius)
                maxx, maxbbxx = max(maxx, self.Points[-1].x), max(maxbbxx, self.Points[-1].x + end_radius)
                miny, minbbxy = min(miny, self.Points[-1].y), min(minbbxy, self.Points[-1].y - end_radius)
                maxy, maxbbxy = max(maxy, self.Points[-1].y), max(maxbbxy, self.Points[-1].y + end_radius)
            self.Pos.x, self.Pos.y = minx, miny
            self.Size = wx.Size(maxx - minx, maxy - miny)
            self.BoundingBox = wx.Rect(minbbxx, minbbxy, maxbbxx - minbbxx + 1, maxbbxy - minbbxy + 1)

    # Refresh the realpoints that permits to keep the proportionality in wire during resizing
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def TestPoint(self, pt):
        # Test the wire start point
        rect = wx.Rect(self.Points[0].x - ANCHOR_DISTANCE, self.Points[0].y - ANCHOR_DISTANCE,
                       2 * ANCHOR_DISTANCE, 2 * ANCHOR_DISTANCE)
        if rect.InsideXY(pt.x, pt.y):
            return 0
        # Test the wire end point
        if len(self.Points) > 1:
            rect = wx.Rect(self.Points[-1].x - ANCHOR_DISTANCE, self.Points[-1].y - ANCHOR_DISTANCE,
                           2 * ANCHOR_DISTANCE, 2 * ANCHOR_DISTANCE)
            if rect.InsideXY(pt.x, pt.y):
                return -1
        return None

    # Returns the wire segment if the point given is on it
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def TestSegment(self, pt, all=False):
        for i in xrange(len(self.Segments)):
            # If wire is not in a Ladder Diagram, first and last segments are excluded
            if all or 0 < i < len(self.Segments) - 1:
                x1, y1 = self.Points[i].x, self.Points[i].y
                x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y
                # Calculate a rectangle around the segment
                rect = wx.Rect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE,
                               abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE)
                if rect.InsideXY(pt.x, pt.y):
                    return i, self.Segments[i]
        return None

    # Define the wire points
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshBoundingBox(self):
        self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)

    # Changes the comment size
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshBoundingBox(self):
        self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)

    # Refresh the power rail size
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetTextBoundingBox(self):
        # Calculate the size of the name outside the block
        text_width, text_height = self.NameSize
        return wx.Rect(self.Pos.x + (self.Size[0] - text_width) / 2,
                       self.Pos.y - (text_height + 2),
                       text_width,
                       text_height)

    # Returns the bounding box of function block without name outside
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetBlockBoundingBox(self, connectors=True):
        bbx_x, bbx_y = self.Pos.x, self.Pos.y
        bbx_width, bbx_height = self.Size
        if connectors:
            bbx_x -= min(1, len(self.Inputs)) * CONNECTOR_SIZE
            bbx_width += (min(1, len(self.Inputs)) + min(1, len(self.Outputs))) * CONNECTOR_SIZE
        if self.ExecutionOrder != 0:
            bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0])
            bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0])
            bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2)
        return wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)

    # Refresh the block bounding box