- Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathBitmapFromBufferTest.py
More file actions
Latest commit
executable file
·94 lines (71 loc) · 2.71 KB
/
Copy pathBitmapFromBufferTest.py
File metadata and controls
executable file
·94 lines (71 loc) · 2.71 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
"""
A test of wx.BitmapFromBuffer
"""
importnumpyasnp
importnumpy.randomasrandom
importwx
classBitmapWindow(wx.Window):
def__init__(self, parent, bytearray, *args, **kwargs):
wx.Window.__init__(self, parent, *args, **kwargs)
self.bytearray=bytearray
self.Bind(wx.EVT_PAINT, self.OnPaint)
defOnPaint(self, evt):
dc=wx.PaintDC(self)
bmp=wx.BitmapFromBufferRGBA(200,200, self.bytearray)
dc.DrawBitmap(bmp, 50, 0 )
classDemoFrame(wx.Frame):
""" This window displays a button """
def__init__(self, title="Bitmap Demo"):
wx.Frame.__init__(self, None , -1, title)#, size = (800,600), style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
# create the array and bitmap:
self.bytearray=np.zeros((200,200,4), dtype=np.uint8)
self.bytearray[:,:,3] =255
#bmp = wx.BitmapFromBufferRGBA(200,200, self.bytearray)
#bmp = wx.Bitmap("Images/smalltest.jpg")
self.BitmapWindow=BitmapWindow(self, self.bytearray)
sizer=wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.BitmapWindow, 1, wx.GROW)
# set up the buttons
ButtonSizer=self.SetUpTheButtons()
sizer.Add(ButtonSizer, 0, wx.GROW)
self.SetSizer(sizer)
# now set up the timer:
self.Timer=wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer)
self.Counter=0
defSetUpTheButtons(self):
StartButton=wx.Button(self, wx.NewId(), "Start")
StartButton.Bind(wx.EVT_BUTTON, self.OnStart)
StopButton=wx.Button(self, wx.NewId(), "Stop")
StopButton.Bind(wx.EVT_BUTTON, self.OnStop)
QuitButton=wx.Button(self, wx.NewId(), "Quit")
QuitButton.Bind(wx.EVT_BUTTON, self.OnQuit)
self.Bind(wx.EVT_CLOSE, self.OnQuit)
sizer=wx.BoxSizer(wx.HORIZONTAL)
sizer.Add((1,1), 1)
sizer.Add(StartButton, 0, wx.ALIGN_CENTER|wx.ALL, 4 )
sizer.Add((1,1), 1)
sizer.Add(StopButton, 0, wx.ALIGN_CENTER|wx.ALL, 4 )
sizer.Add((1,1), 1)
sizer.Add(QuitButton, 0, wx.ALIGN_CENTER|wx.ALL, 4 )
sizer.Add((1,1), 1)
returnsizer
defOnTimer(self,Event):
print"The timer fired"
r, g, b, a=random.randint(255, size= (4,))
self.bytearray[:,:,0] =r
self.bytearray[:,:,1] =g
self.bytearray[:,:,2] =b
self.Refresh()
self.Update()
defOnStart(self,Event):
self.Timer.Start(500) # time between events (in milliseconds)
defOnStop(self, Event=None):
self.Timer.Stop()
defOnQuit(self,Event):
self.Destroy()
app=wx.PySimpleApp(0)
frame=DemoFrame()
frame.Show()
app.MainLoop()