1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-23 07:58:09 +00:00

use == instead of 'is' for scalars, cleanup PinDialog

This commit is contained in:
Jan Pochyla 2016-06-01 14:07:48 +02:00 committed by Pavol Rusnak
parent 46f96ddb81
commit 2880be1db6
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 20 additions and 20 deletions

View File

@ -78,17 +78,17 @@ class Button():
def send(self, event, pos): def send(self, event, pos):
if not self.absolute: if not self.absolute:
pos = rotate_coords(pos) pos = rotate_coords(pos)
if event is loop.TOUCH_START: if event == loop.TOUCH_START:
if in_area(pos, self.area): if in_area(pos, self.area):
self.state = BTN_STARTED | BTN_DIRTY | BTN_ACTIVE 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 in_area(pos, self.area):
if not self.state & BTN_ACTIVE: if not self.state & BTN_ACTIVE:
self.state = BTN_STARTED | BTN_DIRTY | BTN_ACTIVE self.state = BTN_STARTED | BTN_DIRTY | BTN_ACTIVE
else: else:
if self.state & BTN_ACTIVE: if self.state & BTN_ACTIVE:
self.state = BTN_STARTED | BTN_DIRTY 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 self.state = BTN_DIRTY
if in_area(pos, self.area): if in_area(pos, self.area):
return BTN_CLICKED return BTN_CLICKED

View File

@ -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 from trezor import loop
@ -18,13 +20,13 @@ class PinDialog():
def __init__(self, pin=''): def __init__(self, pin=''):
self.pin = pin self.pin = pin
self.confirm_button = button.Button((0, 240 - 60, 120, 60), 'Confirm', self.confirm_button = Button((0, 240 - 60, 120, 60), 'Confirm',
normal_style=button.CONFIRM_BUTTON, normal_style=CONFIRM_BUTTON,
active_style=button.CONFIRM_BUTTON_ACTIVE) active_style=CONFIRM_BUTTON_ACTIVE)
self.cancel_button = button.Button((120, 240 - 60, 120, 60), 'Cancel', self.cancel_button = Button((120, 240 - 60, 120, 60), 'Cancel',
normal_style=button.CANCEL_BUTTON, normal_style=CANCEL_BUTTON,
active_style=button.CANCEL_BUTTON_ACTIVE) active_style=CANCEL_BUTTON_ACTIVE)
self.pin_buttons = [button.Button(digit_area(dig), str(dig)) self.pin_buttons = [Button(digit_area(dig), str(dig))
for dig in range(1, 10)] for dig in range(1, 10)]
def render(self): def render(self):
@ -35,19 +37,17 @@ class PinDialog():
def send(self, event, pos): def send(self, event, pos):
for btn in self.pin_buttons: 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 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 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 return PIN_CANCELLED
def wait_for_result(self): def wait(self):
while True: while True:
self.render() self.render()
event, *pos = yield loop.Select(loop.TOUCH_START, event, *pos = yield loop.Select(loop.TOUCH)
loop.TOUCH_MOVE,
loop.TOUCH_END)
result = self.send(event, pos) result = self.send(event, pos)
if result is not None: if result is not None:
return result return result

View File

@ -29,11 +29,11 @@ class Swipe():
if not self.absolute: if not self.absolute:
pos = rotate_coords(pos) 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_time = utime.time()
self.start_pos = pos 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_time = utime.time()
self.end_pos = pos self.end_pos = pos
td = self.end_time - self.start_time td = self.end_time - self.start_time