]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ShapedWindow.py
1 # 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
9 #----------------------------------------------------------------------
11 class TestFrame(wx
.Frame
):
12 def __init__(self
, parent
, log
):
14 wx
.Frame
.__init
__(self
, parent
, -1, "Shaped Window",
25 self
.Bind(wx
.EVT_LEFT_DCLICK
, self
.OnDoubleClick
)
26 self
.Bind(wx
.EVT_LEFT_DOWN
, self
.OnLeftDown
)
27 self
.Bind(wx
.EVT_LEFT_UP
, self
.OnLeftUp
)
28 self
.Bind(wx
.EVT_MOTION
, self
.OnMouseMove
)
29 self
.Bind(wx
.EVT_RIGHT_UP
, self
.OnExit
)
30 self
.Bind(wx
.EVT_PAINT
, self
.OnPaint
)
32 self
.bmp
= images
.getTuxBitmap()
33 w
, h
= self
.bmp
.GetWidth(), self
.bmp
.GetHeight()
34 self
.SetClientSize( (w
, h
) )
36 if wx
.Platform
!= "__WXMAC__":
37 # wxMac clips the tooltip to the window shape, YUCK!!!
38 self
.SetToolTipString("Right-click to close the window\n"
39 "Double-click the image to set/unset the window shape")
41 if wx
.Platform
== "__WXGTK__":
42 # wxGTK requires that the window be created before you can
43 # set its shape, so delay the call to SetWindowShape until
45 self
.Bind(wx
.EVT_WINDOW_CREATE
, self
.SetWindowShape
)
47 # On wxMSW and wxMac the window has already been created, so go for it.
50 dc
= wx
.ClientDC(self
)
51 dc
.DrawBitmap(self
.bmp
, (0,0), True)
54 def SetWindowShape(self
, *evt
):
55 # Use the bitmap's mask to determine the region
56 r
= wx
.RegionFromBitmap(self
.bmp
)
57 self
.hasShape
= self
.SetShape(r
)
60 def OnDoubleClick(self
, evt
):
62 self
.SetShape(wx
.Region())
68 def OnPaint(self
, evt
):
70 dc
.DrawBitmap(self
.bmp
, (0,0), True)
72 def OnExit(self
, evt
):
76 def OnLeftDown(self
, evt
):
78 x
, y
= self
.ClientToScreen(evt
.GetPosition())
79 originx
, originy
= self
.GetPosition()
82 self
.delta
= ((dx
, dy
))
85 def OnLeftUp(self
, evt
):
90 def OnMouseMove(self
, evt
):
91 if evt
.Dragging() and evt
.LeftIsDown():
92 x
, y
= self
.ClientToScreen(evt
.GetPosition())
93 fp
= (x
- self
.delta
[0], y
- self
.delta
[1])
97 #----------------------------------------------------------------------
99 def runTest(frame
, nb
, log
):
100 win
= TestFrame(nb
, log
)
105 #----------------------------------------------------------------------
109 overview
= """<html><body>
110 <h2><center>Shaped Window</center></h2>
112 Top level windows now have a SetShape method that lets you set a
113 non-rectangular shape for the window using a wxRegion. All pixels
114 outside of the region will not be drawn and the window will not be
115 sensitive to the mouse in those areas either.
122 if __name__
== '__main__':
125 run
.main(['', os
.path
.basename(sys
.argv
[0])])