X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b166c70307f14952b3844837c98602425020e1c5..ed8e1ecb3fdabbbe5062ebba2a50a2bc8d1e2c76:/wxPython/demo/wxDragImage.py diff --git a/wxPython/demo/wxDragImage.py b/wxPython/demo/wxDragImage.py index d53fb4c67b..4c348637cf 100644 --- a/wxPython/demo/wxDragImage.py +++ b/wxPython/demo/wxDragImage.py @@ -9,14 +9,14 @@ class DragShape: def __init__(self, bmp): self.bmp = bmp self.pos = wxPoint(0,0) - self.shown = true + self.shown = True self.text = None - self.fullscreen = false + self.fullscreen = False def HitTest(self, pt): rect = self.GetRect() - return rect.Inside(pt.x, pt.y) + return rect.InsideXY(pt.x, pt.y) def GetRect(self): @@ -29,13 +29,13 @@ class DragShape: memDC = wxMemoryDC() memDC.SelectObject(self.bmp) - dc.Blit(self.pos.x, self.pos.y, - self.bmp.GetWidth(), self.bmp.GetHeight(), - memDC, 0, 0, op, true) + dc.Blit((self.pos.x, self.pos.y), + (self.bmp.GetWidth(), self.bmp.GetHeight()), + memDC, (0, 0), op, True) - return true + return True else: - return false + return False @@ -58,24 +58,25 @@ class DragCanvas(wxScrolledWindow): bmp = images.getTestStarBitmap() shape = DragShape(bmp) shape.pos = wxPoint(5, 5) - shape.fullscreen = true + shape.fullscreen = True self.shapes.append(shape) # Make a shape from some text text = "Some Text" + bg_colour = wxColour(57, 115, 57) # matches the bg image font = wxFont(15, wxROMAN, wxNORMAL, wxBOLD) textExtent = self.GetFullTextExtent(text, font) bmp = wxEmptyBitmap(textExtent[0], textExtent[1]) dc = wxMemoryDC() dc.SelectObject(bmp) + dc.SetBackground(wxBrush(bg_colour, wxSOLID)) dc.Clear() dc.SetTextForeground(wxRED) dc.SetFont(font) - dc.DrawText(text, 0, 0) + dc.DrawText(text, (0, 0)) dc.SelectObject(wxNullBitmap) - del dc - mask = wxMaskColour(bmp, wxWHITE) + mask = wxMaskColour(bmp, bg_colour) bmp.SetMask(mask) shape = DragShape(bmp) shape.pos = wxPoint(5, 100) @@ -99,8 +100,12 @@ class DragCanvas(wxScrolledWindow): EVT_LEFT_DOWN(self, self.OnLeftDown) EVT_LEFT_UP(self, self.OnLeftUp) EVT_MOTION(self, self.OnMotion) + EVT_LEAVE_WINDOW(self, self.OnLeaveWindow) + def OnLeaveWindow(self, evt): + pass + def TileBackground(self, dc): # tile the background bitmap @@ -112,7 +117,7 @@ class DragCanvas(wxScrolledWindow): while x < sz.width: y = 0 while y < sz.height: - dc.DrawBitmap(self.bg_bmp, x, y) + dc.DrawBitmap(self.bg_bmp, (x, y)) y = y + h x = x + w @@ -132,7 +137,7 @@ class DragCanvas(wxScrolledWindow): def EraseShape(self, shape, dc): r = shape.GetRect() - dc.SetClippingRegion(r.x, r.y, r.width, r.height) + dc.SetClippingRect(r) self.TileBackground(dc) self.DrawShapes(dc) dc.DestroyClippingRegion() @@ -143,7 +148,7 @@ class DragCanvas(wxScrolledWindow): if not dc: dc = wxClientDC(self) rect = self.GetUpdateRegion().GetBox() - dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height) + dc.SetClippingRect(rect) self.TileBackground(dc) @@ -180,7 +185,7 @@ class DragCanvas(wxScrolledWindow): # reposition and draw the shape self.dragShape.pos = self.dragShape.pos + evt.GetPosition() - self.dragStartPos - self.dragShape.shown = true + self.dragShape.shown = True self.dragShape.Draw(dc) self.dragShape = None @@ -189,7 +194,7 @@ class DragCanvas(wxScrolledWindow): if not self.dragShape or not evt.Dragging() or not evt.LeftIsDown(): return - # if we have a shape, but havn't started dragging yet + # if we have a shape, but haven't started dragging yet if self.dragShape and not self.dragImage: # only start the drag after having moved a couple pixels @@ -202,7 +207,7 @@ class DragCanvas(wxScrolledWindow): # erase the shape since it will be drawn independently now dc = wxClientDC(self) - self.dragShape.shown = false + self.dragShape.shown = False self.EraseShape(self.dragShape, dc) @@ -223,16 +228,16 @@ class DragCanvas(wxScrolledWindow): # if we have shape and image then move it, posibly highlighting another shape. elif self.dragShape and self.dragImage: onShape = self.FindShape(evt.GetPosition()) - unhiliteOld = false - hiliteNew = false + unhiliteOld = False + hiliteNew = False # figure out what to hilite and what to unhilite if self.hiliteShape: if onShape is None or self.hiliteShape is not onShape: - unhiliteOld = true + unhiliteOld = True if onShape and onShape is not self.hiliteShape and onShape.shown: - hiliteNew = TRUE + hiliteNew = True # if needed, hide the drag image so we can update the window if unhiliteOld or hiliteNew: @@ -257,7 +262,10 @@ class DragCanvas(wxScrolledWindow): #---------------------------------------------------------------------- def runTest(frame, nb, log): - win = DragCanvas(nb, -1) + win = wxPanel(nb, -1) + canvas = DragCanvas(win, -1) + def onSize(evt, panel=win, canvas=canvas): canvas.SetSize(panel.GetSize()) + EVT_SIZE(win, onSize) return win #---------------------------------------------------------------------- @@ -266,3 +274,10 @@ def runTest(frame, nb, log): overview = """\ """ + + +if __name__ == '__main__': + import sys,os + import run + run.main(['', os.path.basename(sys.argv[0])]) +