Skip to content

Instantly share code, notes, and snippets.

@Bakterija
Created June 26, 2017 14:07
Show Gist options
  • Save Bakterija/81fa1b11785cfb28279c65c2660ef512 to your computer and use it in GitHub Desktop.
Save Bakterija/81fa1b11785cfb28279c65c2660ef512 to your computer and use it in GitHub Desktop.
from kivy.uix.floatlayout import FloatLayout
from kivy.app import runTouchApp
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.logger import Logger
from time import time
class RootWidget(FloatLayout):
scheduled_testing = False
def __init__(self, **kwargs):
super(RootWidget, self).__init__(**kwargs)
def schedule_testing(self,):
if not self.scheduled_testing:
Clock.schedule_interval(self.do_test, 0)
def do_test(self, *args):
next_widget = None
for i, x in enumerate(self.inp_widgets):
if x.is_focusable:
next_widget = i + 1
if next_widget == 4:
next_widget = 0
x.is_focusable = False
self.inp_widgets[next_widget].is_focusable = True
self.inp_widgets[next_widget].focus = True
break
print('NEW FOCUS', next_widget)
runTouchApp(Builder.load_string('''
<TestInput@TextInput>:
size_hint: 0.5, 0.5
# foreground_color:
background_active: ''
background_normal: ''
background_disabled_normal: ''
background_color: (0.5, 0.5, 0.5, 1) if not self.focus else (0.9, 0.9, 0.9, 1)
multiline: False
text: 'focus and focusable' if self.focus and self.is_focusable else 'focusable' if self.is_focusable else ''
canvas.after:
Color:
rgba: (1, 0, 0, 1) if self.is_focusable else (1, 0, 0, 0)
Rectangle:
pos: self.pos
size: int(self.width), int(self.height * 0.2)
RootWidget:
inp_widgets: [inp1, inp2, inp3, inp4]
Button:
size_hint: 0.5, 0.1
pos_hint: {'center_x': 0.5, 'center_y': 0.6}
text: 'Do test'
on_press: root.schedule_testing()
GridLayout:
cols: 2
rows: 2
size_hint: 0.7, 0.5
pos_hint: {'center_x': 0.5, 'center_y': 0.3}
TestInput:
id: inp1
focus: True
TestInput:
id: inp2
TestInput:
id: inp3
TestInput:
id: inp4
'''))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment