Kivy Architecture
Last Update : 14 Sep, 2022In this tutorial, You will learn how to design Kivy (Kivy Architecture) from a software engineering point of view. Then, you can understand how everything works together.
When looking at the Kivy codes, You can already get a rough idea about the Kivy structure. But, You can get a good idea about the Kivy architecture using this tutorial.
There are several building blocks consisting of the Kivy. You can get a rough idea by using the graphical summary of the Kivy architecture.
The following shows the graphical summary of the Kivy architecture.
Core Providers and Input Providers
Modularity and Abstraction are some of the main ideas used to understand Kivy’s internals.
Kivy provides an abstract of core tasks such as displaying images and text, opening a window, getting images from a camera, spelling correction, playing audio, and so on. This helps to use and extend the API.
An input provider is a piece of code that helps specific input devices like TUIO, Apple’s trackpads, a mouse emulator, etc.
To add support for a new input device, You can make a new class by reading input data from your device to transform your device into Kivy's basic events.
Graphics
Kivy uses an abstraction of OpenGL for Kivy graphics API.
Kivy issues hardware-accelerated drawing commands using OpenGL on the lowest level. These OpenGL codes can be a little bit confusing for newcomers.
Therefore, Kivy provides the graphics API in which you can draw simple metaphors that are not included in OpenGL such as Canvas, Rectangle, etc.
Kivy graphics API was developed on the C level to achieve good performance. Also, all Kivy widgets use this graphics API.
Kivy graphics API has the ability to optimize the drawing commands automatically. That is a good advantage for Kivy programmers.
Core
The following shows the commonly used features in the Kivy Core package.
Clock
The clock is used to schedule the timer events of both one-shot timers and periodic timers.
Cache
Kivy cache is used to store python objects. No need to write your own code to cache something. You can use Kivy cashe class in your programs.
There are two ways to control the cache such as Object limit and Timeout in Kivy.
Kivy Language
The Kivy language is a language that can describe user interface and interactions. Therefore, You can use it to describe user interfaces more quickly and easily.
Gesture Detection
Gesture Detection is used to detect various types of rectangles, circles, squares, or strokes in Kivy. Also, You can train Kivy to detect your own strokes.
Properties
You can link your widget code to the user interface description using properties classes in Kivy.
UIX
This UIX module includes Widgets and Layouts for creating user interfaces easily and quickly.
Widgets are the base building blocks of graphical user interface interfaces in Kivy. Also, You can add some functionality to your program using Kivy widgets.
File Browser, Buttons, Lists, and Sliders are some examples of Kivy widgets. Also, Kivy layouts are used to arrange widgets.
Modules
Modules are classes that can be loaded when starting a Kivy application. You can use the config file to manage the loading of modules. Also, You can write your own Kivy module also.
Widgets and Input Dispatching
In GUI programming, widgets are one of the most frequently used terms that help to interact with the user. Also, Kivy widgets work as an object that receives input events.
All Kivy widgets are designed in the form of a widget tree that contains the number of child widgets or none of the child widgets.
Kivy event is the first to receive a root widget of the widget tree. Also, Kivy sends one per touch when new data is available.
Input Events
Input events are an essential part of the Kivy architecture. There are different input events contained in Kivy abstract such as touches, mice, TUIO, Mouse, MTDev, and HIDInput.
You can add any individual input event with a 2D onscreen position.
The instance of the touch () class characterizes all the input types. Also, it can be one of the following three states.
- Down
- Move
- Up