Exemplo n.º 1
0
    def process_dragging(self, event):
        pos = event.GetPosition()

        for rect in self.docking_rectangles:
            print(("checking %s in rect %s" % (pos, rect)))
            if rect.Contains(pos):
                break
        else:
            print("NOT IN RECT")
            rect = None

        dc = wx.ClientDC(self.event_window)
        odc = wx.DCOverlay(self.overlay, dc)
        odc.Clear()

        if wx.Platform != "__WXMAC__":
            # Win & linux need this hack: copy background to overlay; otherwise
            # the overlay seems to be black? I don't know what's up with this
            # platform difference
            dc.DrawBitmap(self.drag_window.bitmap, 0, 0)

        # Mac already using GCDC
        if 'wxMac' not in wx.PlatformInfo and self.use_transparency:
            dc = wx.GCDC(dc)

        if rect is not None:
            dc.SetPen(self.pen)
            dc.SetBrush(self.brush)
            dc.DrawRectangle(rect)

        pos = self.event_window.ClientToScreen(pos)
        self.drag_window.SetPosition(pos)

        del odc  # Make sure the odc is destroyed before the dc is.
    def draw_tracking_overlay(self):
        mdc = wx.ClientDC(self)
        dc = wx.BufferedDC(mdc)
        # Draw floor plan
        dc.DrawBitmap(self.bitmap_img, 10, 5)

        font = wx.Font(pointSize=9,
                       family=wx.DEFAULT,
                       style=wx.NORMAL,
                       weight=wx.NORMAL,
                       faceName='Consolas')
        dc.SetFont(font)

        odc = wx.DCOverlay(self.overlay, dc)
        odc.Clear()

        # draw anchors
        if self.anchors != None:
            for name in self.anchors:
                x, y, x_mm, y_mm = self.anchors[name]
                self._draw_anchor(dc, name, x, y, x_mm, y_mm)

        # draw tag
        if self.tag != None:
            x, y, x_mm, y_mm = self.tag
            self._draw_tag(dc, x, y, x_mm, y_mm)
Exemplo n.º 3
0
    def draw_rect(self, dc, rect=None, id=ImageUtil.ID_NONE, color=wx.RED, style=wx.PENSTYLE_SOLID):  # 画矩形透明区域
        # dc -> 绘图上下文,必需
        # rect -> wx.Rect类型,由外部传入
        # id -> int类型,标识图形类别
        # color -> 颜色
        # style -> 样式
        if self.start_pos is None or self.end_pos is None:
            return
        try:
            odc = wx.DCOverlay(self.overlay, dc)
            odc.Clear()
            if 'wxMac' not in wx.PlatformInfo:
                dc = wx.GCDC(dc)
            dc.SetPen(wx.Pen(colour=color,
                             width=self.overlayPenWidth.GetValue(),
                             style=style))

            bc = wx.RED
            bc = wx.Colour(bc.red, bc.green, bc.blue, 0x80)
            dc.SetBrush(wx.Brush(bc))
            if rect is None:
                rect = wx.Rect(topLeft=self.start_pos, bottomRight=self.end_pos)
            dc.DrawRectangle(rect)
            self.objects[id].append(rect)

        except Exception as e:
            Util.LOG.error(repr(e))
Exemplo n.º 4
0
    def OnMouseMove(self, evt):
        if not self.HasCapture():
            return
        rect = wx.Rect(self.startPos, evt.GetPosition())
        # Draw the rubber-band rectangle using an overlay so it
        # will manage keeping the rectangle and the former window
        # contents separate.
        dc = wx.ClientDC(self)
        odc = wx.DCOverlay(self.overlay, dc)
        odc.Clear()

        pen = wx.Pen("black", 2)
        brush = wx.Brush(wx.Colour(192, 192, 192, 128))
        if "wxMac" in wx.PlatformInfo:
            dc.SetPen(pen)
            dc.SetBrush(brush)
            dc.DrawRectangle(rect)
        else:
            # use a GC on Windows (and GTK?)
            # this doesn't work on the Mac
            ctx = wx.GraphicsContext.Create(dc)
            ctx.SetPen(pen)
            ctx.SetBrush(brush)
            print("drawing:", rect)
            ctx.DrawRectangle(*rect)

        del odc  # work around a bug in the Python wrappers to make
