mirror of https://github.com/kivy/kivy.git
Merge branch 'lang-app'
This commit is contained in:
commit
617a5a6dbd
|
@ -281,6 +281,7 @@ class App(EventDispatcher):
|
||||||
_running_app = None
|
_running_app = None
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
App._running_app = self
|
||||||
self._app_directory = None
|
self._app_directory = None
|
||||||
self._app_name = None
|
self._app_name = None
|
||||||
self._app_settings = None
|
self._app_settings = None
|
||||||
|
@ -537,7 +538,6 @@ class App(EventDispatcher):
|
||||||
window.set_icon(icon)
|
window.set_icon(icon)
|
||||||
self._install_settings_keys(window)
|
self._install_settings_keys(window)
|
||||||
|
|
||||||
App._running_app = self
|
|
||||||
self.dispatch('on_start')
|
self.dispatch('on_start')
|
||||||
runTouchApp()
|
runTouchApp()
|
||||||
self.dispatch('on_stop')
|
self.dispatch('on_stop')
|
||||||
|
|
45
kivy/lang.py
45
kivy/lang.py
|
@ -475,6 +475,51 @@ lang_key = re.compile('([a-zA-Z_]+)')
|
||||||
lang_keyvalue = re.compile('([a-zA-Z_][a-zA-Z0-9_.]*\.[a-zA-Z0-9_.]+)')
|
lang_keyvalue = re.compile('([a-zA-Z_][a-zA-Z0-9_.]*\.[a-zA-Z0-9_.]+)')
|
||||||
|
|
||||||
|
|
||||||
|
class ProxyApp(object):
|
||||||
|
# proxy app object
|
||||||
|
# taken from http://code.activestate.com/recipes/496741-object-proxying/
|
||||||
|
|
||||||
|
__slots__ = ['_obj']
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
object.__init__(self)
|
||||||
|
object.__setattr__(self, '_obj', None)
|
||||||
|
|
||||||
|
def _ensure_app(self):
|
||||||
|
app = object.__getattribute__(self, '_obj')
|
||||||
|
if app is None:
|
||||||
|
from kivy.app import App
|
||||||
|
app = App.get_running_app()
|
||||||
|
object.__setattr__(self, '_obj', app)
|
||||||
|
return app
|
||||||
|
|
||||||
|
def __getattribute__(self, name):
|
||||||
|
object.__getattribute__(self, '_ensure_app')()
|
||||||
|
return getattr(object.__getattribute__(self, '_obj'), name)
|
||||||
|
|
||||||
|
def __delattr__(self, name):
|
||||||
|
object.__getattribute__(self, '_ensure_app')()
|
||||||
|
delattr(object.__getattribute__(self, '_obj'), name)
|
||||||
|
|
||||||
|
def __setattr__(self, name, value):
|
||||||
|
object.__getattribute__(self, '_ensure_app')()
|
||||||
|
setattr(object.__getattribute__(self, '_obj'), name, value)
|
||||||
|
|
||||||
|
def __nonzero__(self):
|
||||||
|
object.__getattribute__(self, '_ensure_app')()
|
||||||
|
return bool(object.__getattribute__(self, '_obj'))
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
object.__getattribute__(self, '_ensure_app')()
|
||||||
|
return str(object.__getattribute__(self, '_obj'))
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
object.__getattribute__(self, '_ensure_app')()
|
||||||
|
return repr(object.__getattribute__(self, '_obj'))
|
||||||
|
|
||||||
|
global_idmap['app'] = ProxyApp()
|
||||||
|
|
||||||
|
|
||||||
class ParserException(Exception):
|
class ParserException(Exception):
|
||||||
'''Exception raised when something wrong happened in a kv file.
|
'''Exception raised when something wrong happened in a kv file.
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in New Issue