diff --git a/kivy/lang.py b/kivy/lang.py index 60765f672..383606716 100644 --- a/kivy/lang.py +++ b/kivy/lang.py @@ -458,6 +458,8 @@ from kivy.utils import OrderedDict, QueryDict from kivy.cache import Cache from kivy import kivy_data_dir, require from kivy.lib.debug import make_traceback +from kivy.properties import dpi2px +import kivy.metrics as metrics trace = Logger.trace @@ -517,7 +519,13 @@ class ProxyApp(object): object.__getattribute__(self, '_ensure_app')() return repr(object.__getattribute__(self, '_obj')) + global_idmap['app'] = ProxyApp() +global_idmap['pt'] = metrics.pt +global_idmap['inch'] = metrics.inch +global_idmap['cm'] = metrics.cm +global_idmap['mm'] = metrics.mm +global_idmap['dp'] = metrics.dp class ParserException(Exception): diff --git a/kivy/metrics.py b/kivy/metrics.py new file mode 100644 index 000000000..7d62a450f --- /dev/null +++ b/kivy/metrics.py @@ -0,0 +1,27 @@ +''' +Display Metrics +=============== + +This module give you access to multiple display values, and some conversion +functions. +''' + +__all__ = ('pt', 'inch', 'cm', 'mm', 'dp') + +from kivy.properties import dpi2px + +def pt(value): + return dpi2px(value, 'pt') + +def inch(value): + return dpi2px(value, 'in') + +def cm(value): + return dpi2px(value, 'cm') + +def mm(value): + return dpi2px(value, 'mm') + +def dp(value): + return dpi2px(value, 'dp') +