Exemplo n.º 5
0
 def shape_resize(self, event):
     ms = self.ScreenToClient(self.frame.GetPosition())
     rect = wx.Rect(ms[0], ms[1],
                    self.frame.GetSize()[0],
                    self.frame.GetSize()[1])
     self.rect = rect.GetSize()
     dc = wx.ClientDC(self)
     odc = wx.DCOverlay(self.overlay, dc)
     odc.Clear()
     if 'wxMac' in wx.PlatformInfo:
         dc.SetBrush(wx.Brush(wx.Colour(0xC0, 0xC0, 0xC0, 0x80)))
     else:
         dc.SetBrush(wx.TRANSPARENT_BRUSH)
     self.pen = wx.Pen()
     self.pen.SetWidth(self.pen_width * self.user_scale)
     self.pen.SetColour(self.color)
     dc.SetPen(self.pen)
     if paint.button_id == 100:
         dc.DrawCircle(
             int(ms[0] + (rect.GetSize()[0] / 2)),
             int(ms[1] + (rect.GetSize()[1] / 2)),
             int(min(abs(rect.GetSize()[0]), abs(rect.GetSize()[1])) / 2) -
             10)
     elif paint.button_id == 110:
         dc.DrawRectangle(rect)
     elif paint.button_id == 120:
         dc.DrawEllipse(rect)
     del odc
     event.Skip()
Exemplo n.º 6
0
 def getOverlayDC(self):
     dc = wx.ClientDC(self.scroller)
     odc = wx.DCOverlay(self.scroller.overlay, dc)
     odc.Clear()
     dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT))
     dc.SetBrush(wx.TRANSPARENT_BRUSH)
     return dc, odc
Exemplo n.º 7
0
    def mouse_up(self, evt, wx_obj=None):
        "Release the selected object (pass a wx_obj if the event was captured)"
        self.resizing = False
        if self.current: 
            wx_obj = self.current
            if self.parent.wx_obj.HasCapture():
                self.parent.wx_obj.ReleaseMouse()
            self.current = None
            if self.overlay:
                # When the mouse is released we reset the overlay and it 
                # restores the former content to the window. 
                dc = wx.ClientDC(wx_obj)
                odc = wx.DCOverlay(self.overlay, dc)
                odc.Clear()
                del odc
                self.overlay.Reset()                
                self.overlay = None
                pos = evt.GetPosition()
                # convert to relative client coordinates of the container:
                if evt.GetEventObject() != wx_obj:
                    pos = evt.GetEventObject().ClientToScreen(pos)  # frame
                    pos = wx_obj.ScreenToClient(pos)                # panel
                # finish the multiple selection using the mouse:
                rect = wx.RectPP(self.pos, pos)
                for obj in wx_obj.obj:
                    # only check child controls (not menubar/statusbar)
                    if isinstance(obj, Control):
                        obj_rect = obj.wx_obj.GetRect()
                        if rect.ContainsRect(obj_rect):
                            self.select(obj, keep_selection=True)
                self.pos = None 

        if self.inspector and wx_obj:
            self.inspector.inspect(wx_obj.obj)
        if DEBUG: print "SELECTION", self.selection
Exemplo n.º 8
0
    def draw_rubberband(self, event, x0, y0, x1, y1):
        # Use an Overlay to draw a rubberband-like bounding box.

        dc = wx.ClientDC(self.canvas)
        odc = wx.DCOverlay(self.wxoverlay, dc)
        odc.Clear()

        # Mac's DC is already the same as a GCDC, and it causes
        # problems with the overlay if we try to use an actual
        # wx.GCDC so don't try it.
        if 'wxMac' not in wx.PlatformInfo:
            dc = wx.GCDC(dc)

        height = self.canvas.figure.bbox.height
        y1 = height - y1
        y0 = height - y0

        if y1 < y0: y0, y1 = y1, y0
        if x1 < y0: x0, x1 = x1, x0

        w = x1 - x0
        h = y1 - y0
        rect = wx.Rect(x0, y0, w, h)

        rubberBandColor = '#C0C0FF'  # or load from config?

        # Set a pen for the border
        color = wx.NamedColour(rubberBandColor)
        dc.SetPen(wx.Pen(color, 1))

        # use the same color, plus alpha for the brush
        r, g, b = color.Get()
        color.Set(r, g, b, 0x60)
        dc.SetBrush(wx.Brush(color))
        dc.DrawRectangleRect(rect)
