-
Notifications
You must be signed in to change notification settings - Fork 21
/
ScrolledBitmap.py
executable file
·63 lines (40 loc) · 1.46 KB
/
ScrolledBitmap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
"""
Putting an image in a Scrolled Window
And drawing something over it.
"""
import wx
# set an image file here
img_filename = 'Images/white_tank.jpg'
class MyCanvas(wx.ScrolledWindow):
def __init__(self, *args, **kwargs):
wx.ScrolledWindow.__init__(self, *args, **kwargs)
self.bmp = wx.Image(img_filename).ConvertToBitmap()
self.maxWidth, self.maxHeight = self.bmp.GetWidth(), self.bmp.GetHeight()
self.SetScrollbars(20, 20, self.maxWidth / 20, self.maxHeight / 20)
self.Bind(wx.EVT_PAINT, self.OnPaint)
# an arbitrary rect to draw -- in pixel coords of the image
self.rect = (200, 200, 300, 200) # x, y, width, height
def OnPaint(self, event):
dc = wx.PaintDC(self)
self.PrepareDC(dc)
dc.SetPen(wx.Pen(wx.RED, 2))
dc.SetBrush(wx.Brush((255, 255, 255, 85)))
dc.DrawBitmap(self.bmp, 0, 0)
dc.DrawRectangle(*self.rect)
class TestFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
self.Canvas = MyCanvas(self)
def OnCloseWindow(self, event):
self.Destroy()
class App(wx.App):
def OnInit(self):
frame = TestFrame(None, title="Scroll Test", size=(800, 700))
self.SetTopWindow(frame)
frame.Show(True)
return True
if __name__ == "__main__":
app = App(False)
app.MainLoop()