import kivy
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.switch import Switch
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
Builder.load_string('''
<sanTool>:
orientation: 'vertical'
s_text: s_text
e_text: e_text
Switch:
id: switch
Button:
id: btn
text: 'btn'
on_release: root.scan()
TextInput:
id: s_text
bind: self.on_text_validate == root.validate(self,self.text)
multiline: False
TextInput:
id: e_text
bind: self.on_text_validate == root.validate(self,self.text)
multiline: False
''')
class sanTool(BoxLayout):
def __init__(self, **kwargs):
super(sanTool, self).__init__(**kwargs)
def validate(self,instance,value):
print value
def scan(self):
for i in range(int(self.s_text.text),int(self.e_text.text)):
print i
class sanApp(App):
def build(self):
return sanTool()
if __name__ == '__main__':
sanApp().run()
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
Builder.load_string('''
<sanTool>:
orientation: 'vertical'
s_text: s_text
e_text: e_text
Switch:
id: switch
Button:
id: btn
text: 'btn'
on_release: root.scan()
TextInput:
id: s_text
#See http://kivy.org/docs/api-kivy.uix.textinput.html
# on_text_validate is only fired when enter is pressed (if multiline)
# or if it losses focus (in single-line)
#on_text_validate: root.validate(self)
# It might be better to use on_text, so it's immediate
on_text: root.enforce_numeric(self)
multiline: False
TextInput:
id: e_text
text: "0"
on_text_validate: root.validate(self)
multiline: False
''')
class sanTool(BoxLayout):
def __init__(self, **kwargs):
super(sanTool, self).__init__(**kwargs)
def validate(self, text_input):
print "validate got ", str(text_input)
def enforce_numeric(self, text_input):
""" Ensure the text input contains only numeric characters or nothing"""
if not text_input.text.isdigit():
digit_list = [num for num in text_input.text if num.isdigit()]
text_input.text = "".join(digit_list)
def scan(self):
print "Scan called."
class sanApp(App):
def build(self):
return sanTool()
if __name__ == '__main__':
sanApp().run()