Exemplo n.º 9
0
    def DoHighlight(self, tlw, rect, colour, penWidth=2):
        if not tlw.IsFrozen():
            tlw.Freeze()

        if self.useOverlay:
            dc = wx.ClientDC(tlw)
            dco = wx.DCOverlay(self.overlay, dc)
            dco.Clear()
        else:
            dc = wx.ScreenDC()
            dco = None

        dc.SetPen(wx.Pen(colour, penWidth))
        dc.SetBrush(wx.TRANSPARENT_BRUSH)

        drawRect = wx.Rect(*rect)
        dc.DrawRectangle(drawRect)

        drawRect.Inflate(2, 2)
        if not self.useOverlay:
            pos = tlw.ScreenToClient(drawRect.GetPosition())
            drawRect.SetPosition(pos)
        wx.CallLater(self.highlightTime, self.DoUnhighlight, tlw, drawRect)

        return dc, dco
Exemplo n.º 10
0
 def test_overlay1(self):
     o = wx.Overlay()
     dc = wx.ClientDC(self.frame)
     odc = wx.DCOverlay(o, dc)
     odc.Clear()
     del odc
     o.Reset()
Exemplo n.º 11
0
 def OnPaint(self, event):
     #dc = wx.BufferedPaintDC(self, self.bitmap)
     dc = wx.BufferedPaintDC(self, self.buffer, wx.BUFFER_VIRTUAL_AREA)
     #dc.DrawBitmap(self.bitmap, 0, 0)
     odc = wx.DCOverlay(self.overlay, dc)
     odc.Clear()
     if self.LeftClickFlag == 1:
         dc.SetPen(wx.Pen('red', 1))
         dc.DrawLine(self.LeX, 0, self.LeX, 150)
     if self.RightClickFlag == 1:
         dc.SetPen(wx.Pen('blue', 1))
         dc.DrawLine(self.RiX, 0, self.RiX, 150)
     #Draw a transparent rectangle to emphasize the selected area
     if (self.LeftClickFlag == 1 and self.RightClickFlag == 1
             and self.LeX != self.RiX):
         Colour = wx.Colour(139, 0, 255, 100)  #notice the alpha channel
         brush = wx.Brush(Colour)
         if self.RiX > self.LeX:
             width = self.RiX - self.LeX
             x = self.LeX
         else:
             width = self.LeX - self.RiX
             x = self.RiX
         height = self.bitmap.GetHeight()
         pdc = wx.GCDC(dc)
         pdc.SetBrush(brush)
         pdc.DrawRectangle(x, 0, width, height)
     dc.SetPen(wx.Pen('yellow', 1))
     dc.DrawLine(-self.CalcScrolledPosition(0, 0)[0] + 150, 0,
                 -self.CalcScrolledPosition(0, 0)[0] + 150, 150)
     dc.SetPen(wx.Pen('green', 1))
     dc.DrawLine(self.CurrPos, 0, self.CurrPos, 150)
     del odc
     #SKIP THE DRAWING OF RULER WHICH SEVERELY STUCK THE RENDERING
     event.Skip()
Exemplo n.º 12
0
 def cleanup(self):
     dc = wx.ClientDC(self.scroller)
     odc = wx.DCOverlay(self.scroller.overlay, dc)
     odc.Clear()
     del odc
     self.scroller.overlay.Reset()
     self.scroller.Refresh()
     self.world_coords = None
Exemplo n.º 13
0
 def finish_rectangle(self, event):
     self.finish_pos = self.enforce_ratio(event.GetPosition())
     self.redraw_rectangle(self.finish_pos)
     dc = wx.ClientDC(self)
     odc = wx.DCOverlay(self.overlay, dc)
     odc.Clear()
     del odc
     self.overlay.Reset()
     print "finish rectangle"
Exemplo n.º 14
0
 def redraw_rectangle(self, pos):
     rect = wx.RectPP(self.start_pos, pos)
     dc = wx.ClientDC(self.mplayer)
     odc = wx.DCOverlay(self.overlay, dc)
     odc.Clear()
     dc.SetPen(wx.Pen(wx.RED, 1, wx.SOLID))
     dc.SetBrush(wx.Brush("grey", style=wx.TRANSPARENT))
     dc.DrawRectangleRect(rect)
     del odc  #bug in python, this makes sure odc destroyed before dc
