1
1
#!/usr/bin/python
2
-
3
2
"""
4
3
A small program to produce a "magnifying glass" effect over an image.
5
4
11
10
try :
12
11
import fixdc
13
12
except 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
16
15
import wx
17
16
17
+
18
18
class MyCanvas (wx .Panel ):
19
19
def __init__ (self , parent ):
20
20
wx .Panel .__init__ (self , parent , - 1 )
21
21
self .bmp = wx .Bitmap ('splash.gif' )
22
- self .mpos = (0 ,0 )
22
+ self .mpos = (0 , 0 )
23
23
self .Bind (wx .EVT_PAINT , self .OnPaint )
24
24
self .Bind (wx .EVT_MOTION , self .OnMouseMove )
25
25
#self.SetSizeHints(*self.bmp.GetSize())
26
- self .SetSizeHints ( self .bmp .GetWidth (), self .bmp .GetHeight () )
26
+ self .SetSizeHints (self .bmp .GetWidth (), self .bmp .GetHeight ())
27
27
self .lentSize = 80
28
28
self .Zoom = 2.
29
29
self .usePIL = False
@@ -35,24 +35,24 @@ def OnMouseMove(self, evt):
35
35
36
36
def SetMask (self , bmp ):
37
37
#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 )
40
40
mdc = wx .MemoryDC ()
41
41
mdc .SelectObject (mask )
42
42
mdc .SetBrush (wx .BLACK_BRUSH )
43
- mdc .DrawRectangle (0 ,0 , size [0 ], size [1 ])
43
+ mdc .DrawRectangle (0 , 0 , size [0 ], size [1 ])
44
44
mdc .SetBrush (wx .WHITE_BRUSH )
45
- mdc .DrawEllipse (0 ,0 , size [0 ], size [1 ])
45
+ mdc .DrawEllipse (0 , 0 , size [0 ], size [1 ])
46
46
mdc .SelectObject (wx .NullBitmap )
47
47
m = wx .Mask (mask )
48
48
bmp .SetMask (m )
49
49
50
50
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
54
54
from PIL import Image
55
- loupe = wx .EmptyBitmap (sample , sample )
55
+ loupe = wx .Bitmap (sample , sample )
56
56
mdc = wx .MemoryDC ()
57
57
mdc .SelectObject (loupe )
58
58
mdc .Blit (0 , 0 , sample , sample , self .offDC , x , y )
@@ -68,10 +68,10 @@ def getAALoupe(self):
68
68
return loupe
69
69
70
70
def getLoupe (self ):
71
- sample = self .lentSize / self .Zoom
71
+ sample = self .lentSize / self .Zoom
72
72
x = self .mpos [0 ] - sample / 2
73
73
y = self .mpos [1 ] - sample / 2
74
- loupe = wx .EmptyBitmap (self .lentSize , self .lentSize )
74
+ loupe = wx .Bitmap (self .lentSize , self .lentSize )
75
75
mdc = wx .MemoryDC ()
76
76
mdc .SelectObject (loupe )
77
77
mdc .SetUserScale (self .Zoom , self .Zoom )
@@ -83,11 +83,10 @@ def getLoupe(self):
83
83
def OnPaint (self , evt ):
84
84
#self.size = self.bmp.GetSize()
85
85
self .size = (self .bmp .GetWidth (), self .bmp .GetHeight ())
86
- offscreenBMP = wx .EmptyBitmap (* self .size )
86
+ offscreenBMP = wx .Bitmap (* self .size )
87
87
self .offDC = wx .MemoryDC ()
88
88
self .offDC .SelectObject (offscreenBMP )
89
89
self .offDC .Clear ()
90
- self .offDC .BeginDrawing ()
91
90
self .offDC .DrawBitmap (self .bmp , 0 , 0 , True )
92
91
93
92
if self .usePIL :
@@ -97,13 +96,12 @@ def OnPaint(self, evt):
97
96
loupe = self .getLoupe ()
98
97
else :
99
98
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
102
101
if self .mpos [0 ]> 0 and self .mpos [1 ]> 0 and \
103
102
self .mpos [0 ]< self .size [0 ]- 1 and self .mpos [1 ]< self .size [1 ]- 1 :
104
103
self .offDC .DrawBitmap (loupe , x , y , True )
105
104
106
- self .offDC .EndDrawing ()
107
105
self .dc = wx .PaintDC (self )
108
106
self .dc .Blit (0 , 0 , self .size [0 ], self .size [1 ], self .offDC , 0 , 0 )
109
107
evt .Skip ()
@@ -112,18 +110,19 @@ def OnPaint(self, evt):
112
110
class Controller (wx .Panel ):
113
111
zooms = ['x2' , 'x4' , 'x8' , 'x16' ]
114
112
lents = ['80' , '120' , '160' ]
113
+
115
114
def __init__ (self , parent ):
116
115
self .canvas = parent .canvas
117
116
wx .Panel .__init__ (self , parent , - 1 )
118
117
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 )
125
124
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 )
127
126
sizer .Add ((- 1 , - 1 ), 1 )
128
127
sizer .Add (self .loupe , 0 , wx .ALL , 5 )
129
128
sizer .Add ((- 1 , - 1 ), 1 )
@@ -148,7 +147,7 @@ def __init__(self):
148
147
wx .Frame .__init__ (self , None , - 1 , "Lupa" )
149
148
self .canvas = MyCanvas (self )
150
149
self .controller = Controller (self )
151
- sizer = wx .BoxSizer (wx .VERTICAL )
150
+ sizer = wx .BoxSizer (wx .VERTICAL )
152
151
sizer .Add (self .canvas )
153
152
sizer .Add (self .controller , 0 , wx .EXPAND )
154
153
#self.SetSizerAndFit(sizer)
0 commit comments