X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d14a1e28567de23c586bc80017073d0c39f8d18f..414dfb5804fc568b26fec3f8a8ecc2f25addedfd:/wxPython/demo/ShapedWindow.py diff --git a/wxPython/demo/ShapedWindow.py b/wxPython/demo/ShapedWindow.py index e484f96aad..26361a7d12 100644 --- a/wxPython/demo/ShapedWindow.py +++ b/wxPython/demo/ShapedWindow.py @@ -1,69 +1,69 @@ -from wxPython.wx import * -import images +import wx +import images #---------------------------------------------------------------------- -class TestFrame(wxFrame): +class TestFrame(wx.Frame): def __init__(self, parent, log): self.log = log - wxFrame.__init__(self, parent, -1, "Shaped Window", + wx.Frame.__init__(self, parent, -1, "Shaped Window", style = - wxFRAME_SHAPED - | wxSIMPLE_BORDER - | wxFRAME_NO_TASKBAR - | wxSTAY_ON_TOP + wx.FRAME_SHAPED + | wx.SIMPLE_BORDER + | wx.FRAME_NO_TASKBAR + | wx.STAY_ON_TOP ) self.hasShape = False - self.delta = wxPoint(0,0) + self.delta = (0,0) - EVT_LEFT_DCLICK(self, self.OnDoubleClick) - EVT_LEFT_DOWN(self, self.OnLeftDown) - EVT_LEFT_UP(self, self.OnLeftUp) - EVT_MOTION(self, self.OnMouseMove) - EVT_RIGHT_UP(self, self.OnExit) - EVT_PAINT(self, self.OnPaint) + self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick) + self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) + self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) + self.Bind(wx.EVT_MOTION, self.OnMouseMove) + self.Bind(wx.EVT_RIGHT_UP, self.OnExit) + self.Bind(wx.EVT_PAINT, self.OnPaint) self.bmp = images.getTuxBitmap() w, h = self.bmp.GetWidth(), self.bmp.GetHeight() self.SetClientSize( (w, h) ) - if wxPlatform != "__WXMAC__": + if wx.Platform != "__WXMAC__": # wxMac clips the tooltip to the window shape, YUCK!!! self.SetToolTipString("Right-click to close the window\n" "Double-click the image to set/unset the window shape") - if wxPlatform == "__WXGTK__": + if wx.Platform == "__WXGTK__": # wxGTK requires that the window be created before you can # set its shape, so delay the call to SetWindowShape until # this event. - EVT_WINDOW_CREATE(self, self.SetWindowShape) + self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape) else: # On wxMSW and wxMac the window has already been created, so go for it. self.SetWindowShape() - dc = wxClientDC(self) - dc.DrawBitmap(self.bmp, (0,0), True) + dc = wx.ClientDC(self) + dc.DrawBitmap(self.bmp, 0,0, True) def SetWindowShape(self, *evt): # Use the bitmap's mask to determine the region - r = wxRegionFromBitmap(self.bmp) + r = wx.RegionFromBitmap(self.bmp) self.hasShape = self.SetShape(r) def OnDoubleClick(self, evt): if self.hasShape: - self.SetShape(wxRegion()) + self.SetShape(wx.Region()) self.hasShape = False else: self.SetWindowShape() def OnPaint(self, evt): - dc = wxPaintDC(self) - dc.DrawBitmap(self.bmp, (0,0), True) + dc = wx.PaintDC(self) + dc.DrawBitmap(self.bmp, 0,0, True) def OnExit(self, evt): self.Close() @@ -71,11 +71,11 @@ class TestFrame(wxFrame): def OnLeftDown(self, evt): self.CaptureMouse() - pos = self.ClientToScreen(evt.GetPosition()) - origin = self.GetPosition() - dx = pos.x - origin.x - dy = pos.y - origin.y - self.delta = wxPoint(dx, dy) + x, y = self.ClientToScreen(evt.GetPosition()) + originx, originy = self.GetPosition() + dx = x - originx + dy = y - originy + self.delta = ((dx, dy)) def OnLeftUp(self, evt): @@ -85,19 +85,33 @@ class TestFrame(wxFrame): def OnMouseMove(self, evt): if evt.Dragging() and evt.LeftIsDown(): - pos = self.ClientToScreen(evt.GetPosition()) - fp = (pos.x - self.delta.x, pos.y - self.delta.y) + x, y = self.ClientToScreen(evt.GetPosition()) + fp = (x - self.delta[0], y - self.delta[1]) self.Move(fp) -#---------------------------------------------------------------------- +#--------------------------------------------------------------------------- -def runTest(frame, nb, log): - win = TestFrame(nb, log) - frame.otherWin = win - win.Show(True) +class TestPanel(wx.Panel): + def __init__(self, parent, log): + self.log = log + wx.Panel.__init__(self, parent, -1) + + b = wx.Button(self, -1, "Show the ShapedWindow sample", (50,50)) + self.Bind(wx.EVT_BUTTON, self.OnButton, b) + def OnButton(self, evt): + win = TestFrame(self, self.log) + win.Show(True) + +#--------------------------------------------------------------------------- + + +def runTest(frame, nb, log): + win = TestPanel(nb, log) + return win + #---------------------------------------------------------------------- @@ -118,5 +132,5 @@ sensitive to the mouse in those areas either. if __name__ == '__main__': import sys,os import run - run.main(['', os.path.basename(sys.argv[0])]) + run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])