5
This module defines the abstraction layers for our core providers and their
6
implementations. For further information, please refer to
7
:ref:`architecture` and the :ref:`providers` section of the documentation.
9
In most cases, you shouldn't directly use a library that's already covered
10
by the core abstraction. Always try to use our providers first.
11
In case we are missing a feature or method, please let us know by
12
opening a new Bug report instead of relying on your library.
15
These are **not** widgets! These are just abstractions of the respective
16
functionality. For example, you cannot add a core image to your window.
17
You have to use the image **widget** class instead. If you're really
18
looking for widgets, please refer to :mod:`kivy.uix` instead.
26
from kivy.logger import Logger
29
class CoreCriticalException(Exception):
33
def core_select_lib(category, llist, create_instance=False,
34
base='kivy.core', basemodule=None):
35
if 'KIVY_DOC' in os.environ:
37
category = category.lower()
38
basemodule = basemodule or category
41
for option, modulename, classname in llist:
43
# module activated in config ?
45
if option not in kivy.kivy_options[category]:
46
libs_ignored.append(modulename)
48
'{0}: Provider <{1}> ignored by config'.format(
49
category.capitalize(), option))
55
mod = __import__(name='{2}.{0}.{1}'.format(
56
basemodule, modulename, base),
59
fromlist=[modulename], level=0)
60
cls = mod.__getattribute__(classname)
63
Logger.info('{0}: Provider: {1}{2}'.format(
64
category.capitalize(), option,
65
'({0} ignored)'.format(libs_ignored) if libs_ignored else ''))
70
except ImportError as e:
71
errs.append((option, e, sys.exc_info()[2]))
72
libs_ignored.append(modulename)
73
Logger.debug('{0}: Ignored <{1}> (import error)'.format(
74
category.capitalize(), option))
75
Logger.trace('', exc_info=e)
77
except CoreCriticalException as e:
78
errs.append((option, e, sys.exc_info()[2]))
79
Logger.error('{0}: Unable to use {1}'.format(
80
category.capitalize(), option))
82
'{0}: The module raised an important error: {1!r}'.format(
83
category.capitalize(), e.message))
86
except Exception as e:
87
errs.append((option, e, sys.exc_info()[2]))
88
libs_ignored.append(modulename)
89
Logger.trace('{0}: Unable to use {1}'.format(
90
category.capitalize(), option, category))
91
Logger.trace('', exc_info=e)
93
err = '\n'.join(['{} - {}: {}\n{}'.format(opt, e.__class__.__name__, e,
94
''.join(traceback.format_tb(tb))) for opt, e, tb in errs])
96
'{0}: Unable to find any valuable {0} provider at all!\n{1}'.format(
97
category.capitalize(), err))
100
def core_register_libs(category, libs, base='kivy.core'):
101
if 'KIVY_DOC' in os.environ:
103
category = category.lower()
104
kivy_options = kivy.kivy_options[category]
108
for option, lib in libs:
109
# module activated in config ?
110
if option not in kivy_options:
111
Logger.debug('{0}: option <{1}> ignored by config'.format(
112
category.capitalize(), option))
113
libs_ignored.append(lib)
115
libs_loadable[option] = lib
118
for item in kivy_options:
122
lib = libs_loadable[item]
125
__import__(name='{2}.{0}.{1}'.format(category, lib, base),
131
libs_loaded.append(lib)
133
except Exception as e:
134
Logger.trace('{0}: Unable to use <{1}> as loader!'.format(
135
category.capitalize(), option))
136
Logger.trace('', exc_info=e)
137
libs_ignored.append(lib)
139
Logger.info('{0}: Providers: {1} {2}'.format(
140
category.capitalize(),
141
', '.join(libs_loaded),
142
'({0} ignored)'.format(
143
', '.join(libs_ignored)) if libs_ignored else ''))