trace interface

This page explains the trace function interface.

What interface is this?

The trace function interface displays any message on the browser console. This interface behaves like the JavaScript console.log function.

Also, this interface displays Python’s file name, caller information, and line number.

Note for the print alias

The ap.print function is the alias of the trace function. Therefore, It behaves the same as the trace function.

Basic usage

The trace function can accept any number of arguments and various value types.

The following example draws the rectangle. Then, the handler displays the message on the browser console when you click it(please press the F12 key).

import apysc as ap


def on_rectangle_click(e: ap.MouseEvent[ap.Rectangle], options: dict) -> None:
    """
    The handler that the rectangle calls when clicked.

    Parameters
    ----------
    e : MouseEvent
        Event instance.
    options : dict
        Optional arguments dictionary.
    """
    ap.trace("Hello apysc!", "Rectangle width:", e.this.width)


ap.Stage(
    stage_width=150,
    stage_height=150,
    background_color=ap.Color("#333"),
    stage_elem_id="stage",
)
sprite: ap.Sprite = ap.Sprite()
sprite.graphics.begin_fill(color=ap.Color("#0af"))
rectangle: ap.Rectangle = sprite.graphics.draw_rect(x=50, y=50, width=50, height=50)
rectangle.click(on_rectangle_click)

ap.save_overall_html(dest_dir_path="trace_basic_usage/")

trace API

Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.

[Interface signature] trace(*args: Any) -> None


[Interface summary]

Display arguments information to console. This function saves a JavaScript console.log expression.


[Parameters]

  • *args: list

    • Any arguments to display to console.


[Notes]

The ap.print function is the alias of the trace function.


[Examples]

>>> import apysc as ap
>>> _ = ap.Stage()
>>> int_val: ap.Int = ap.Int(10)
>>> ap.trace("Int value is:", int_val)