Created
September 15, 2016 20:45
-
-
Save Eskatrem/f86a8a0bcf6a49bb9e7b4aef2388e10c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kivy | |
from kivy.clock import Clock | |
from kivy.app import App | |
from kivy.uix.floatlayout import FloatLayout | |
from kivy.uix.label import Label | |
from kivy.uix.textinput import TextInput | |
def on_enter(instance): | |
print '============== still in "global?" on_enter() ====================' | |
print 'User pressed enter in', instance # Python 3 way: print('User pressed enter in', instance) | |
print '"value" == ', instance.text # Python 3 way: print('"value" == ', instance.text) | |
print 'resetting focus BACK to textinput!' | |
# self.focus = True # error: NameError: global name 'self' is not defined | |
class MyTextInput(TextInput): | |
def on_parent(self, widget, parent): | |
self.focus = True | |
def set_focus(self): | |
self.focus = True | |
def on_enter(self, value): | |
# import pdb; pdb.set_trace() | |
global myApp | |
myApp.label.text += ("\n"+value.text) | |
self.text = '' | |
# print 'User pressed enter in', instance # Python 3 way: print('User pressed enter in', instance) | |
# print '"value" == ', instance.text # Python 3 way: print('"value" == ', instance.text) | |
# print 'resetting focus BACK to textinput!' | |
Clock.schedule_once(lambda dt: self.set_focus()) | |
# instance.focus = True | |
class BoundedLabel(Label): | |
pass | |
class MyApp(App): | |
def build(self): | |
self.root = FloatLayout(padding=10) | |
self.label = BoundedLabel(text='Hello world', halign="left", valign="top") # text_size: self.size # halign: 'right' # valign: 'middle' | |
self.label.bind(size=self.label.setter('text_size')) | |
self.root.add_widget(self.label) | |
# textinput = TextInput(size_hint=(self.root.width, None), size=(100, 50), multiline=False) # , focus=True) locked up app! | |
textinput = MyTextInput(size_hint=(self.root.width, None), size=(100, 50), multiline=False) # , focus=True) locked up app! | |
textinput.bind(on_text_validate=textinput.on_enter) | |
self.root.add_widget(textinput) | |
return self.root | |
if __name__ == '__main__': | |
global myApp | |
myApp = MyApp() | |
myApp.run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment