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:
parent
46f96ddb81
commit
2880be1db6
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user