]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/samples/wxPIA_book/Chapter-08/shaped_frame.py
Added the sample code from wxPython In Action to the samples dir
[wxWidgets.git] / wxPython / samples / wxPIA_book / Chapter-08 / shaped_frame.py
diff --git a/wxPython/samples/wxPIA_book/Chapter-08/shaped_frame.py b/wxPython/samples/wxPIA_book/Chapter-08/shaped_frame.py
new file mode 100644 (file)
index 0000000..513ab46
--- /dev/null
@@ -0,0 +1,43 @@
+import wx
+import images
+
+class ShapedFrame(wx.Frame):
+    def __init__(self):
+        wx.Frame.__init__(self, None, -1, "Shaped Window",
+                style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER |
+                wx.FRAME_NO_TASKBAR)
+        self.hasShape = False
+        self.bmp = images.getVippiBitmap()
+        self.SetClientSize((self.bmp.GetWidth(), self.bmp.GetHeight()))
+        dc = wx.ClientDC(self)
+        dc.DrawBitmap(self.bmp, 0,0, True)
+        self.SetWindowShape()
+        self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)
+        self.Bind(wx.EVT_RIGHT_UP, self.OnExit)
+        self.Bind(wx.EVT_PAINT, self.OnPaint)
+        self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
+
+    def SetWindowShape(self, evt=None):
+        r = wx.RegionFromBitmap(self.bmp)
+        self.hasShape = self.SetShape(r)
+
+    def OnDoubleClick(self, evt):
+        if self.hasShape:
+            self.SetShape(wx.Region())
+            self.hasShape = False
+        else:
+            self.SetWindowShape()
+
+    def OnPaint(self, evt):
+        dc = wx.PaintDC(self)
+        dc.DrawBitmap(self.bmp, 0,0, True)
+
+    def OnExit(self, evt):
+        self.Close()
+
+if __name__ == '__main__':
+    app = wx.PySimpleApp()
+    ShapedFrame().Show()
+    app.MainLoop()
+
+