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>
|
2015-12-07 01:40:10 -08:00
|
|
|
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
|
2015-12-07 01:40:10 -08:00
|
|
|
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
|
2015-12-07 01:40:10 -08:00
|
|
|
GridLayout:
|
|
|
|
id: kb
|
2015-12-20 08:37:07 -08:00
|
|
|
update_amount: popup.update_password
|
2015-12-07 01:40:10 -08:00
|
|
|
password: ''
|
2015-12-20 08:37:07 -08:00
|
|
|
on_password: popup.on_password(self.password)
|
2015-12-07 01:40:10 -08:00
|
|
|
size_hint: 1, None
|
2016-02-13 01:00:20 -08:00
|
|
|
height: '200dp'
|
2015-12-07 01:40:10 -08:00
|
|
|
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')
|
2016-03-04 20:00:33 -08:00
|
|
|
on_release:
|
|
|
|
popup.dismiss()
|
2015-12-20 08:37:07 -08:00
|
|
|
''')
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordDialog(Factory.Popup):
|
|
|
|
|
2016-03-06 02:46:09 -08:00
|
|
|
#def __init__(self, message, callback):
|
|
|
|
# Factory.Popup.__init__(self)
|
|
|
|
|
|
|
|
def init(self, message, callback):
|
2016-02-13 01:00:20 -08:00
|
|
|
self.message = message
|
|
|
|
self.callback = callback
|
2016-03-06 02:46:09 -08:00
|
|
|
self.ids.kb.password = ''
|
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-10-14 05:52:24 -07:00
|
|
|
Clock.schedule_once(lambda dt: self.callback(pw), 0.1)
|