]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ShapedWindow.py
   5 #---------------------------------------------------------------------- 
   7 class TestFrame(wx
.Frame
): 
   8     def __init__(self
, parent
, log
): 
  10         wx
.Frame
.__init
__(self
, parent
, -1, "Shaped Window", 
  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
) 
  28         self
.bmp 
= images
.getVippiBitmap() 
  29         w
, h 
= self
.bmp
.GetWidth(), self
.bmp
.GetHeight() 
  30         self
.SetClientSize( (w
, h
) ) 
  32         if wx
.Platform 
!= "__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") 
  37         if wx
.Platform 
== "__WXGTK__": 
  38             # wxGTK requires that the window be created before you can 
  39             # set its shape, so delay the call to SetWindowShape until 
  41             self
.Bind(wx
.EVT_WINDOW_CREATE
, self
.SetWindowShape
) 
  43             # On wxMSW and wxMac the window has already been created, so go for it. 
  46         dc 
= wx
.ClientDC(self
) 
  47         dc
.DrawBitmap(self
.bmp
, 0,0, True) 
  50     def SetWindowShape(self
, *evt
): 
  51         # Use the bitmap's mask to determine the region 
  52         r 
= wx
.RegionFromBitmap(self
.bmp
) 
  53         self
.hasShape 
= self
.SetShape(r
) 
  56     def OnDoubleClick(self
, evt
): 
  58             self
.SetShape(wx
.Region()) 
  64     def OnPaint(self
, evt
): 
  66         dc
.DrawBitmap(self
.bmp
, 0,0, True) 
  68     def OnExit(self
, evt
): 
  72     def OnLeftDown(self
, evt
): 
  74         x
, y 
= self
.ClientToScreen(evt
.GetPosition()) 
  75         originx
, originy 
= self
.GetPosition() 
  78         self
.delta 
= ((dx
, dy
)) 
  81     def OnLeftUp(self
, evt
): 
  86     def OnMouseMove(self
, evt
): 
  87         if evt
.Dragging() and evt
.LeftIsDown(): 
  88             x
, y 
= self
.ClientToScreen(evt
.GetPosition()) 
  89             fp 
= (x 
- self
.delta
[0], y 
- self
.delta
[1]) 
  93 #--------------------------------------------------------------------------- 
  95 class TestPanel(wx
.Panel
): 
  96     def __init__(self
, parent
, log
): 
  98         wx
.Panel
.__init
__(self
, parent
, -1) 
 100         b 
= wx
.Button(self
, -1, "Show the ShapedWindow sample", (50,50)) 
 101         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
 104     def OnButton(self
, evt
): 
 105         win 
= TestFrame(self
, self
.log
) 
 108 #--------------------------------------------------------------------------- 
 111 def runTest(frame
, nb
, log
): 
 112     win 
= TestPanel(nb
, log
) 
 115 #---------------------------------------------------------------------- 
 119 overview 
= """<html><body> 
 120 <h2><center>Shaped Window</center></h2> 
 122 Top level windows now have a SetShape method that lets you set a 
 123 non-rectangular shape for the window using a wxRegion.  All pixels 
 124 outside of the region will not be drawn and the window will not be 
 125 sensitive to the mouse in those areas either. 
 132 if __name__ 
== '__main__': 
 135     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])