]>
Commit | Line | Data |
---|---|---|
8fa876ca RD |
1 | # 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
2 | # | |
3 | # o Updated for wx namespace | |
4 | # | |
1fded56b | 5 | |
8fa876ca RD |
6 | import wx |
7 | import images | |
1fded56b RD |
8 | |
9 | #---------------------------------------------------------------------- | |
10 | ||
8fa876ca | 11 | class TestFrame(wx.Frame): |
1fded56b RD |
12 | def __init__(self, parent, log): |
13 | self.log = log | |
8fa876ca | 14 | wx.Frame.__init__(self, parent, -1, "Shaped Window", |
1fded56b | 15 | style = |
8fa876ca RD |
16 | wx.FRAME_SHAPED |
17 | | wx.SIMPLE_BORDER | |
18 | | wx.FRAME_NO_TASKBAR | |
19 | | wx.STAY_ON_TOP | |
1fded56b RD |
20 | ) |
21 | ||
22 | self.hasShape = False | |
8fa876ca | 23 | self.delta = (0,0) |
1fded56b | 24 | |
8fa876ca RD |
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) | |
1fded56b RD |
31 | |
32 | self.bmp = images.getTuxBitmap() | |
33 | w, h = self.bmp.GetWidth(), self.bmp.GetHeight() | |
34 | self.SetClientSize( (w, h) ) | |
35 | ||
8fa876ca | 36 | if wx.Platform != "__WXMAC__": |
1fded56b RD |
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") | |
40 | ||
8fa876ca | 41 | if wx.Platform == "__WXGTK__": |
1fded56b RD |
42 | # wxGTK requires that the window be created before you can |
43 | # set its shape, so delay the call to SetWindowShape until | |
44 | # this event. | |
8fa876ca | 45 | self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape) |
1fded56b RD |
46 | else: |
47 | # On wxMSW and wxMac the window has already been created, so go for it. | |
48 | self.SetWindowShape() | |
49 | ||
8fa876ca | 50 | dc = wx.ClientDC(self) |
d14a1e28 | 51 | dc.DrawBitmap(self.bmp, (0,0), True) |
1fded56b RD |
52 | |
53 | ||
54 | def SetWindowShape(self, *evt): | |
55 | # Use the bitmap's mask to determine the region | |
8fa876ca | 56 | r = wx.RegionFromBitmap(self.bmp) |
1fded56b RD |
57 | self.hasShape = self.SetShape(r) |
58 | ||
59 | ||
60 | def OnDoubleClick(self, evt): | |
61 | if self.hasShape: | |
8fa876ca | 62 | self.SetShape(wx.Region()) |
1fded56b RD |
63 | self.hasShape = False |
64 | else: | |
65 | self.SetWindowShape() | |
66 | ||
67 | ||
68 | def OnPaint(self, evt): | |
8fa876ca | 69 | dc = wx.PaintDC(self) |
d14a1e28 | 70 | dc.DrawBitmap(self.bmp, (0,0), True) |
1fded56b RD |
71 | |
72 | def OnExit(self, evt): | |
73 | self.Close() | |
74 | ||
75 | ||
76 | def OnLeftDown(self, evt): | |
77 | self.CaptureMouse() | |
8fa876ca RD |
78 | x, y = self.ClientToScreen(evt.GetPosition()) |
79 | originx, originy = self.GetPosition() | |
80 | dx = x - originx | |
81 | dy = y - originy | |
82 | self.delta = ((dx, dy)) | |
1fded56b RD |
83 | |
84 | ||
85 | def OnLeftUp(self, evt): | |
86 | if self.HasCapture(): | |
87 | self.ReleaseMouse() | |
88 | ||
89 | ||
90 | def OnMouseMove(self, evt): | |
91 | if evt.Dragging() and evt.LeftIsDown(): | |
8fa876ca RD |
92 | x, y = self.ClientToScreen(evt.GetPosition()) |
93 | fp = (x - self.delta[0], y - self.delta[1]) | |
1fded56b RD |
94 | self.Move(fp) |
95 | ||
96 | ||
97 | #---------------------------------------------------------------------- | |
98 | ||
99 | def runTest(frame, nb, log): | |
100 | win = TestFrame(nb, log) | |
101 | frame.otherWin = win | |
102 | win.Show(True) | |
103 | ||
104 | ||
105 | #---------------------------------------------------------------------- | |
106 | ||
107 | ||
108 | ||
109 | overview = """<html><body> | |
110 | <h2><center>Shaped Window</center></h2> | |
111 | ||
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. | |
116 | ||
117 | </body></html> | |
118 | """ | |
119 | ||
120 | ||
121 | ||
122 | if __name__ == '__main__': | |
123 | import sys,os | |
124 | import run | |
125 | run.main(['', os.path.basename(sys.argv[0])]) | |
126 |