pyplanet.core.ui

class pyplanet.core.ui.template.Template(file)[source]

Template class manages the template file source and the rendering of it.

Will also take care of the loader of the Jinja2 template engine.

Some notable prefixes:

  • core.views: pyplanet.views.templates.

  • core.pyplanet: pyplanet.apps.core.pyplanet.templates.

  • core.maniaplanet: pyplanet.apps.core.pyplanet.templates.

  • core.trackmania: pyplanet.apps.core.trackmania.templates.

  • core.shootmania: pyplanet.apps.core.shootmania.templates.

  • [app_label]: [app path]/templates.

class pyplanet.core.ui.AppUIManager(instance, app)[source]

The App UI manager is here to maintain the context of the app and have it destroy all the listeners when the app is unloaded.

The UI Properties will be set and hold in the class definition bellow.

class pyplanet.core.ui.ui_properties.UIProperties(instance)[source]

Set the custom Script UI Properties.

Access this class with:

self.instance.ui_manager.properties
get_attribute(element: str, attribute: str, default=<object object>)[source]

Get an attribute value of an element.

Parameters
  • element – Element name

  • attribute – Attribute name

  • default – Default if not found.

Returns

Boolean if it’s set correctly.

get_visibility(element: str, default=<object object>)[source]

Set the visibility of the UI Property and don’t complain about failing to set. Must be set at the start of the app(s).

Parameters
Returns

The boolean if it’s visible or raise exception if not exists (or the default if default is given).

async reset()[source]

Reset the UI Properties to the default ManiaPlanet ones. :return:

set_attribute(element: str, attribute: str, value)[source]

Set an attribute of an element and silent if it’s not found. Useful to change positions but unsure if it will and still exists. Returns boolean if it’s set successfully.

Parameters
  • element – Element name

  • attribute – Attribute name

  • value – New value of the attribute.

Returns

Boolean if it’s set correctly.

set_visibility(element: str, visible: bool)[source]

Set the visibility of the UI Property and don’t complain about failing to set. Must be set at the start of the app(s).

Parameters
Returns

Boolean, true if is set, false if failed to set.

The StaticManiaLink is mostly used in PyPlanet for general views. Please use the View classes instead of this core ui component!

async destroy()

Destroy the Manialink with it’s handlers and references. Will also hide the Manialink for all users!

destroy_sync()

Destroy the Manialink with it’s handlers and references. Will also hide the Manialink for all users!

This method is sync and will call a async method (destroying of the manialink at our players) async but will not be executed at the same time. Be aware with this one!

async display(player_logins=None, **kwargs)

Display the manialink. Will also render if no body is given. Will show per player or global. depending on the data given and stored!

Parameters

player_logins – Only display to the list of player logins given.

async handle_catch_all(player, action, values, **kwargs)

Override this class to handle all other actions related to this view/manialink.

Parameters
  • player – Player instance.

  • action – Action name/string

  • values – Values provided by the user client.

  • kwargs

async hide(player_logins=None)

Hide manialink globally of only for the logins given in parameter.

Parameters

player_logins – Only hide for list of players, None for all players on the server.

async render(player_login=None, data=None, player_data=None, template=None)

Render template. Will render template and return body.

Parameters
  • player_login – Render data only for player, set to None to globally render (and ignore player_data).

  • data – Data to append.

  • player_data – Data to append.

  • template (pyplanet.core.ui.template.Template) – Template instance to use.

Returns

Body, rendered manialink + script.

subscribe(action, target)

Subscribe to a action given by the manialink.

Parameters
  • action – Action name.

  • target – Target method.

Returns

The DynamicManiaLink is a special manialink with data-bindings and automatically updates via maniascript. Please use the View classes instead!

Warning

This feature is not yet implemented.

async destroy()

Destroy the Manialink with it’s handlers and references. Will also hide the Manialink for all users!

destroy_sync()

Destroy the Manialink with it’s handlers and references. Will also hide the Manialink for all users!

This method is sync and will call a async method (destroying of the manialink at our players) async but will not be executed at the same time. Be aware with this one!

async display(player_logins=None, **kwargs)

Display the manialink. Will also render if no body is given. Will show per player or global. depending on the data given and stored!

Parameters

player_logins – Only display to the list of player logins given.

async handle_catch_all(player, action, values, **kwargs)

Override this class to handle all other actions related to this view/manialink.

Parameters
  • player – Player instance.

  • action – Action name/string

  • values – Values provided by the user client.

  • kwargs

async hide(player_logins=None)

Hide manialink globally of only for the logins given in parameter.

Parameters

player_logins – Only hide for list of players, None for all players on the server.

async render(player_login=None, data=None, player_data=None, template=None)

Render template. Will render template and return body.

Parameters
  • player_login – Render data only for player, set to None to globally render (and ignore player_data).

  • data – Data to append.

  • player_data – Data to append.

  • template (pyplanet.core.ui.template.Template) – Template instance to use.

Returns

Body, rendered manialink + script.

subscribe(action, target)

Subscribe to a action given by the manialink.

Parameters
  • action – Action name.

  • target – Target method.

Returns

exception pyplanet.core.ui.exceptions.ManialinkMemoryLeakException[source]

Is thrown when a memory leak is detected in a view. Raised when a manialink responds to a view, but the view is vanished for the specified player(s).

exception pyplanet.core.ui.exceptions.UIException[source]

Base exception for UI core component.

exception pyplanet.core.ui.exceptions.UIPropertyDoesNotExist[source]

Thrown when UI Property with element doesn’t exist.

class pyplanet.core.ui.loader.PyPlanetLoader[source]

Lazy loader for the pyplanet jinja2 loader.