diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-03-26 20:42:03 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-03-26 20:42:03 (GMT) |
| commit | a9413db5cf80c8ccf46782aeba8503371655d912 (patch) | |
| tree | a481b24e8c1c932d1712d734d747fcd983c332af | |
| parent | 9545e60f6242b6dad6a82eec4bb8f7e3c02a579a (diff) | |
wasp: Move the constants into seperate container classes
| -rw-r--r-- | wasp/apps/clock.py | 2 | ||||
| -rw-r--r-- | wasp/apps/testapp.py | 2 | ||||
| -rw-r--r-- | wasp/wasp.py | 36 |
3 files changed, 22 insertions, 18 deletions
diff --git a/wasp/apps/clock.py b/wasp/apps/clock.py index bc612b2..3292120 100644 --- a/wasp/apps/clock.py +++ b/wasp/apps/clock.py @@ -31,7 +31,7 @@ class ClockApp(): def handle_event(self, event_view): """Process events that the app is subscribed to.""" - if event_view[0] == wasp.EVENT_TICK: + if event_view[0] == wasp.Event.TICK: self.update() else: # TODO: Raise an unexpected event exception diff --git a/wasp/apps/testapp.py b/wasp/apps/testapp.py index af531eb..40e8cce 100644 --- a/wasp/apps/testapp.py +++ b/wasp/apps/testapp.py @@ -16,7 +16,7 @@ class TestApp(): """Activate the application.""" self.on_screen = ( -1, -1, -1, -1, -1, -1 ) 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): """De-activate the application (without losing state).""" diff --git a/wasp/wasp.py b/wasp/wasp.py index 58607b2..d0ff7e3 100644 --- a/wasp/wasp.py +++ b/wasp/wasp.py @@ -10,18 +10,22 @@ from apps.clock import ClockApp from apps.flashlight import FlashlightApp from apps.testapp import TestApp -DOWN = 1 -UP = 2 -LEFT = 3 -RIGHT = 4 - -EVENT_TOUCH = 0x0001 -EVENT_SWIPE_LEFTRIGHT = 0x0002 -EVENT_SWIPE_UPDOWN = 0x0004 -EVENT_BUTTON = 0x0008 - -class Manager(object): +class Direction(): + DOWN = 1 + UP = 2 + LEFT = 3 + RIGHT = 4 + +class Event(): + TOUCH = 0x0001 + SWIPE_LEFTRIGHT = 0x0002 + SWIPE_UPDOWN = 0x0004 + BUTTON = 0x0008 + +class Manager(): def __init__(self): + """System management + """ self.app = None self.applications = [ @@ -58,12 +62,12 @@ class Manager(object): """ app_list = self.applications - if direction == LEFT: + if direction == Direction.LEFT: i = app_list.index(self.app) + 1 if i >= len(app_list): i = 0 self.switch(app_list[i]) - elif direction == RIGHT: + elif direction == Direction.RIGHT: i = app_list.index(self.app) - 1 if i < 0: i = len(app_list)-1 @@ -87,13 +91,13 @@ class Manager(object): event_mask = self.event_mask if event[0] < 5: updown = event[0] == 1 or event[0] == 2 - if (bool(event_mask & EVENT_SWIPE_UPDOWN) and updown) or \ - (bool(event_mask & EVENT_SWIPE_LEFTRIGHT) and not updown): + if (bool(event_mask & Event.SWIPE_UPDOWN) and updown) or \ + (bool(event_mask & Event.SWIPE_LEFTRIGHT) and not updown): if not self.app.swipe(event): self.navigate(event[0]) else: 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) def tick(self): |
