From 0059e9c2b3f062f4b4a961228dc644dd0c01baf2 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Thu, 1 Nov 2012 04:04:28 +0100 Subject: [PATCH] lang: introduce dp/inches/mm/cm/pt functions into kivy.metrics + add access from the lang global map --- kivy/lang.py | 8 ++++++++ kivy/metrics.py | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 kivy/metrics.py 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') +