Exemplo n.º 15
0
    def imageMouseEvent(self, event):
        # See if there's a loaded picture
        if not len(self.images):
            return
        
        # See if user clicked on the image
        if event.ButtonDown():
            self.dragging = True
            self.dragStart = event.GetPosition()
            self.dragStop = event.GetPosition()
        elif event.ButtonUp() and self.currentObject:
            self.dragging = False
            
            # Clear the overlay
            self.overlay.Reset()
            
            # Smaller features than 10 by 10 pixels are not accepted
            if self.currentObject.GetWidth() < 10 or self.currentObject.GetHeight() < 10:
                self.currentObject = False
                return
            
            # Draw permanent marker on the picture itself
            self.drawRect(self.currentObject)
            
            # Save the last action
            self.selectedObjects.append(self.currentObject)
            self.currentObject = False

        # The user wants to delimit a feature
        if self.dragging:
            self.dragStop = event.GetPosition()
            
            dc = wx.ClientDC(self.image)
            odc = wx.DCOverlay(self.overlay, dc)
            odc.Clear()
            
            dc.SetPen(wx.Pen("red", style=wx.SOLID))
            dc.SetBrush(wx.Brush("red", wx.TRANSPARENT))
            w = abs(self.dragStart[0] - self.dragStop[0])
            h = abs(self.dragStart[1] - self.dragStop[1])
            
            # Make it so that the rectangle could be dragged in any way and constrain the rectangle to a square
            if self.dragStart[0] < self.dragStop[0]:
                x = self.dragStart[0]
            else:
                x = self.dragStop[0]
                
            if self.dragStart[1] < self.dragStop[1]:
                y = self.dragStart[1]
            else:
                y = self.dragStop[1]
            
            h = w
            
            self.currentObject = wx.Rect(x, y, w, h)
            dc.DrawRectangleRect(self.currentObject)
Exemplo n.º 16
0
    def shape_exit(self, event):
        if self.frame_on:
            ms = self.CalcUnscrolledPosition(
                self.ScreenToClient(self.frame.GetPosition()))
            rect = wx.Rect(ms[0], ms[1],
                           self.frame.GetSize()[0],
                           self.frame.GetSize()[1])
            dc = wx.BufferedDC(None, self.buffer)
            self.pen = wx.Pen()
            self.pen.SetWidth(self.pen_width)
            self.pen.SetColour(self.color)
            dc.SetPen(self.pen)
            dc.SetBrush(wx.TRANSPARENT_BRUSH)

            if paint.button_id == 100:
                dc.DrawCircle(
                    int((ms[0] + ((rect.GetSize()[0] / 2))) / self.user_scale),
                    int((ms[1] + ((rect.GetSize()[1] / 2))) / self.user_scale),
                    int(((min(abs(rect.GetSize()[0]), abs(rect.GetSize()[1])) /
                          2) - 10) / self.user_scale))

            elif paint.button_id == 110:
                dc.DrawRectangle(
                    int(ms[0] / self.user_scale), int(ms[1] / self.user_scale),
                    int(self.frame.GetSize()[0] / self.user_scale),
                    int(self.frame.GetSize()[1] / self.user_scale))

            elif paint.button_id == 120:
                dc.DrawEllipse(int(ms[0] / self.user_scale),
                               int(ms[1] / self.user_scale),
                               int(self.frame.GetSize()[0] / self.user_scale),
                               int(self.frame.GetSize()[1] / self.user_scale))

            elif paint.button_id == 130:
                dc.DrawLine(
                    int((ms[0] + abs(self.line_1x)) / self.user_scale),
                    int((ms[1] + abs(self.line_1y)) / self.user_scale),
                    int((ms[0] + rect.GetSize()[0] - abs(self.line_1x)) /
                        self.user_scale),
                    int((ms[1] + rect.GetSize()[1] - abs(self.line_1y)) /
                        self.user_scale))

            buffer_image = self.buffer.ConvertToImage()
            buffer_image.Rescale(self.size[0] * self.user_scale,
                                 self.size[1] * self.user_scale,
                                 wx.IMAGE_QUALITY_NORMAL)
            self.front_buffer = buffer_image.ConvertToBitmap(-1)
            self.frame.Destroy()
            dc = wx.ClientDC(self)
            odc = wx.DCOverlay(self.overlay, dc)
            odc.Clear()
            del odc
            self.overlay.Reset()
            self.Refresh()
