electrum-bitcoinprivate/gui/kivy/uix/dialogs/password_dialog.py

97 lines
2.4 KiB
Python
Raw Normal View History

2015-12-20 08:37:07 -08:00
from kivy.app import App
from kivy.factory import Factory
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from decimal import Decimal
2016-02-13 01:33:49 -08:00
from kivy.clock import Clock
2015-12-20 08:37:07 -08:00
Builder.load_string('''
<PasswordDialog@Popup>
id: popup
2016-02-13 01:00:20 -08:00
title: _('PIN Code')
message: ''
2015-12-07 07:43:18 -08:00
size_hint: 0.9, 0.9
2015-10-13 10:09:12 -07:00
BoxLayout:
orientation: 'vertical'
2016-02-13 01:00:20 -08:00
Widget:
size_hint: 1, 1
Label:
text: root.message
text_size: self.width, None
size: self.texture_size
Widget:
size_hint: 1, 1
Label:
id: a
2015-12-07 07:43:18 -08:00
text: ' * '*len(kb.password) + ' o '*(6-len(kb.password))
2016-02-13 01:00:20 -08:00
Widget:
size_hint: 1, 1
GridLayout:
id: kb
2015-12-20 08:37:07 -08:00
update_amount: popup.update_password
password: ''
2015-12-20 08:37:07 -08:00
on_password: popup.on_password(self.password)
size_hint: 1, None
2016-02-13 01:00:20 -08:00
height: '200dp'
cols: 3
KButton:
text: '1'
KButton:
text: '2'
KButton:
text: '3'
KButton:
text: '4'
KButton:
text: '5'
KButton:
text: '6'
KButton:
text: '7'
KButton:
text: '8'
KButton:
text: '9'
KButton:
text: 'Clear'
KButton:
text: '0'
KButton:
text: '<'
2016-02-13 01:00:20 -08:00
BoxLayout:
size_hint: 1, None
height: '48dp'
Widget:
size_hint: 0.5, None
Button:
size_hint: 0.5, None
height: '48dp'
text: _('Cancel')
on_release: popup.dismiss()
2015-12-20 08:37:07 -08:00
''')
class PasswordDialog(Factory.Popup):
2016-02-13 01:00:20 -08:00
def __init__(self, message, callback):
2015-12-20 08:37:07 -08:00
Factory.Popup.__init__(self)
2016-02-13 01:00:20 -08:00
self.message = message
self.callback = callback
2015-12-20 08:37:07 -08:00
def update_password(self, c):
kb = self.ids.kb
text = kb.password
if c == '<':
text = text[:-1]
elif c == 'Clear':
text = ''
else:
text += c
kb.password = text
def on_password(self, pw):
if len(pw) == 6:
self.dismiss()
2016-02-13 01:33:49 -08:00
Clock.schedule_once(lambda dt: self.callback(pw), 0.1)