2003-07-02 19:13:10 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
import wx
|
|
|
|
import images
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestFrame(wx.Frame):
|
2003-07-02 19:13:10 -04:00
|
|
|
def __init__(self, parent, log):
|
|
|
|
self.log = log
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Frame.__init__(self, parent, -1, "Shaped Window",
|
2003-07-02 19:13:10 -04:00
|
|
|
style =
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.FRAME_SHAPED
|
|
|
|
| wx.SIMPLE_BORDER
|
|
|
|
| wx.FRAME_NO_TASKBAR
|
|
|
|
| wx.STAY_ON_TOP
|
2003-07-02 19:13:10 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
self.hasShape = False
|
2003-12-08 20:23:28 -05:00
|
|
|
self.delta = (0,0)
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
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)
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
self.bmp = images.getTuxBitmap()
|
|
|
|
w, h = self.bmp.GetWidth(), self.bmp.GetHeight()
|
|
|
|
self.SetClientSize( (w, h) )
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
if wx.Platform != "__WXMAC__":
|
2003-07-02 19:13:10 -04:00
|
|
|
# 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")
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
if wx.Platform == "__WXGTK__":
|
2003-07-02 19:13:10 -04:00
|
|
|
# wxGTK requires that the window be created before you can
|
|
|
|
# set its shape, so delay the call to SetWindowShape until
|
|
|
|
# this event.
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
|
2003-07-02 19:13:10 -04:00
|
|
|
else:
|
|
|
|
# On wxMSW and wxMac the window has already been created, so go for it.
|
|
|
|
self.SetWindowShape()
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
dc = wx.ClientDC(self)
|
2003-11-12 16:34:20 -05:00
|
|
|
dc.DrawBitmap(self.bmp, (0,0), True)
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def SetWindowShape(self, *evt):
|
|
|
|
# Use the bitmap's mask to determine the region
|
2003-12-08 20:23:28 -05:00
|
|
|
r = wx.RegionFromBitmap(self.bmp)
|
2003-07-02 19:13:10 -04:00
|
|
|
self.hasShape = self.SetShape(r)
|
|
|
|
|
|
|
|
|
|
|
|
def OnDoubleClick(self, evt):
|
|
|
|
if self.hasShape:
|
2003-12-08 20:23:28 -05:00
|
|
|
self.SetShape(wx.Region())
|
2003-07-02 19:13:10 -04:00
|
|
|
self.hasShape = False
|
|
|
|
else:
|
|
|
|
self.SetWindowShape()
|
|
|
|
|
|
|
|
|
|
|
|
def OnPaint(self, evt):
|
2003-12-08 20:23:28 -05:00
|
|
|
dc = wx.PaintDC(self)
|
2003-11-12 16:34:20 -05:00
|
|
|
dc.DrawBitmap(self.bmp, (0,0), True)
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
def OnExit(self, evt):
|
|
|
|
self.Close()
|
|
|
|
|
|
|
|
|
|
|
|
def OnLeftDown(self, evt):
|
|
|
|
self.CaptureMouse()
|
2003-12-08 20:23:28 -05:00
|
|
|
x, y = self.ClientToScreen(evt.GetPosition())
|
|
|
|
originx, originy = self.GetPosition()
|
|
|
|
dx = x - originx
|
|
|
|
dy = y - originy
|
|
|
|
self.delta = ((dx, dy))
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def OnLeftUp(self, evt):
|
|
|
|
if self.HasCapture():
|
|
|
|
self.ReleaseMouse()
|
|
|
|
|
|
|
|
|
|
|
|
def OnMouseMove(self, evt):
|
|
|
|
if evt.Dragging() and evt.LeftIsDown():
|
2003-12-08 20:23:28 -05:00
|
|
|
x, y = self.ClientToScreen(evt.GetPosition())
|
|
|
|
fp = (x - self.delta[0], y - self.delta[1])
|
2003-07-02 19:13:10 -04:00
|
|
|
self.Move(fp)
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestFrame(nb, log)
|
|
|
|
frame.otherWin = win
|
|
|
|
win.Show(True)
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overview = """<html><body>
|
|
|
|
<h2><center>Shaped Window</center></h2>
|
|
|
|
|
|
|
|
Top level windows now have a SetShape method that lets you set a
|
|
|
|
non-rectangular shape for the window using a wxRegion. All pixels
|
|
|
|
outside of the region will not be drawn and the window will not be
|
|
|
|
sensitive to the mouse in those areas either.
|
|
|
|
|
|
|
|
</body></html>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])])
|
|
|
|
|