11#!/usr/bin/python
2-
32"""
43A small program to produce a "magnifying glass" effect over an image.
54
1110try :
1211 import fixdc
1312except ImportError :
14- pass # If you get an error like: DC_DrawBitmap() takes at most 4 arguments (5 given)
15- # you need the fixdc module, and don't have it
13+ pass # If you get an error like: DC_DrawBitmap() takes at most 4 arguments (5 given)
14+ # you need the fixdc module, and don't have it
1615import wx
1716
17+
1818class MyCanvas (wx .Panel ):
1919 def __init__ (self , parent ):
2020 wx .Panel .__init__ (self , parent , - 1 )
2121 self .bmp = wx .Bitmap ('splash.gif' )
22- self .mpos = (0 ,0 )
22+ self .mpos = (0 , 0 )
2323 self .Bind (wx .EVT_PAINT , self .OnPaint )
2424 self .Bind (wx .EVT_MOTION , self .OnMouseMove )
2525 #self.SetSizeHints(*self.bmp.GetSize())
26- self .SetSizeHints ( self .bmp .GetWidth (), self .bmp .GetHeight () )
26+ self .SetSizeHints (self .bmp .GetWidth (), self .bmp .GetHeight ())
2727 self .lentSize = 80
2828 self .Zoom = 2.
2929 self .usePIL = False
@@ -35,24 +35,24 @@ def OnMouseMove(self, evt):
3535
3636 def SetMask (self , bmp ):
3737 #size = bmp.GetSize()
38- size = ( self .bmp .GetWidth (), self .bmp .GetHeight () )
39- mask = wx .EmptyBitmap (* size )
38+ size = (self .bmp .GetWidth (), self .bmp .GetHeight ())
39+ mask = wx .Bitmap (* size )
4040 mdc = wx .MemoryDC ()
4141 mdc .SelectObject (mask )
4242 mdc .SetBrush (wx .BLACK_BRUSH )
43- mdc .DrawRectangle (0 ,0 , size [0 ], size [1 ])
43+ mdc .DrawRectangle (0 , 0 , size [0 ], size [1 ])
4444 mdc .SetBrush (wx .WHITE_BRUSH )
45- mdc .DrawEllipse (0 ,0 , size [0 ], size [1 ])
45+ mdc .DrawEllipse (0 , 0 , size [0 ], size [1 ])
4646 mdc .SelectObject (wx .NullBitmap )
4747 m = wx .Mask (mask )
4848 bmp .SetMask (m )
4949
5050 def getAALoupe (self ):
51- sample = self .lentSize / self .Zoom
52- x = self .mpos [0 ]- sample / 2
53- y = self .mpos [1 ]- sample / 2
51+ sample = self .lentSize / self .Zoom
52+ x = self .mpos [0 ] - sample / 2
53+ y = self .mpos [1 ] - sample / 2
5454 from PIL import Image
55- loupe = wx .EmptyBitmap (sample , sample )
55+ loupe = wx .Bitmap (sample , sample )
5656 mdc = wx .MemoryDC ()
5757 mdc .SelectObject (loupe )
5858 mdc .Blit (0 , 0 , sample , sample , self .offDC , x , y )
@@ -68,10 +68,10 @@ def getAALoupe(self):
6868 return loupe
6969
7070 def getLoupe (self ):
71- sample = self .lentSize / self .Zoom
71+ sample = self .lentSize / self .Zoom
7272 x = self .mpos [0 ] - sample / 2
7373 y = self .mpos [1 ] - sample / 2
74- loupe = wx .EmptyBitmap (self .lentSize , self .lentSize )
74+ loupe = wx .Bitmap (self .lentSize , self .lentSize )
7575 mdc = wx .MemoryDC ()
7676 mdc .SelectObject (loupe )
7777 mdc .SetUserScale (self .Zoom , self .Zoom )
@@ -83,11 +83,10 @@ def getLoupe(self):
8383 def OnPaint (self , evt ):
8484 #self.size = self.bmp.GetSize()
8585 self .size = (self .bmp .GetWidth (), self .bmp .GetHeight ())
86- offscreenBMP = wx .EmptyBitmap (* self .size )
86+ offscreenBMP = wx .Bitmap (* self .size )
8787 self .offDC = wx .MemoryDC ()
8888 self .offDC .SelectObject (offscreenBMP )
8989 self .offDC .Clear ()
90- self .offDC .BeginDrawing ()
9190 self .offDC .DrawBitmap (self .bmp , 0 , 0 , True )
9291
9392 if self .usePIL :
@@ -97,13 +96,12 @@ def OnPaint(self, evt):
9796 loupe = self .getLoupe ()
9897 else :
9998 loupe = self .getLoupe ()
100- x = self .mpos [0 ]- self .lentSize / 2
101- y = self .mpos [1 ]- self .lentSize / 2
99+ x = self .mpos [0 ] - self .lentSize / 2
100+ y = self .mpos [1 ] - self .lentSize / 2
102101 if self .mpos [0 ]> 0 and self .mpos [1 ]> 0 and \
103102 self .mpos [0 ]< self .size [0 ]- 1 and self .mpos [1 ]< self .size [1 ]- 1 :
104103 self .offDC .DrawBitmap (loupe , x , y , True )
105104
106- self .offDC .EndDrawing ()
107105 self .dc = wx .PaintDC (self )
108106 self .dc .Blit (0 , 0 , self .size [0 ], self .size [1 ], self .offDC , 0 , 0 )
109107 evt .Skip ()
@@ -112,18 +110,19 @@ def OnPaint(self, evt):
112110class Controller (wx .Panel ):
113111 zooms = ['x2' , 'x4' , 'x8' , 'x16' ]
114112 lents = ['80' , '120' , '160' ]
113+
115114 def __init__ (self , parent ):
116115 self .canvas = parent .canvas
117116 wx .Panel .__init__ (self , parent , - 1 )
118117 self .pil = wx .CheckBox (self , - 1 , "Use AA Resize" , style = wx .ALIGN_RIGHT )
119- self .rb = wx .RadioBox (
120- self , - 1 , "Zoom:" , wx .DefaultPosition , wx . DefaultSize ,
121- self . zooms , 1 , wx .RA_SPECIFY_ROWS )
122- self .loupe = wx .RadioBox (
123- self , - 1 , "Lent Size:" , wx .DefaultPosition , wx . DefaultSize ,
124- self . lents , 1 , wx .RA_SPECIFY_ROWS )
118+ self .rb = wx .RadioBox (self , - 1 , "Zoom:" , wx . DefaultPosition ,
119+ wx .DefaultSize , self . zooms , 1 ,
120+ wx .RA_SPECIFY_ROWS )
121+ self .loupe = wx .RadioBox (self , - 1 , "Lent Size:" , wx . DefaultPosition ,
122+ wx .DefaultSize , self . lents , 1 ,
123+ wx .RA_SPECIFY_ROWS )
125124 sizer = wx .BoxSizer (wx .HORIZONTAL )
126- sizer .Add (self .pil , 0 , wx .ALIGN_CENTER | wx .ALL , 5 )
125+ sizer .Add (self .pil , 0 , wx .ALIGN_CENTER | wx .ALL , 5 )
127126 sizer .Add ((- 1 , - 1 ), 1 )
128127 sizer .Add (self .loupe , 0 , wx .ALL , 5 )
129128 sizer .Add ((- 1 , - 1 ), 1 )
@@ -148,7 +147,7 @@ def __init__(self):
148147 wx .Frame .__init__ (self , None , - 1 , "Lupa" )
149148 self .canvas = MyCanvas (self )
150149 self .controller = Controller (self )
151- sizer = wx .BoxSizer (wx .VERTICAL )
150+ sizer = wx .BoxSizer (wx .VERTICAL )
152151 sizer .Add (self .canvas )
153152 sizer .Add (self .controller , 0 , wx .EXPAND )
154153 #self.SetSizerAndFit(sizer)
0 commit comments