From 2880be1db6a2cbce09c2f44075a418b2d8f4619c Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Wed, 1 Jun 2016 14:07:48 +0200 Subject: [PATCH] use == instead of 'is' for scalars, cleanup PinDialog --- src/trezor/ui/button.py | 6 +++--- src/trezor/ui/pin.py | 30 +++++++++++++++--------------- src/trezor/ui/swipe.py | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/trezor/ui/button.py b/src/trezor/ui/button.py index b7e33a131c..f91799b3f5 100644 --- a/src/trezor/ui/button.py +++ b/src/trezor/ui/button.py @@ -78,17 +78,17 @@ class Button(): def send(self, event, pos): if not self.absolute: pos = rotate_coords(pos) - if event is loop.TOUCH_START: + if event == loop.TOUCH_START: if in_area(pos, self.area): self.state = BTN_STARTED | BTN_DIRTY | BTN_ACTIVE - elif event is loop.TOUCH_MOVE and self.state & BTN_STARTED: + elif event == loop.TOUCH_MOVE and self.state & BTN_STARTED: if in_area(pos, self.area): if not self.state & BTN_ACTIVE: self.state = BTN_STARTED | BTN_DIRTY | BTN_ACTIVE else: if self.state & BTN_ACTIVE: self.state = BTN_STARTED | BTN_DIRTY - elif event is loop.TOUCH_END and self.state & BTN_STARTED: + elif event == loop.TOUCH_END and self.state & BTN_STARTED: self.state = BTN_DIRTY if in_area(pos, self.area): return BTN_CLICKED diff --git a/src/trezor/ui/pin.py b/src/trezor/ui/pin.py index 48ecb82000..acfb979ac5 100644 --- a/src/trezor/ui/pin.py +++ b/src/trezor/ui/pin.py @@ -1,4 +1,6 @@ -from . import button +from .button import Button, BTN_CLICKED +from .button import CONFIRM_BUTTON, CONFIRM_BUTTON_ACTIVE +from .button import CANCEL_BUTTON, CANCEL_BUTTON_ACTIVE from trezor import loop @@ -18,13 +20,13 @@ class PinDialog(): def __init__(self, pin=''): self.pin = pin - self.confirm_button = button.Button((0, 240 - 60, 120, 60), 'Confirm', - normal_style=button.CONFIRM_BUTTON, - active_style=button.CONFIRM_BUTTON_ACTIVE) - self.cancel_button = button.Button((120, 240 - 60, 120, 60), 'Cancel', - normal_style=button.CANCEL_BUTTON, - active_style=button.CANCEL_BUTTON_ACTIVE) - self.pin_buttons = [button.Button(digit_area(dig), str(dig)) + self.confirm_button = Button((0, 240 - 60, 120, 60), 'Confirm', + normal_style=CONFIRM_BUTTON, + active_style=CONFIRM_BUTTON_ACTIVE) + self.cancel_button = Button((120, 240 - 60, 120, 60), 'Cancel', + normal_style=CANCEL_BUTTON, + active_style=CANCEL_BUTTON_ACTIVE) + self.pin_buttons = [Button(digit_area(dig), str(dig)) for dig in range(1, 10)] def render(self): @@ -35,19 +37,17 @@ class PinDialog(): def send(self, event, pos): for btn in self.pin_buttons: - if btn.send(event, pos) is button.BTN_CLICKED: + if btn.send(event, pos) == BTN_CLICKED: self.pin += btn.text - if self.confirm_button.send(event, pos) is button.BTN_CLICKED: + if self.confirm_button.send(event, pos) == BTN_CLICKED: return PIN_CONFIRMED - if self.cancel_button.send(event, pos) is button.BTN_CLICKED: + if self.cancel_button.send(event, pos) == BTN_CLICKED: return PIN_CANCELLED - def wait_for_result(self): + def wait(self): while True: self.render() - event, *pos = yield loop.Select(loop.TOUCH_START, - loop.TOUCH_MOVE, - loop.TOUCH_END) + event, *pos = yield loop.Select(loop.TOUCH) result = self.send(event, pos) if result is not None: return result diff --git a/src/trezor/ui/swipe.py b/src/trezor/ui/swipe.py index e0ae1175a0..5e0ac4c80d 100644 --- a/src/trezor/ui/swipe.py +++ b/src/trezor/ui/swipe.py @@ -29,11 +29,11 @@ class Swipe(): if not self.absolute: pos = rotate_coords(pos) - if event is loop.TOUCH_START and in_area(pos, self.area): + if event == loop.TOUCH_START and in_area(pos, self.area): self.start_time = utime.time() self.start_pos = pos - elif event is loop.TOUCH_END and self.start_pos is not None: + elif event == loop.TOUCH_END and self.start_pos is not None: self.end_time = utime.time() self.end_pos = pos td = self.end_time - self.start_time