]>
Commit | Line | Data |
---|---|---|
be05b434 RD |
1 | import wx |
2 | import images | |
3 | ||
4 | class ShapedFrame(wx.Frame): | |
5 | def __init__(self): | |
6 | wx.Frame.__init__(self, None, -1, "Shaped Window", | |
7 | style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER ) | |
8 | self.hasShape = False | |
9 | self.delta = wx.Point(0,0) | |
10 | self.bmp = images.getVippiBitmap() | |
11 | self.SetClientSize((self.bmp.GetWidth(), self.bmp.GetHeight())) | |
12 | dc = wx.ClientDC(self) | |
13 | dc.DrawBitmap(self.bmp, 0,0, True) | |
14 | self.SetWindowShape() | |
15 | self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick) | |
16 | self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) | |
17 | self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) | |
18 | self.Bind(wx.EVT_MOTION, self.OnMouseMove) | |
19 | self.Bind(wx.EVT_RIGHT_UP, self.OnExit) | |
20 | self.Bind(wx.EVT_PAINT, self.OnPaint) | |
21 | self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape) | |
22 | ||
23 | def SetWindowShape(self, evt=None): | |
24 | r = wx.RegionFromBitmap(self.bmp) | |
25 | self.hasShape = self.SetShape(r) | |
26 | ||
27 | def OnDoubleClick(self, evt): | |
28 | if self.hasShape: | |
29 | self.SetShape(wx.Region()) | |
30 | self.hasShape = False | |
31 | else: | |
32 | self.SetWindowShape() | |
33 | ||
34 | def OnPaint(self, evt): | |
35 | dc = wx.PaintDC(self) | |
36 | dc.DrawBitmap(self.bmp, 0,0, True) | |
37 | ||
38 | def OnExit(self, evt): | |
39 | self.Close() | |
40 | ||
41 | def OnLeftDown(self, evt): | |
42 | self.CaptureMouse() | |
43 | pos = self.ClientToScreen(evt.GetPosition()) | |
44 | origin = self.GetPosition() | |
45 | self.delta = wx.Point(pos.x - origin.x, pos.y - origin.y) | |
46 | ||
47 | def OnMouseMove(self, evt): | |
48 | if evt.Dragging() and evt.LeftIsDown(): | |
49 | pos = self.ClientToScreen(evt.GetPosition()) | |
50 | newPos = (pos.x - self.delta.x, pos.y - self.delta.y) | |
51 | self.Move(newPos) | |
52 | ||
53 | def OnLeftUp(self, evt): | |
54 | if self.HasCapture(): | |
55 | self.ReleaseMouse() | |
56 | ||
57 | ||
58 | ||
59 | if __name__ == '__main__': | |
60 | app = wx.PySimpleApp() | |
61 | ShapedFrame().Show() | |
62 | app.MainLoop() | |
63 | ||
64 |