Exemplo n.º 17
0
    def OnLeftUp(self, evt):
        if self.HasCapture():
            self.ReleaseMouse()
        self.startPos = None

        # When the mouse is released we reset the overlay and it
        # restores the former content to the window.
        dc = wx.ClientDC(self)
        odc = wx.DCOverlay(self.overlay, dc)
        odc.Clear()
        del odc
        self.overlay.Reset()
Exemplo n.º 18
0
    def OnMotion(self, evt):
        if not self.HasCapture():
            return

        dc = wx.ClientDC(self)
        odc = wx.DCOverlay(self.overlay, dc)
        odc.Clear()
        ctx = wx.GraphicsContext_Create(dc)
        ctx.SetPen(wx.GREY_PEN)
        ctx.SetBrush(wx.Brush(wx.Color(192, 192, 192, 128)))
        ctx.DrawRectangle(*wx.RectPP(self.selectionStart, evt.Position))
        del odc
Exemplo n.º 19
0
    def OnMouseMove(self, event):
        if event.Dragging() and event.LeftIsDown():
            evtPos = event.GetPosition()

            try:
                rect = wx.Rect(topLeft=self.startPos, bottomRight=evtPos)
            except TypeError as exc:  # topLeft = NoneType. Attempting to double click image or something
                return
            except Exception as exc:
                raise exc

            # Draw the rubber-band rectangle using an overlay so it
            # will manage keeping the rectangle and the former window
            # contents separate.
            dc = wx.ClientDC(self)
            odc = wx.DCOverlay(self.overlay, dc)
            odc.Clear()

            # Mac's DC is already the same as a GCDC, and it causes
            # problems with the overlay if we try to use an actual
            # wx.GCDC so don't try it.  If you do not need to use a
            # semi-transparent background then you can leave this out.
            if 'wxMac' not in wx.PlatformInfo:
                dc = wx.GCDC(dc)

            # Set the pen, for the box's border
            dc.SetPen(
                wx.Pen(
                    colour=self.overlayPenColor.GetColour(),
                    width=self.overlayPenWidth.GetValue(),
                    style=self.wxPenStylesDict[self.penstylesCombo.GetString(
                        self.penstylesCombo.GetSelection())]))

            # Create a brush (for the box's interior) with the same colour,
            # but 50% transparency.
            bc = self.overlayPenColor.GetColour()
            bc = wx.Colour(bc.red, bc.green, bc.blue, 0x80)
            dc.SetBrush(wx.Brush(bc))

            # Draw the rectangle
            dc.DrawRectangle(rect)

            if evtPos[0] < self.startPos[
                    0]:  # draw on left side of rect, not inside it
                dc.DrawBitmap(self.cropbitmap,
                              evtPos[0] - 25 - self.overlayPenWidth.GetValue(),
                              evtPos[1] - 17)
            else:
                dc.DrawBitmap(self.cropbitmap,
                              evtPos[0] + 2 + self.overlayPenWidth.GetValue(),
                              evtPos[1] - 17)

            del odc  # Make sure the odc is destroyed before the dc is.
Exemplo n.º 20
0
 def DoUnhighlight(self, tlw, rect):
     if not tlw:
         return
     if tlw.IsFrozen():
         tlw.Thaw()
     if self.useOverlay:
         dc = wx.ClientDC(tlw)
         dco = wx.DCOverlay(self.overlay, dc)
         dco.Clear()
         del dc, dco
         self.overlay.Reset()
     else:
         tlw.RefreshRect(rect)
Exemplo n.º 21
0
    def DrawSash_overlay(self, x, y, mode):
        if mode in ['press', 'move--']:
            # these are not needed for this implementation
            return

        if mode == 'release':
            dc = wx.ClientDC(self.m_container)
            odc = wx.DCOverlay(self.m_overlay, dc)
            odc.Clear()
            del odc
            self.m_overlay.Reset()

        if mode == 'move':
            dc = wx.ClientDC(self.m_container)
            odc = wx.DCOverlay(self.m_overlay, dc)
            odc.Clear()

            penclr = wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DDKSHADOW)
            dc.SetPen(wx.Pen(penclr, 1))
            bshclr = penclr.Get(False) + (0x80,)
            bshclr = wx.Colour(*bshclr)
            dc.SetBrush(wx.Brush(bshclr))

            self._doDrawSash(dc, x, y, False)
