Quick search

Console

バージョン 1.9.1 で追加.

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

警告

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 “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
  • “Top”: select the parent widget
  • “Down”: select the first children of the current selected widget
  • “Left”: select the previous following sibling
  • “Right”: select the next following sibling

Additional informations

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

Addons

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

By default, 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 widget 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 addon that adds panels. Panel activation/deactivation are not tied to the addon activation/deactivation, but on 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)[ソース]

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)[ソース]

Stop and unload any active Inspectors for the given ctx.

class kivy.modules.console.Console(**kwargs)[ソース]

ベースクラス: 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)[ソース]

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)[ソース]

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)[ソース]

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.

pick(widget, x, y)[ソース]

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

remove_toolbar_widget(widget)[ソース]

Remove a widget from the toolbar

set_content(content)[ソース]

Replace the Console content with a new one.

widget

Current widget being selected

class kivy.modules.console.ConsoleAddon(console)[ソース]

ベースクラス: builtins.object

Base class for implementing addons

activate()[ソース]

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

console = None

Console instance

deactivate()[ソース]

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

init()[ソース]

Method called when the addon is instantiated by the Console

class kivy.modules.console.ConsoleButton(**kwargs)[ソース]

ベースクラス: kivy.uix.button.Button

Button specialized for the Console

class kivy.modules.console.ConsoleToggleButton(**kwargs)[ソース]

ベースクラス: kivy.uix.togglebutton.ToggleButton

ToggleButton specialized for the Console

class kivy.modules.console.ConsoleLabel(**kwargs)[ソース]

ベースクラス: kivy.uix.label.Label

LabelButton specialized for the Console