Table Of Contents
Modules¶
Modules are classes that can be loaded when a Kivy application is starting. The loading of modules is managed by the config file. Currently, we include:
touchring
: Draw a circle around each touch.monitor
: Add a red topbar that indicates the FPS and a small graph indicating input activity.keybinding
: Bind some keys to actions, such as a screenshot.recorder
: Record and playback a sequence of events.screen
: Emulate the characteristics (dpi/density/ resolution) of different screens.inspector
: Examines your widget hierarchy and widget properties.webdebugger
: Realtime examination of your app internals via a web browser.joycursor
: Navigate in your app with a joystick.
Modules are automatically loaded from the Kivy path and User path:
- PATH_TO_KIVY/kivy/modules
- HOME/.kivy/mods
Activating a module¶
There are various ways in which you can activate a kivy module.
Activate a module in the config¶
To activate a module this way, you can edit your configuration file (in your HOME/.kivy/config.ini):
[modules]
# uncomment to activate
touchring =
# monitor =
# keybinding =
Only the name of the module followed by “=” is sufficient to activate the module.
Activate a module in Python¶
Before starting your application, preferably at the start of your import, you can do something like this:
import kivy
kivy.require('1.0.8')
# Activate the touchring module
from kivy.config import Config
Config.set('modules', 'touchring', '')
Activate a module via the commandline¶
When starting your application from the commandline, you can add a -m <modulename> to the arguments. For example:
python main.py -m webdebugger
Note
Some modules, such as the screen, may require additional parameters. They will, however, print these parameters to the console when launched without them.
Create your own module¶
Create a file in your HOME/.kivy/mods, and create 2 functions:
def start(win, ctx):
pass
def stop(win, ctx):
pass
Start/stop are functions that will be called for every window opened in Kivy. When you are starting a module, you can use these to store and manage the module state. Use the ctx variable as a dictionary. This context is unique for each instance/start() call of the module, and will be passed to stop() too.