-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinputs.py
37 lines (27 loc) · 1.18 KB
/
inputs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import re
# where does validation happen? on de_focus? or on submit? I'd say on de_focus and that must somehow block _submit_
from kivy.uix.textinput import TextInput
IPSUB = re.compile(r'[^0-9.]')
PORTSUB = re.compile(r'[^0-9]')
class AndCatTextInput(TextInput):
def __init__(self, *args, **kwargs):
self.edited = False
self.font_size = '20sp'
super(AndCatTextInput, self).__init__(*args, **kwargs)
def on_focus(self, instance, value):
if value and not self.edited:
self.edited = True
self.placeholder = self.text
self.text = ''
elif value and self.text == self.placeholder:
self.text = ''
elif not value and self.text == '':
self.text = self.placeholder
class AndCatIPInput(AndCatTextInput):
def insert_text(self, substring, from_undo=False):
s = IPSUB.sub('', substring)
return super(AndCatIPInput, self).insert_text(s, from_undo=from_undo)
class AndCatPortInput(AndCatTextInput):
def insert_text(self, substring, from_undo=False):
s = PORTSUB.sub('', substring)
return super(AndCatPortInput, self).insert_text(s, from_undo=from_undo)