Created
September 26, 2016 16:09
-
-
Save ilovetogetspamed/f4ee4e918346e9d2c54d517a171b5df8 to your computer and use it in GitHub Desktop.
Can't get on_current_user to fire. Trying to figure out how to use EventDispatcher class.
This file contains 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
from kivy.uix.boxlayout import BoxLayout | |
from kivy.app import App | |
from kivy.uix.button import Button | |
from kivy.event import EventDispatcher | |
from kivy.properties import DictProperty | |
class UserManger(EventDispatcher): | |
current_user = DictProperty({'rfid_tag': '', 'nickname': '', 'logged_in': False}) | |
# This never fires! | |
def on_current_user(self, instance, value): | |
print("Typical property change from", obj, "to", value) | |
class DemoBox(BoxLayout): | |
# add a current user for the app | |
current_user = UserManger() | |
def __init__(self,**kw): | |
"""Constructor: make a new panel with a button""" | |
super(DemoBox,self).__init__(**kw) | |
button = Button(text='Click Me!',size_hint=(1,1)) | |
self.add_widget(button) | |
# Set the callback function | |
button.on_press = self.my_callback | |
def my_callback(self): | |
"""Function to call when button is pressed.""" | |
print 'Hello World!' | |
self.current_user.rfid_tag = 'ABCDEFG' | |
self.current_user.nick_name = 'Santa Claus' | |
self.current_user.logged_in = True | |
print self.current_user.rfid_tag | |
self.current_user.rfid_tag = 'QWERTY1' | |
print self.current_user.rfid_tag | |
class DemoApp(App): | |
def build(self): | |
return DemoBox() | |
if __name__ == "__main__": | |
DemoApp().run() |
Author
ilovetogetspamed
commented
Sep 26, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment