Version

Quick search

Console

New in version 1.9.1.

Reboot of the old inspector, designed to be modular and keep concerns separated. It also has an addons architecture that allow you to add a button, panel, or more in the Console itself.

Warning

This module works, but might fail in some cases. Please contribute!

Usage

For normal module usage, please see the modules documentation:

python main.py -m console

Mouse navigation

When the “Select” button is activated, you can:

  • tap once on a widget to select it without leaving inspect mode

  • double tap on a widget to select and leave inspect mode (then you can manipulate the widget again)

Keyboard navigation

  • “Ctrl + e”: toggle console

  • “Escape”: cancel widget lookup, then hide inspector view

  • “Up”: select the parent widget

  • “Down”: select the first child of the currently selected widget

  • “Left”: select the previous sibling

  • “Right”: select the next sibling

Additional information

Some properties can be edited live. However, due to the delayed usage of some properties, it might crash if you don’t handle the required cases.

Addons

Addons must be added to Console.addons before the first Clock tick of the application, or before create_console is called. You currently cannot add addons on the fly. Addons are quite cheap until the Console is activated. Panels are even cheaper as nothing is done until the user selects them.

We provide multiple addons activated by default:

  • ConsoleAddonFps: display the FPS at the top-right

  • ConsoleAddonSelect: activate the selection mode

  • ConsoleAddonBreadcrumb: display the hierarchy of the current widget at the bottom

  • ConsoleAddonWidgetTree: panel to display the widget tree of the application

  • ConsoleAddonWidgetPanel: panel to display the properties of the selected widget

If you need to add custom widgets in the Console, please use either ConsoleButton, ConsoleToggleButton or ConsoleLabel.

An addon must inherit from the ConsoleAddon class.

For example, here is a simple addon for displaying the FPS at the top/right of the Console:

from kivy.modules.console import Console, ConsoleAddon

class ConsoleAddonFps(ConsoleAddon):
    def init(self):
        self.lbl = ConsoleLabel(text="0 Fps")
        self.console.add_toolbar_widget(self.lbl, right=True)

    def activate(self):
        self.event = Clock.schedule_interval(self.update_fps, 1 / 2.)

    def deactivated(self):
        self.event.cancel()

    def update_fps(self, *args):
        fps = Clock.get_fps()
        self.lbl.text = "{} Fps".format(int(fps))

Console.register_addon(ConsoleAddonFps)

You can create addons that add panels. Panel activation/deactivation is not tied to the addon activation/deactivation, but in some cases, you can use the same callback for deactivating the addon and the panel. Here is a simple “About” panel addon:

from kivy.modules.console import Console, ConsoleAddon, ConsoleLabel

class ConsoleAddonAbout(ConsoleAddon):
    def init(self):
        self.console.add_panel("About", self.panel_activate,
                               self.panel_deactivate)

    def panel_activate(self):
        self.console.bind(widget=self.update_content)
        self.update_content()

    def panel_deactivate(self):
        self.console.unbind(widget=self.update_content)

    def deactivate(self):
        self.panel_deactivate()

    def update_content(self, *args):
        widget = self.console.widget
        if not widget:
            return
        text = "Selected widget is: {!r}".format(widget)
        lbl = ConsoleLabel(text=text)
        self.console.set_content(lbl)

Console.register_addon(ConsoleAddonAbout)
kivy.modules.console.start(win, ctx)[source]

Create an Console instance attached to the ctx and bound to the Window’s on_keyboard() event for capturing the keyboard shortcut.

Parameters
win: A Window

The application Window to bind to.

ctx: A Widget or subclass

The Widget to be inspected.

kivy.modules.console.stop(win, ctx)[source]

Stop and unload any active Inspectors for the given ctx.

class kivy.modules.console.Console(**kwargs)[source]

Bases: kivy.uix.relativelayout.RelativeLayout

Console interface

This widget is created by create_console(), when the module is loaded. During that time, you can add addons on the console to extend the functionalities, or add your own application stats / debugging module.

activated

True if the Console is activated (showed)

add_panel(name, cb_activate, cb_deactivate, cb_refresh=None)[source]

Add a new panel in the Console.

  • cb_activate is a callable that will be called when the panel is activated by the user.

  • cb_deactivate is a callable that will be called when the panel is deactivated or when the console will hide.

  • cb_refresh is an optional callable that is called if the user click again on the button for display the panel

When activated, it’s up to the panel to display a content in the Console by using set_content().

add_toolbar_widget(widget, right=False)[source]

Add a widget in the top left toolbar of the Console. Use right=True if you wanna add the widget at the right instead.

addons = [<class 'kivy.modules.console.ConsoleAddonSelect'>, <class 'kivy.modules.console.ConsoleAddonFps'>, <class 'kivy.modules.console.ConsoleAddonWidgetPanel'>, <class 'kivy.modules.console.ConsoleAddonWidgetTree'>, <class 'kivy.modules.console.ConsoleAddonBreadcrumb'>]

Array of addons that will be created at Console creation

highlight_at(x, y)[source]

Select a widget from a x/y window coordinate. This is mostly used internally when Select mode is activated

inspect_enabled

Indicate if the inspector inspection is enabled. If yes, the next touch down will select a the widget under the touch

mode

Display mode of the Console, either docked at the bottom, or as a floating window.

on_touch_down(touch)[source]

Receive a touch down event.

Parameters
touch: MotionEvent class

Touch received. The touch is in parent coordinates. See relativelayout for a discussion on coordinate systems.

Returns

bool If True, the dispatching of the touch event will stop. If False, the event will continue to be dispatched to the rest of the widget tree.

on_touch_move(touch)[source]

Receive a touch move event. The touch is in parent coordinates.

See on_touch_down() for more information.

on_touch_up(touch)[source]

Receive a touch up event. The touch is in parent coordinates.

See on_touch_down() for more information.

pick(widget, x, y)[source]

Pick a widget at x/y, given a root widget

remove_toolbar_widget(widget)[source]

Remove a widget from the toolbar

set_content(content)[source]

Replace the Console content with a new one.

widget

Current widget being selected

class kivy.modules.console.ConsoleAddon(console)[source]

Bases: builtins.object

Base class for implementing addons

activate()[source]

Method called when the addon is activated by the console (when the console is displayed)

console = None

Console instance

deactivate()[source]

Method called when the addon is deactivated by the console (when the console is hidden)

init()[source]

Method called when the addon is instantiated by the Console

class kivy.modules.console.ConsoleButton(**kwargs)[source]

Bases: kivy.uix.button.Button

Button specialized for the Console

class kivy.modules.console.ConsoleToggleButton(**kwargs)[source]

Bases: kivy.uix.togglebutton.ToggleButton

ToggleButton specialized for the Console

class kivy.modules.console.ConsoleLabel(**kwargs)[source]

Bases: kivy.uix.label.Label

LabelButton specialized for the Console