from kivy.app import App
from kivy.core.window import Window
from kivy.event import EventDispatcher
from kivy.logger import Logger
from kivy.metrics import Metrics
from kivy.properties import * # NumericProperty, ReferenceProperty...
from kivy.uix.screenmanager import ScreenManager, SlideTransition



''' Notes on lazy instantiation:
In Python, because function call overhead is high, singletons are more
than just annoying syntax; they cost a lot of performance.  A
module-level global is identical in function to a singleton in compiled
languages.

The difference is that with a singleton, you don't always have to keep
track of when objects have been instantiated.  Because of your API
always calling getSingleton whenever it's needed, you don't worry about
whether the name is there or not.

Avoiding this in Python leaves us with an interesting world.  Classes
want to use singletons before those singletons can truly be
instantiated.  Singletons want to use widgets in their methods.

However, global dynamic name resolution to the rescue.  The names inside
the function bodies will not be resolved until the function is called.
This means only a few functions will ever need to deal with
instantiation order even though I'm skipping singletons.

The recipe is simple:

*  Define classes that intantiate themselves lazily, without calling their
supers immeditately.
*  Instantiate them to create their names.
*  Whenever each one needs to use it's real API the first time, call
late_init.
*  Even better, since only some controllers need to init against each
other (for property binding) just call them in the correct order.
'''


class StateController(EventDispatcher):
    ''' This class's job is to take care of the State stack,