]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ShapedWindow.py
mention ShouldInheritColours() change
[wxWidgets.git] / wxPython / demo / ShapedWindow.py
CommitLineData
1fded56b
RD
1
2from wxPython.wx import *
3import images
4
5#----------------------------------------------------------------------
6
7class TestFrame(wxFrame):
8 def __init__(self, parent, log):
9 self.log = log
10 wxFrame.__init__(self, parent, -1, "Shaped Window",
11 style =
12 wxFRAME_SHAPED
13 | wxSIMPLE_BORDER
14 | wxFRAME_NO_TASKBAR
15 | wxSTAY_ON_TOP
16 )
17
18 self.hasShape = False
19 self.delta = wxPoint(0,0)
20
21 EVT_LEFT_DCLICK(self, self.OnDoubleClick)
22 EVT_LEFT_DOWN(self, self.OnLeftDown)
23 EVT_LEFT_UP(self, self.OnLeftUp)
24 EVT_MOTION(self, self.OnMouseMove)
25 EVT_RIGHT_UP(self, self.OnExit)
26 EVT_PAINT(self, self.OnPaint)
27
28 self.bmp = images.getTuxBitmap()
29 w, h = self.bmp.GetWidth(), self.bmp.GetHeight()
30 self.SetClientSize( (w, h) )
31
32 if wxPlatform != "__WXMAC__":
33 # wxMac clips the tooltip to the window shape, YUCK!!!
34 self.SetToolTipString("Right-click to close the window\n"
35 "Double-click the image to set/unset the window shape")
36
37 if wxPlatform == "__WXGTK__":
38 # wxGTK requires that the window be created before you can
39 # set its shape, so delay the call to SetWindowShape until
40 # this event.
41 EVT_WINDOW_CREATE(self, self.SetWindowShape)
42 else:
43 # On wxMSW and wxMac the window has already been created, so go for it.
44 self.SetWindowShape()
45
46 dc = wxClientDC(self)
47 dc.DrawBitmap(self.bmp, 0,0, True)
48
49
50 def SetWindowShape(self, *evt):
51 # Use the bitmap's mask to determine the region
52 r = wxRegionFromBitmap(self.bmp)
53 self.hasShape = self.SetShape(r)
54
55
56 def OnDoubleClick(self, evt):
57 if self.hasShape:
58 self.SetShape(wxRegion())
59 self.hasShape = False
60 else:
61 self.SetWindowShape()
62
63
64 def OnPaint(self, evt):
65 dc = wxPaintDC(self)
66 dc.DrawBitmap(self.bmp, 0,0, True)
67
68 def OnExit(self, evt):
69 self.Close()
70
71
72 def OnLeftDown(self, evt):
73 self.CaptureMouse()
74 pos = self.ClientToScreen(evt.GetPosition())
75 origin = self.GetPosition()
76 dx = pos.x - origin.x
77 dy = pos.y - origin.y
78 self.delta = wxPoint(dx, dy)
79
80
81 def OnLeftUp(self, evt):
82 if self.HasCapture():
83 self.ReleaseMouse()
84
85
86 def OnMouseMove(self, evt):
87 if evt.Dragging() and evt.LeftIsDown():
88 pos = self.ClientToScreen(evt.GetPosition())
89 fp = (pos.x - self.delta.x, pos.y - self.delta.y)
90 self.Move(fp)
91
92
93#----------------------------------------------------------------------
94
95def runTest(frame, nb, log):
96 win = TestFrame(nb, log)
97 frame.otherWin = win
98 win.Show(True)
99
100
101#----------------------------------------------------------------------
102
103
104
105overview = """<html><body>
106<h2><center>Shaped Window</center></h2>
107
108Top level windows now have a SetShape method that lets you set a
109non-rectangular shape for the window using a wxRegion. All pixels
110outside of the region will not be drawn and the window will not be
111sensitive to the mouse in those areas either.
112
113</body></html>
114"""
115
116
117
118if __name__ == '__main__':
119 import sys,os
120 import run
121 run.main(['', os.path.basename(sys.argv[0])])
122