Exemplo n.º 22
0
    def OnMove(self, event):
        if event.Dragging() and event.LeftIsDown(
        ) and self.StartMove is not None:
            pos = event.GetPosition()
            #self.Refresh()
            dc = wx.ClientDC(self)
            odc = wx.DCOverlay(self.overlay, dc)
            odc.Clear()
            ## a black and white line so you can see it over any color.
            dc.SetPen(wx.Pen('WHITE', 2))
            dc.SetBrush(wx.TRANSPARENT_BRUSH)
            dc.DrawLinePoint(self.StartMove, pos)
            dc.SetPen(wx.Pen('BLACK', 2, wx.SHORT_DASH))
            dc.DrawLinePoint(self.StartMove, pos)

            del odc  # to ensure it gets delted before the Client
Exemplo n.º 23
0
    def OnLeftUp(self, event):
        if self.HasCapture():
            self.ReleaseMouse()
        self.endPos = event.GetPosition()
        ## print('StartPos: %s' %self.startPos)
        ## print('EndPos: %s' %self.endPos)
        self.startPos = None
        self.endPos = None

        # When the mouse is released we reset the overlay and it
        # restores the former content to the window.
        dc = wx.ClientDC(self)
        odc = wx.DCOverlay(self.overlay, dc)
        odc.Clear()
        del odc
        self.overlay.Reset()
Exemplo n.º 24
0
    def OnMouseMove(self, event):
        if event.Dragging() and event.LeftIsDown():
            evtPos = event.GetPosition()

            try:
                rect = wx.Rect(topLeft=self.startPos, bottomRight=evtPos)
            except TypeError as exc:  # topLeft = NoneType. Attempting to double click image or something
                return
            except Exception as exc:
                raise exc

            # Draw the rubber-band rectangle using an overlay so it
            # will manage keeping the rectangle and the former window
            # contents separate.
            dc = wx.ClientDC(self)
            odc = wx.DCOverlay(self.overlay, dc)
            odc.Clear()

            dc.SetPen(
                wx.Pen(
                    colour=self.overlayPenColor.GetColour(),
                    width=self.overlayPenWidth.GetValue(),
                    style=self.wxPenStylesDict[self.penstylesCombo.GetString(
                        self.penstylesCombo.GetSelection())]))
            if 'wxMac' in wx.PlatformInfo:
                dc.SetBrush(wx.Brush(wx.Colour(0xC0, 0xC0, 0xC0, 0x80)))
            else:
                dc.SetBrush(wx.TRANSPARENT_BRUSH)

            dc.DrawRectangle(rect)

            #Draw Pos Text
            ## text = u'%s'%evtPos
            ## width, height = dc.GetTextExtent(text)
            ## dc.DrawText(text, x=evtPos[0]+2, y=evtPos[1]-height)

            if evtPos[0] < self.startPos[
                    0]:  # draw on left side of rect, not inside it
                dc.DrawBitmap(self.cropbitmap,
                              evtPos[0] - 25 - self.overlayPenWidth.GetValue(),
                              evtPos[1] - 17)
            else:
                dc.DrawBitmap(self.cropbitmap,
                              evtPos[0] + 2 + self.overlayPenWidth.GetValue(),
                              evtPos[1] - 17)

            del odc  # Make sure the odc is destroyed before the dc is.
Exemplo n.º 25
0
 def on_up(self, event):
     if paint.pipette_on:
         event.Skip()
     elif paint.fill_on:
         event.Skip()
     elif paint.shape_on:
         self.t_shape.Stop()
         dc = wx.ClientDC(self)
         odc = wx.DCOverlay(self.overlay, dc)
         odc.Clear()
         del odc
         self.overlay.Reset()
         self.shape_on_up()
         event.Skip()
     else:
         self.t.Stop()
         event.Skip()
         self.coord = []
Exemplo n.º 26
0
    def OnMouseMove(self, evt):
        if evt.Dragging() and evt.LeftIsDown():
            rect = wx.RectPP(self.startPos, evt.GetPosition())

            # Draw the rubber-band rectangle using an overlay so it
            # will manage keeping the rectangle and the former window
            # contents separate.
            dc = wx.ClientDC(self)
            odc = wx.DCOverlay(self.overlay, dc)
            odc.Clear()

            dc.SetPen(wx.Pen("black", 2))
            if 'wxMac' in wx.PlatformInfo:
                dc.SetBrush(wx.Brush(wx.Colour(0xC0, 0xC0, 0xC0, 0x80)))
            else:
                dc.SetBrush(wx.TRANSPARENT_BRUSH)
            dc.DrawRectangleRect(rect)

            del odc  # work around a bug in the Python wrappers to make
