App Reference Guide

Note

This documentation in still in progress. Your feedback is welcome :)

The kabaret framework is a modular system that will help you create standalone or embedded applications.

When building a application, you will start by creating a kabaret.app.session.KabaretSession (or more likely, one of its subclasses).

A Session contains some Actors that each provide specific functionnalities and commands to use them.

A Session containts some Views that use the commands to display and modify the informations managed by Actors.

A Session manages the communication between other sessions on the network, deals with UI (events, layouts, …) and logging.

Frameword devellopers can extend kabaret by providing new Actors and/or Views. When a User wants to use an extension, he must subclass a Session to register the additionnal Actors / Views.

Once you session is properly configured, you can use one or more instances of it in a single python interpretor. But you can’t share sessions between threads.

You can define multiple session types: a standalone GUI for User, another for administration, a headless one acting as a worker waiting for orders, …

You can navigate to the Create My Studio tutorial to get you started.

Session

Resources

Generic file resouces repository.

This package provide a way to register some folders under a given name (add_folder()) and later retreive files by their basename and registered folder name (get()).

When registering a folder with the same name as another one, the lookup will favorize the last one and fall back to the first one.

This way you can extend and/or override the resources available under a given folder name.

You can deal with any kind of files, but in the case of images there are a couple helper functions: get_pixmap() and get_icon()

Every search result is cached so disk access is minimized. You don’t need to cache your resources next to their usage code, just can keep calling resources.get() as much as you want.

You can inspect the available resources with get_folder_names(), list_folder() and list_folder_paths()

Note

Files starting with an underscore _ are ignored.

exception kabaret.app.resources.NotFoundError[source]

Raised when the the resource was not found. Note that this is a ResourcesError too.

exception kabaret.app.resources.ResourcesError[source]

Raised when the folder_name is unknown.

kabaret.app.resources.add_folder(name, path)[source]

Register a folder to the search path.

The name will be used to access files.

You can use get_folder_names() to get a list of all declared names.

The path can be a file inside the folder to register, or the path of the folder itself.

If a folder with the same name was previously added, the files from the last one overrides the previous one but the previous files not available in the last one are still accessible.

In other words: the last call overrides and extends the previous ones.

Typical resource declaration:

my_studio/icons/emoji/__init__.py
# We're in a package folder containing some png files
# Every file will be accessible, and overrides previous
# declarations of 'icons.emoji' files
import kabaret.app.resources
kabaret.app.resources.add_folder('icons.emoji', __file__)
my_studio/gui.py
# Be sure to have the resource modules imported at least once
# This is typically done in the module defining your session
from my_studio.icons import emoji

Typical resource access:

my_studio/flows/my_dope_flow/__init__.py
# Use anywhere
from kabaret.app import resources
icon = resources.get('icons.emoji', 'sunglasses')
kabaret.app.resources.get(folder_name, file_name)[source]

Returns the file named file_name in the folder registered as folder_name.

kabaret.app.resources.get_folder_names()[source]

Returns a list of available folder names.

kabaret.app.resources.get_icon(icon_ref, for_widget=None, disabled_ref=None)[source]

Same as get_pixmap(), but returns a QIcon

If icon_ref is an int, for_widget must not be None and its current QStyle will be used to return the QIcon pointed by icon_ref.

If icon_ref is a 2D tuple, it is used to call get_pixmap(*icon_ref)()

If icon_ref is a file path, an icon is created from this file.

if disable_ref is not None, it must be a 2D tuple suitable for get_pixmap(*disabled_ref)() and will be used as the “disabled” state of the icon.

Warning: calls with different disabled_ref for the same icon_ref has undefined behavior.

kabaret.app.resources.get_pixmap(folder_name, pixmap_name)[source]

Same as get(), but returns a QPixmap

kabaret.app.resources.list_folder(folder_name)[source]

Returns a list of resource names available in folder_name.

kabaret.app.resources.list_folder_paths(folder_name)[source]

Return a list of list of file_name for folder_name. (overrides come first)