lang: introduce dp/inches/mm/cm/pt functions into kivy.metrics + add access from the lang global map

This commit is contained in:
Mathieu Virbel 2012-11-01 04:04:28 +01:00
parent 132468acfd
commit 0059e9c2b3
2 changed files with 35 additions and 0 deletions

View File

@ -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):

27
kivy/metrics.py Normal file
View File

@ -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')