2003-07-02 23:13:10 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
import wx
|
|
|
|
import images
|
2003-07-02 23:13:10 +00:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
class TestFrame(wx.Frame):
|
2003-07-02 23:13:10 +00:00
|
|
|
def __init__(self, parent, log):
|
|
|
|
self.log = log
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.Frame.__init__(self, parent, -1, "Shaped Window",
|
2003-07-02 23:13:10 +00:00
|
|
|
style =
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.FRAME_SHAPED
|
|
|
|
| wx.SIMPLE_BORDER
|
|
|
|
| wx.FRAME_NO_TASKBAR
|
|
|
|
| wx.STAY_ON_TOP
|
2003-07-02 23:13:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
self.hasShape = False
|
2003-12-09 01:23:28 +00:00
|
|
|
self.delta = (0,0)
|
2003-07-02 23:13:10 +00:00
|
|
|
|
2003-12-09 01:23:28 +00: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 23:13:10 +00:00
|
|
|
|
|
|
|
self.bmp = images.getTuxBitmap()
|
|
|
|
w, h = self.bmp.GetWidth(), self.bmp.GetHeight()
|
|
|
|
self.SetClientSize( (w, h) )
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
if wx.Platform != "__WXMAC__":
|
2003-07-02 23:13:10 +00: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-09 01:23:28 +00:00
|
|
|
if wx.Platform == "__WXGTK__":
|
2003-07-02 23:13:10 +00: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-09 01:23:28 +00:00
|
|
|
self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
|
2003-07-02 23:13:10 +00:00
|
|
|
else:
|
|
|
|
# On wxMSW and wxMac the window has already been created, so go for it.
|
|
|
|
self.SetWindowShape()
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
dc = wx.ClientDC(self)
|
2004-05-02 02:41:33 +00:00
|
|
|
dc.DrawBitmap(self.bmp, 0,0, True)
|
2003-07-02 23:13:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def SetWindowShape(self, *evt):
|
|
|
|
# Use the bitmap's mask to determine the region
|
2003-12-09 01:23:28 +00:00
|
|
|
r = wx.RegionFromBitmap(self.bmp)
|
2003-07-02 23:13:10 +00:00
|
|
|
self.hasShape = self.SetShape(r)
|
|
|
|
|
|
|
|
|
|
|
|
def OnDoubleClick(self, evt):
|
|
|
|
if self.hasShape:
|
2003-12-09 01:23:28 +00:00
|
|
|
self.SetShape(wx.Region())
|
2003-07-02 23:13:10 +00:00
|
|
|
self.hasShape = False
|
|
|
|
else:
|
|
|
|
self.SetWindowShape()
|
|
|
|
|
|
|
|
|
|
|
|
def OnPaint(self, evt):
|
2003-12-09 01:23:28 +00:00
|
|
|
dc = wx.PaintDC(self)
|
2004-05-02 02:41:33 +00:00
|
|
|
dc.DrawBitmap(self.bmp, 0,0, True)
|
2003-07-02 23:13:10 +00:00
|
|
|
|
|
|
|
def OnExit(self, evt):
|
|
|
|
self.Close()
|
|
|
|
|
|
|
|
|
|
|
|
def OnLeftDown(self, evt):
|
|
|
|
self.CaptureMouse()
|
2003-12-09 01:23:28 +00:00
|
|
|
x, y = self.ClientToScreen(evt.GetPosition())
|
|
|
|
originx, originy = self.GetPosition()
|
|
|
|
dx = x - originx
|
|
|
|
dy = y - originy
|
|
|
|
self.delta = ((dx, dy))
|
2003-07-02 23:13:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def OnLeftUp(self, evt):
|
|
|
|
if self.HasCapture():
|
|
|
|
self.ReleaseMouse()
|
|
|
|
|
|
|
|
|
|
|
|
def OnMouseMove(self, evt):
|
|
|
|
if evt.Dragging() and evt.LeftIsDown():
|
2003-12-09 01:23:28 +00:00
|
|
|
x, y = self.ClientToScreen(evt.GetPosition())
|
|
|
|
fp = (x - self.delta[0], y - self.delta[1])
|
2003-07-02 23:13:10 +00:00
|
|
|
self.Move(fp)
|
|
|
|
|
|
|
|
|
2004-08-10 01:21:16 +00:00
|
|
|
#---------------------------------------------------------------------------
|
2003-07-02 23:13:10 +00:00
|
|
|
|
2004-08-10 01:21:16 +00:00
|
|
|
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)
|
2003-07-02 23:13:10 +00:00
|
|
|
|
|
|
|
|
2004-08-10 01:21:16 +00:00
|
|
|
def OnButton(self, evt):
|
|
|
|
win = TestFrame(self, self.log)
|
|
|
|
win.Show(True)
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
|
2003-07-02 23:13:10 +00:00
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2004-03-05 00:06:33 +00:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
2003-07-02 23:13:10 +00:00
|
|
|
|