wasp: Move the constants into seperate container classes
This commit is contained in:
parent
9545e60f62
commit
a9413db5cf
3 changed files with 20 additions and 16 deletions
|
@ -31,7 +31,7 @@ class ClockApp():
|
||||||
|
|
||||||
def handle_event(self, event_view):
|
def handle_event(self, event_view):
|
||||||
"""Process events that the app is subscribed to."""
|
"""Process events that the app is subscribed to."""
|
||||||
if event_view[0] == wasp.EVENT_TICK:
|
if event_view[0] == wasp.Event.TICK:
|
||||||
self.update()
|
self.update()
|
||||||
else:
|
else:
|
||||||
# TODO: Raise an unexpected event exception
|
# TODO: Raise an unexpected event exception
|
||||||
|
|
|
@ -16,7 +16,7 @@ class TestApp():
|
||||||
"""Activate the application."""
|
"""Activate the application."""
|
||||||
self.on_screen = ( -1, -1, -1, -1, -1, -1 )
|
self.on_screen = ( -1, -1, -1, -1, -1, -1 )
|
||||||
self.draw(effect)
|
self.draw(effect)
|
||||||
wasp.system.request_event(wasp.EVENT_TOUCH | wasp.EVENT_SWIPE_UPDOWN)
|
wasp.system.request_event(wasp.Event.TOUCH | wasp.Event.SWIPE_UPDOWN)
|
||||||
|
|
||||||
def background(self):
|
def background(self):
|
||||||
"""De-activate the application (without losing state)."""
|
"""De-activate the application (without losing state)."""
|
||||||
|
|
32
wasp/wasp.py
32
wasp/wasp.py
|
@ -10,18 +10,22 @@ from apps.clock import ClockApp
|
||||||
from apps.flashlight import FlashlightApp
|
from apps.flashlight import FlashlightApp
|
||||||
from apps.testapp import TestApp
|
from apps.testapp import TestApp
|
||||||
|
|
||||||
DOWN = 1
|
class Direction():
|
||||||
UP = 2
|
DOWN = 1
|
||||||
LEFT = 3
|
UP = 2
|
||||||
RIGHT = 4
|
LEFT = 3
|
||||||
|
RIGHT = 4
|
||||||
|
|
||||||
EVENT_TOUCH = 0x0001
|
class Event():
|
||||||
EVENT_SWIPE_LEFTRIGHT = 0x0002
|
TOUCH = 0x0001
|
||||||
EVENT_SWIPE_UPDOWN = 0x0004
|
SWIPE_LEFTRIGHT = 0x0002
|
||||||
EVENT_BUTTON = 0x0008
|
SWIPE_UPDOWN = 0x0004
|
||||||
|
BUTTON = 0x0008
|
||||||
|
|
||||||
class Manager(object):
|
class Manager():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""System management
|
||||||
|
"""
|
||||||
self.app = None
|
self.app = None
|
||||||
|
|
||||||
self.applications = [
|
self.applications = [
|
||||||
|
@ -58,12 +62,12 @@ class Manager(object):
|
||||||
"""
|
"""
|
||||||
app_list = self.applications
|
app_list = self.applications
|
||||||
|
|
||||||
if direction == LEFT:
|
if direction == Direction.LEFT:
|
||||||
i = app_list.index(self.app) + 1
|
i = app_list.index(self.app) + 1
|
||||||
if i >= len(app_list):
|
if i >= len(app_list):
|
||||||
i = 0
|
i = 0
|
||||||
self.switch(app_list[i])
|
self.switch(app_list[i])
|
||||||
elif direction == RIGHT:
|
elif direction == Direction.RIGHT:
|
||||||
i = app_list.index(self.app) - 1
|
i = app_list.index(self.app) - 1
|
||||||
if i < 0:
|
if i < 0:
|
||||||
i = len(app_list)-1
|
i = len(app_list)-1
|
||||||
|
@ -87,13 +91,13 @@ class Manager(object):
|
||||||
event_mask = self.event_mask
|
event_mask = self.event_mask
|
||||||
if event[0] < 5:
|
if event[0] < 5:
|
||||||
updown = event[0] == 1 or event[0] == 2
|
updown = event[0] == 1 or event[0] == 2
|
||||||
if (bool(event_mask & EVENT_SWIPE_UPDOWN) and updown) or \
|
if (bool(event_mask & Event.SWIPE_UPDOWN) and updown) or \
|
||||||
(bool(event_mask & EVENT_SWIPE_LEFTRIGHT) and not updown):
|
(bool(event_mask & Event.SWIPE_LEFTRIGHT) and not updown):
|
||||||
if not self.app.swipe(event):
|
if not self.app.swipe(event):
|
||||||
self.navigate(event[0])
|
self.navigate(event[0])
|
||||||
else:
|
else:
|
||||||
self.navigate(event[0])
|
self.navigate(event[0])
|
||||||
elif event[0] == 5 and self.event_mask & EVENT_TOUCH:
|
elif event[0] == 5 and self.event_mask & Event.TOUCH:
|
||||||
self.app.touch(event)
|
self.app.touch(event)
|
||||||
|
|
||||||
def tick(self):
|
def tick(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue