]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ShapedWindow.py
Add docstrings for ComboCtrl and ComboPopup, and added OwnerDrawnComboBox
[wxWidgets.git] / wxPython / demo / ShapedWindow.py
CommitLineData
1fded56b 1
8fa876ca
RD
2import wx
3import images
1fded56b
RD
4
5#----------------------------------------------------------------------
6
8fa876ca 7class TestFrame(wx.Frame):
1fded56b
RD
8 def __init__(self, parent, log):
9 self.log = log
8fa876ca 10 wx.Frame.__init__(self, parent, -1, "Shaped Window",
1fded56b 11 style =
8fa876ca
RD
12 wx.FRAME_SHAPED
13 | wx.SIMPLE_BORDER
14 | wx.FRAME_NO_TASKBAR
15 | wx.STAY_ON_TOP
1fded56b
RD
16 )
17
18 self.hasShape = False
8fa876ca 19 self.delta = (0,0)
1fded56b 20
8fa876ca
RD
21 self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)
22 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
23 self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
24 self.Bind(wx.EVT_MOTION, self.OnMouseMove)
25 self.Bind(wx.EVT_RIGHT_UP, self.OnExit)
26 self.Bind(wx.EVT_PAINT, self.OnPaint)
1fded56b 27
6c75a4cf 28 self.bmp = images.getVippiBitmap()
1fded56b
RD
29 w, h = self.bmp.GetWidth(), self.bmp.GetHeight()
30 self.SetClientSize( (w, h) )
31
8fa876ca 32 if wx.Platform != "__WXMAC__":
1fded56b
RD
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
8fa876ca 37 if wx.Platform == "__WXGTK__":
1fded56b
RD
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.
8fa876ca 41 self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
1fded56b
RD
42 else:
43 # On wxMSW and wxMac the window has already been created, so go for it.
44 self.SetWindowShape()
45
8fa876ca 46 dc = wx.ClientDC(self)
d7403ad2 47 dc.DrawBitmap(self.bmp, 0,0, True)
1fded56b
RD
48
49
50 def SetWindowShape(self, *evt):
51 # Use the bitmap's mask to determine the region
8fa876ca 52 r = wx.RegionFromBitmap(self.bmp)
1fded56b
RD
53 self.hasShape = self.SetShape(r)
54
55
56 def OnDoubleClick(self, evt):
57 if self.hasShape:
8fa876ca 58 self.SetShape(wx.Region())
1fded56b
RD
59 self.hasShape = False
60 else:
61 self.SetWindowShape()
62
63
64 def OnPaint(self, evt):
8fa876ca 65 dc = wx.PaintDC(self)
d7403ad2 66 dc.DrawBitmap(self.bmp, 0,0, True)
1fded56b
RD
67
68 def OnExit(self, evt):
69 self.Close()
70
71
72 def OnLeftDown(self, evt):
73 self.CaptureMouse()
8fa876ca
RD
74 x, y = self.ClientToScreen(evt.GetPosition())
75 originx, originy = self.GetPosition()
76 dx = x - originx
77 dy = y - originy
78 self.delta = ((dx, dy))
1fded56b
RD
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():
8fa876ca
RD
88 x, y = self.ClientToScreen(evt.GetPosition())
89 fp = (x - self.delta[0], y - self.delta[1])
1fded56b
RD
90 self.Move(fp)
91
92
34a544a6 93#---------------------------------------------------------------------------
1fded56b 94
34a544a6
RD
95class TestPanel(wx.Panel):
96 def __init__(self, parent, log):
97 self.log = log
98 wx.Panel.__init__(self, parent, -1)
99
100 b = wx.Button(self, -1, "Show the ShapedWindow sample", (50,50))
101 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
1fded56b
RD
102
103
34a544a6
RD
104 def OnButton(self, evt):
105 win = TestFrame(self, self.log)
106 win.Show(True)
107
108#---------------------------------------------------------------------------
109
110
111def runTest(frame, nb, log):
112 win = TestPanel(nb, log)
113 return win
114
1fded56b
RD
115#----------------------------------------------------------------------
116
117
118
119overview = """<html><body>
120<h2><center>Shaped Window</center></h2>
121
122Top level windows now have a SetShape method that lets you set a
123non-rectangular shape for the window using a wxRegion. All pixels
124outside of the region will not be drawn and the window will not be
125sensitive to the mouse in those areas either.
126
127</body></html>
128"""
129
130
131
132if __name__ == '__main__':
133 import sys,os
134 import run
8eca4fef 135 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1fded56b 136