Add cancel button to trezor dialogs

This commit is contained in:
Neil Booth 2016-01-17 18:16:58 +09:00
parent 144f53be18
commit c160a99ebc
2 changed files with 11 additions and 13 deletions

View File

@ -23,13 +23,7 @@ class GuiMixin(object):
def callback_ButtonRequest(self, msg):
msg_code = self.msg_code_override or msg.code
message = self.messages.get(msg_code, self.messages['default'])
if msg.code in [3, 8] and hasattr(self, 'cancel'):
cancel_callback = self.cancel
else:
cancel_callback = None
self.handler.show_message(message % self.device, cancel_callback)
self.handler.show_message(message % self.device, self.cancel)
return self.proto.ButtonAck()
def callback_PinMatrixRequest(self, msg):
@ -106,6 +100,10 @@ class TrezorClientBase(GuiMixin, PrintError):
path.append(abs(int(x)) | prime)
return path
def cancel(self):
'''Provided here as in keepkeylib but not trezorlib.'''
self.transport.write(self.proto.Cancel())
def first_address(self, derivation):
return self.address_from_derivation(derivation)

View File

@ -43,8 +43,8 @@ class QtHandler(PrintError):
def watching_only_changed(self):
self.win.emit(SIGNAL('watching_only_changed'))
def show_message(self, msg, cancel_callback=None):
self.win.emit(SIGNAL('message_dialog'), msg, cancel_callback)
def show_message(self, msg, on_cancel=None):
self.win.emit(SIGNAL('message_dialog'), msg, on_cancel)
def show_error(self, msg):
self.win.emit(SIGNAL('error_dialog'), msg)
@ -106,17 +106,17 @@ class QtHandler(PrintError):
self.word = unicode(text.text())
self.done.set()
def message_dialog(self, msg, cancel_callback):
def message_dialog(self, msg, on_cancel):
# Called more than once during signing, to confirm output and fee
self.clear_dialog()
title = _('Please check your %s device') % self.device
self.dialog = dialog = WindowModalDialog(self.top_level_window(), title)
l = QLabel(msg)
vbox = QVBoxLayout(dialog)
if cancel_callback:
vbox.addLayout(Buttons(CancelButton(dialog)))
dialog.connect(dialog, SIGNAL('rejected()'), cancel_callback)
vbox.addWidget(l)
if on_cancel:
dialog.rejected.connect(on_cancel)
vbox.addLayout(Buttons(CancelButton(dialog)))
dialog.show()
def error_dialog(self, msg):