Utils

kivy.utils.intersection(set1, set2)

Return intersection between 2 list

kivy.utils.difference(set1, set2)

Return difference between 2 list

kivy.utils.strtotuple(s)

Convert a tuple string into tuple, with some security check. Designed to be used with eval() function:

a = (12, 54, 68)
b = str(a)         # return '(12, 54, 68)'
c = strtotuple(b)  # return (12, 54, 68)
kivy.utils.get_color_from_hex(s)

Transform from hex string color to kivy color

kivy.utils.get_hex_from_color(color)

Transform from kivy color to hex:

>>> get_hex_from_color((0, 1, 0))
'#00ff00'
>>> get_hex_from_color((.25, .77, .90, .5))
'#3fc4e57f'

New in version 1.5.0.

kivy.utils.get_random_color(alpha=1.0)

Returns a random color (4 tuple)

Parameters :
alpha : float, default to 1.0

if alpha == ‘random’ a random alpha value is generated

kivy.utils.is_color_transparent(c)

Return true if alpha channel is 0

kivy.utils.boundary(value, minvalue, maxvalue)

Limit a value between a minvalue and maxvalue

kivy.utils.deprecated(func)

This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted the first time the function is used.

class kivy.utils.SafeList

Bases: list

List with clear() method

Warning

Usage of iterate() function will decrease your performance.

kivy.utils.interpolate(value_from, value_to, step=10)

Interpolate a value to another. Can be useful to smooth some transition. For example:

# instead of setting directly
self.pos = pos

# use interpolate, and you'll have a nice transition
self.pos = interpolate(self.pos, new_pos)

Warning

This interpolation work only on list/tuple/double with the same dimension. No test are done if the dimension is not the same.

class kivy.utils.QueryDict

Bases: dict

QueryDict is a dict() that can be queried with dot.

New in version 1.0.4.

d = QueryDict()
# create a key named toto, with the value 1
d.toto = 1
# it's the same as
d['toto'] = 1
kivy.utils.platform()

Return the version of the current platform. This will return one of: win, linux, android, macosx, ios, unknown

New in version 1.0.8.

Warning

ios is not currently reported.

kivy.utils.escape_markup(text)

Escape markup characters found in the text. Intended to be used when markup text is activated on the Label:

untrusted_text = escape_markup('Look at the example [1]')
text = '[color=ff0000]' + untrusted_text + '[/color]'
w = Label(text=text, markup=True)

New in version 1.3.0.

class kivy.utils.reify(func)

Bases: object

Put the result of a method which uses this (non-data) descriptor decorator in the instance dict after the first call, effectively replacing the decorator with an instance variable.

It acts like @property, except that the function is only ever called once; after that, the value is cached as a regular attribute. This gives you lazy attribute creation on objects that are meant to be immutable.

Taken from Pyramid project.