Exemplo n.º 27
0
    def OnMotion(self, evt):
        if not self.HasCapture():
            return

        dc = wx.ClientDC(self)
        odc = wx.DCOverlay(self.overlay, dc)
        odc.Clear()
        if 'phoenix' in wx.version():
            ctx = wx.GraphicsContext.Create(dc)
        else:
            ctx = wx.GraphicsContext_Create(dc)
        ctx.SetPen(wx.GREY_PEN)
        ctx.SetBrush(wx.Brush(wx.Colour(192, 192, 192, 128)))
        if 'phoenix' in wx.version():
            ctx.DrawRectangle(self.selectionStart[0], self.selectionStart[0],
                              evt.Position[0], evt.Position[1])
        else:
            ctx.DrawRectangle(*wx.RectPP(self.selectionStart, evt.Position))
        del odc
Exemplo n.º 28
0
    def cleanup_docking(self, evt):
        if self.event_window.HasCapture():
            self.event_window.ReleaseMouse()
        pos = evt.GetPosition()

        # When the mouse is released we reset the overlay and it
        # restores the former content to the window.
        dc = wx.ClientDC(self.event_window)
        odc = wx.DCOverlay(self.overlay, dc)
        odc.Clear()
        del odc
        self.overlay.Reset()
        self.overlay = None

        self.drag_window.Destroy()
        self.drag_window = None
        self.event_window.Refresh()  # Force redraw

        return pos
Exemplo n.º 29
0
 def mouse_move(self, evt):
     "Move the selected object"
     if DEBUG: print "move!"
     if self.current and not self.overlay:
         wx_obj = self.current
         sx, sy = self.start
         x, y = wx.GetMousePosition()
         # calculate the new position (this will overwrite relative dimensions):
         x, y = (x + sx, y + sy)
         if evt.ShiftDown():     # snap to grid:
             x = x / GRID_SIZE[0] * GRID_SIZE[0]
             y = y / GRID_SIZE[1] * GRID_SIZE[1]
         # calculate the diff to use in the rest of the selected objects:
         ox, oy = wx_obj.obj.pos
         dx, dy = (x - ox), (y - oy)
         # move all selected objects:
         for obj in self.selection:
             x, y = obj.pos
             x = x + dx
             y = y + dy
             obj.pos = (wx.Point(x, y))
     elif self.overlay:
         wx_obj = self.current
         pos = evt.GetPosition()
         # convert to relative client coordinates of the containter:
         if evt.GetEventObject() != wx_obj:
             pos = evt.GetEventObject().ClientToScreen(pos)  # frame
             pos = wx_obj.ScreenToClient(pos)                # panel
         rect = wx.RectPP(self.pos, pos) 
         # Draw the rubber-band rectangle using an overlay so it 
         # will manage keeping the rectangle and the former window 
         # contents separate. 
         dc = wx.ClientDC(wx_obj) 
         odc = wx.DCOverlay(self.overlay, dc) 
         odc.Clear() 
         dc.SetPen(wx.Pen("blue", 2)) 
         if 'wxMac' in wx.PlatformInfo: 
             dc.SetBrush(wx.Brush(wx.Colour(0xC0, 0xC0, 0xC0, 0x80))) 
         else: 
             dc.SetBrush(wx.TRANSPARENT_BRUSH) 
         dc.DrawRectangleRect(rect)
         del odc # work around a bug in the Python wrappers to make 
Exemplo n.º 30
0
    def OnMouseMove(self, evt):
        if evt.Dragging() and evt.LeftIsDown():
            rect = wx.RectPP(self.startPos, evt.GetPosition())

            # Draw the rubber-band rectangle using an overlay so it
            # will manage keeping the rectangle and the former window
            # contents separate.
            dc = wx.ClientDC(self)
            odc = wx.DCOverlay(self.overlay, dc)
            odc.Clear()

            # Mac's DC is already the same as a GCDC, and it causes
            # problems with the overlay if we try to use an actual
            # wx.GCDC so don't try it.
            if 'wxMac' not in wx.PlatformInfo:
                dc = wx.GCDC(dc)

            dc.SetPen(wx.Pen("black", 2))
            dc.SetBrush(wx.Brush(wx.Colour(0xC0, 0xC0, 0xC0, 0x80)))
            dc.DrawRectangleRect(rect)