-
Notifications
You must be signed in to change notification settings - Fork 0
/
pygame_code.py
287 lines (211 loc) · 9.32 KB
/
pygame_code.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
###########################################################################
import numpy as np
from PIL import Image, ImageDraw
#from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar
import wx
import time
import pygame
global xdata1
fps = 0.
drawing = False
start_time = time.time()
"""
ht(); speed(0)
color('green'); width(1)
for i in range(4): # axes
fd(80); bk(80); rt(90)
color('red'); width(2)
pu(); goto(-50, -70); pd()
for x in range(-50, 30):
y = 2*x + 30
goto(x, y)
"""
class Testu_logs ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Testu logs", pos = wx.DefaultPosition, size = wx.Size( 700,450 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
bSizer1 = wx.BoxSizer( wx.HORIZONTAL )
####Izveidoti jauni atteli ar RGBA kanaliem
self.imgG = Image.new('RGBA', (600,600), color=(255,255,255,80))
self.imgB = Image.new('RGBA', (600,600), color=(255,255,255,80))
self.imgR = Image.new('RGBA', (600,600), color=(255,255,255,80))
self.imgR.save("imgR.png")
self.imgG.save("imgG.png")
self.imgB.save("imgB.png")
pygame.init()
#uzzime virsu viniem
draw = ImageDraw.Draw(self.imgG)
draw.line((100,200, 150,300), fill='green',width=10)
draw2 = ImageDraw.Draw(self.imgB)
draw2.line((200,200, 150,400), fill='blue',width=20)
draw3 = ImageDraw.Draw(self.imgR)
draw3.line((200,200, 50,500), fill='red',width=20)
image1 = pygame.image.load("imgR.png").convert()
image2 = pygame.image.load("imgG.png").convert()
image3 = pygame.image.load("imgB.png").convert()
self.m_panel2 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.BORDER_SUNKEN|wx.TAB_TRAVERSAL )
self.m_panel2.SetMinSize( wx.Size( 150,-1 ) )
self.m_panel1 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
self.m_panel1.SetDoubleBuffered(True)
bSizer1.Add( self.m_panel1, 1, wx.EXPAND, 5 )
#izveido jaunus wx attelus ko var parveidot uz bitmap ar tadu pasu izmeru ka pil atteli
self.wx_image1 = wx.Image(600, 600)
self.wx_image2 = wx.Image(600, 600)
self.wx_image3 = wx.Image(600, 600)
#print('here')
#### seit pil attela datus iedod wx attelam gan rga vertibas gan alpha vertibas
self.wx_image1.SetData(image1.convert("RGB").tobytes())
self.wx_image1.SetAlpha(image1.convert("RGBA").tobytes()[3::4])
self.wx_image2.SetData(image2.convert("RGB").tobytes())
self.wx_image2.SetAlpha(image2.convert("RGBA").tobytes()[3::4])
self.wx_image3.SetData(image3.convert("RGB").tobytes())
self.wx_image3.SetAlpha(image3.convert("RGBA").tobytes()[3::4])
#self.wx_image1.SetAlpha(150)
#no atteliem parveido uz bitmap
self.bmp = wx.Bitmap(self.wx_image1)
self.bmp2 = wx.Bitmap(self.wx_image2)
self.bmp3 = wx.Bitmap(self.wx_image3)
#self.bmp=wx.Bitmap.FromBuffer(600,600,self.imgR.tobytes())
#self.bmp2=wx.Bitmap.FromBuffer(600,600,self.imgG.tobytes())
#self.bmp3=wx.Bitmap.FromBuffer(600,600,self.imgB.tobytes())
#self.bmp = wx.Bitmap.FromRGBA()
#self.bmp2 = wx.Bitmap.FromRGBA(600, 600, red=0, green=0, blue=255, alpha=80)
#self.bmp3 = wx.Bitmap.FromRGBA(600, 600, red=255, green=0, blue=0, alpha=80)
global k
k=0.
global Blit
Blit = True
##########TIMER
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.draw, self.timer)
################
bSizer2 = wx.BoxSizer( wx.VERTICAL )
bSizer2.Add( ( 0, 0), 1, wx.EXPAND, 5 )
self.m_button1 = wx.Button( self.m_panel2, wx.ID_ANY, u"Variants A", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer2.Add( self.m_button1, 0, wx.ALL, 5 )
self.m_button2 = wx.Button( self.m_panel2, wx.ID_ANY, u"Variants B", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer2.Add( self.m_button2, 0, wx.ALL, 5 )
self.toggleBtn = wx.Button(self.m_panel2, wx.ID_ANY, "Start")
bSizer2.Add( self.toggleBtn, 0, wx.ALL, 5 )
bSizer2.Add( ( 0, 0), 1, wx.EXPAND, 5 )
self.m_panel2.SetSizer( bSizer2 )
self.m_panel2.Layout()
bSizer2.Fit( self.m_panel2 )
bSizer1.Add( self.m_panel2, 0, wx.EXPAND, 5 )
self.SetSizer( bSizer1 )
self.Layout()
self.Centre( wx.BOTH )
self.m_statusBar1 = self.CreateStatusBar( 1, wx.STB_SIZEGRIP|wx.BORDER_RAISED, wx.ID_ANY )
# Connect Events
self.Bind( wx.EVT_CLOSE, self.OnClose )
self.Bind( wx.EVT_IDLE, self.OnIdle )
self.m_button1.Bind( wx.EVT_BUTTON, self.OnVariantsA )
self.m_button2.Bind( wx.EVT_BUTTON, self.OnVariantsB )
self.toggleBtn.Bind(wx.EVT_BUTTON, self.onToggle)
#lai zimetu vislaik uz panela 1
self.m_panel1.Bind(wx.EVT_PAINT, self.OnPaint)
########################
def __del__( self ):
pass
# Virtual event handlers, overide them in your derived class
def OnClose( self, event ):
#self.Close()
#pass
event.Skip()
def OnIdle( self, event ):
event.Skip()
def onToggle(self, event):
btnLabel = self.toggleBtn.GetLabel()
if btnLabel == "Start":
print ("starting timer...")
self.timer.Start(0)
self.toggleBtn.SetLabel("Stop")
else:
print ("timer stopped!")
self.timer.Stop()
self.toggleBtn.SetLabel("Start")
def OnVariantsA( self, event ):
global Blit
Blit = True
self.imgG.putdata((0,0,0,0))
#self.Combine()
print ("With Blit")
#self.timer.Start(10)
def OnVariantsB( self, event ):
global Blit
for i in range(1,85):
image.set_alpha(i)
#self.imgR.putdata((255,255,255,150))
#self.imgB.putdata((255,255,255,150))
Blit = False
#####paint funkcija kur atkariba no vertiba bitmapi tiek zimeti viens uz otra
def OnPaint(self,event):
dc = wx.PaintDC(self.m_panel1)
dc.SetBackground(wx.Brush("WHITE"))
# ... drawing here all other images in order of overlapping
if Blit == True:
dc.DrawBitmap(self.bmp , 0, 0, True)
dc.DrawBitmap(self.bmp2, 0, 0, True)
elif Blit == False:
dc.DrawBitmap(self.bmp3, 0, 0, True)
def draw(self, event):
global start_time
global k, fps
global Blit
global drawing
if drawing:
return
drawing = True
self.m_panel1.Refresh()#komanda lai parzimetu attēlu
#self.img.show()
#####
current_time = time.time()
try:
fps = int( ( 9 * fps + 1.0 / ( current_time - start_time ) ) / 10 )
except ZeroDivisionError:
pass
#fps = str( int( fps ) )
self.m_statusBar1.SetStatusText( 'FPS:{0:3d}'.format( fps ) )
start_time = current_time
drawing = False
def OnClick(self, event):
if event.dblclick:
pass
else:
if event.button == 3:
try:#wx.MessageBox("This is a Message Box", "Message" ,wx.OK | wx.ICON_INFORMATION)
if wx.TheClipboard.Open():#pievieno y data clipboardam
wx.TheClipboard.SetData(wx.TextDataObject(str("%.2f" %event.ydata)))
print("Sucess")
wx.TheClipboard.Close()
self.xdata1=str("X Dati: %.2f" %event.artist.get_xdata())
self.ydata1=str("Y Dati: %.2f" %event.artist.get_ydata())
print(self.xdata1,self.ydata1)
MyDialog(self, "Dialog",self.xdata1,self.ydata1).ShowModal()
except TypeError:
pass
#### event.xdata,event.ydata # here you click on the plot
class MyDialog(wx.Dialog):
def __init__(self, parent, title, xtext,ytext):
super(MyDialog, self).__init__(parent, title = "Izvēlētie Dati", size = (150,150))
panel = wx.Panel(self)
self.textboxSampleTime = wx.StaticText(panel, -1,label=xtext, pos = (0,0))
self.textboxSampleTime = wx.StaticText(panel, -1,label=ytext, pos = (0,15))
#####Button
self.btn = wx.Button(panel, wx.ID_OK, label = "EXIT", size = (50,20), pos = (50,50))
class MainApp(wx.App):
def OnInit(self):
mainFrame = Testu_logs(None)
#mainFrame.draw()
#mainFrame.status()
mainFrame.Show(True)
return True
if __name__ =='__main__':
# start time of the loop
app = MainApp()
app.MainLoop()
#app = wx.App( False )
#frame = Testu_logs( None )
#frame.Show( True )
#start the applications
#app.MainLoop()