mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-09 23:11:10 +00:00
Use PinMatrixWidget if graphic mode is enabled
This commit is contained in:
parent
f7f04b0482
commit
e5d19d64a7
63
cmd.py
63
cmd.py
@ -1,11 +1,14 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
import os
|
||||||
import binascii
|
import binascii
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
|
import threading
|
||||||
|
|
||||||
from trezorlib.client import TrezorClient
|
from trezorlib.client import TrezorClient, pin_func
|
||||||
from trezorlib.debuglink import DebugLink
|
from trezorlib.debuglink import DebugLink
|
||||||
from trezorlib.protobuf_json import pb2json
|
from trezorlib.protobuf_json import pb2json
|
||||||
|
from trezorlib.pinmatrix import PinMatrixWidget
|
||||||
|
|
||||||
def parse_args(commands):
|
def parse_args(commands):
|
||||||
parser = argparse.ArgumentParser(description='Commandline tool for Trezor devices.')
|
parser = argparse.ArgumentParser(description='Commandline tool for Trezor devices.')
|
||||||
@ -152,7 +155,61 @@ def list_usb():
|
|||||||
from trezorlib.transport_hid import HidTransport
|
from trezorlib.transport_hid import HidTransport
|
||||||
devices = HidTransport.enumerate()
|
devices = HidTransport.enumerate()
|
||||||
return devices
|
return devices
|
||||||
|
|
||||||
|
class PinMatrixThread(threading.Thread):
|
||||||
|
'''
|
||||||
|
Hacked PinMatrixWidget into command line tool :-).
|
||||||
|
'''
|
||||||
|
def __init__(self, input_text, message):
|
||||||
|
super(PinMatrixThread, self).__init__()
|
||||||
|
self.input_text = input_text
|
||||||
|
self.message = message
|
||||||
|
self.pin_value = ''
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
import sys
|
||||||
|
from PyQt4.Qt import QApplication, QWidget, QVBoxLayout
|
||||||
|
from PyQt4.QtGui import QPushButton, QLabel
|
||||||
|
from PyQt4.QtCore import QObject, SIGNAL
|
||||||
|
|
||||||
|
a = QApplication(sys.argv)
|
||||||
|
matrix = PinMatrixWidget()
|
||||||
|
|
||||||
|
def clicked():
|
||||||
|
self.pin_value = str(matrix.get_value())
|
||||||
|
a.closeAllWindows()
|
||||||
|
|
||||||
|
ok = QPushButton('OK')
|
||||||
|
QObject.connect(ok, SIGNAL('clicked()'), clicked)
|
||||||
|
|
||||||
|
vbox = QVBoxLayout()
|
||||||
|
vbox.addWidget(QLabel(self.input_text + self.message))
|
||||||
|
vbox.addWidget(matrix)
|
||||||
|
vbox.addWidget(ok)
|
||||||
|
|
||||||
|
w = QWidget()
|
||||||
|
w.setLayout(vbox)
|
||||||
|
w.move(100, 100)
|
||||||
|
w.show()
|
||||||
|
|
||||||
|
a.exec_()
|
||||||
|
|
||||||
|
def qt_pin_func(input_text, message=None):
|
||||||
|
'''
|
||||||
|
This is a hack to display Qt window in non-qt application.
|
||||||
|
Qt window just asks for PIN and closes itself, which trigger join().
|
||||||
|
'''
|
||||||
|
if os.getenv('DISPLAY'):
|
||||||
|
# Let's hope that system is configured properly and this won't crash
|
||||||
|
t = PinMatrixThread(input_text, message)
|
||||||
|
t.start()
|
||||||
|
t.join()
|
||||||
|
return t.pin_value
|
||||||
|
else:
|
||||||
|
# Most likely no X is running,
|
||||||
|
# let's fallback to default pin_func implementation
|
||||||
|
return pin_func(input_text, message)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args(Commands)
|
args = parse_args(Commands)
|
||||||
|
|
||||||
@ -172,7 +229,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
debuglink = None
|
debuglink = None
|
||||||
|
|
||||||
client = TrezorClient(transport, debuglink=debuglink)
|
client = TrezorClient(transport, pin_func=qt_pin_func, debuglink=debuglink)
|
||||||
client.setup_debuglink(button=True, pin_correct=True)
|
client.setup_debuglink(button=True, pin_correct=True)
|
||||||
cmds = Commands(client)
|
cmds = Commands(client)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user