switch from pygame event loop to glib
This commit is contained in:
parent
562497c2df
commit
cd243353a9
47
csc.py
47
csc.py
@ -1,5 +1,6 @@
|
||||
import BLE_GATT
|
||||
from gi.repository import GLib
|
||||
|
||||
import pdb
|
||||
import struct
|
||||
|
||||
@ -121,31 +122,35 @@ csc_measurement = '00002a5b-0000-1000-8000-00805F9B34FB'
|
||||
bike.on_value_change(csc_measurement, app.listener.process)
|
||||
|
||||
running = True
|
||||
|
||||
def handle_pygame_event(event):
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
if event.type == pygame.KEYUP and event.key == pygame.K_q:
|
||||
running = False
|
||||
if event.type == pygame.KEYUP and event.key == pygame.K_SPACE:
|
||||
if app.listener.startTime == None:
|
||||
app.listener.startTime = datetime.now()
|
||||
else:
|
||||
app.listener.startTime = None
|
||||
if event.type == pygame.VIDEORESIZE:
|
||||
app.width = event.w
|
||||
app.height = event.h
|
||||
app.font = None
|
||||
|
||||
def on_timer():
|
||||
handle_pygame_event(pygame.event.poll())
|
||||
app.on_update()
|
||||
return True
|
||||
|
||||
|
||||
GLib.timeout_add(100, on_timer)
|
||||
|
||||
try:
|
||||
# Time to go live
|
||||
context = bike.mainloop.get_context()
|
||||
|
||||
print("Listening for events...")
|
||||
while running:
|
||||
time.sleep(0.1)
|
||||
context.iteration(False)
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
if event.type == pygame.KEYUP and event.key == pygame.K_q:
|
||||
running = False
|
||||
if event.type == pygame.KEYUP and event.key == pygame.K_SPACE:
|
||||
if app.listener.startTime == None:
|
||||
app.listener.startTime = datetime.now()
|
||||
else:
|
||||
app.listener.startTime = None
|
||||
if event.type == pygame.VIDEORESIZE:
|
||||
app.width = event.w
|
||||
app.height = event.h
|
||||
app.font = None
|
||||
bike.mainloop.run()
|
||||
|
||||
app.on_update()
|
||||
|
||||
finally:
|
||||
pygame.quit()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user