ajenti.ui

class ajenti.ui.UI[source]

The root UI object, one per session

clear_updates()[source]

Marks all pending updates as processed

create(typeid, *args, **kwargs)[source]

Creates an element by its type ID.

Parameters:typeid (str) – type ID
dispatch_event(uid, event, params=None)[source]

Dispatches an event to an element with given UID

Parameters:
  • uid (int) – element UID
  • event (str) – event name
  • params (dict, None) – event arguments
find(id)[source]
Parameters:id (str) – element ID
Returns:nearest element with given ID
Return type:UIElement, None
find_uid(uid)[source]
Parameters:uid (int) – element UID
Returns:nearest element with given unique ID
Return type:UIElement, None
has_updates()[source]

Checks for pending UI updates

Return type:bool
inflate(layout)[source]
Parameters:layout (str) – layout spec: “<plugin id>:<layout file name without extension>”
Returns:an inflated element tree of the given layout XML name
Return type:UIElement
init()[source]
render()[source]

Renders the UI into JSON

Return type:dict
class ajenti.ui.UIElement(ui, typeid=None, children=[], **kwargs)[source]

Base UI element class

append(child)[source]

Appends a child

Parameters:child (UIElement) – child
bind

Bound property name

bindtransform

Value transformation function for one-direction bindings

broadcast(method, *args, **kwargs)[source]

Calls method on every member of the subtree

Parameters:method (str) – method
clear_updates()[source]

Marks all pending updates as processed

client

Whether this element’s events are only processed on client side

clone(set_ui=None, set_context=None)[source]
Returns:a deep copy of the element and its children. Property values are shallow copies.
Return type:UIElement
contains(element)[source]

Checks if the element is in the subtree of self

Parameters:element (UIElement) – element
delete()[source]

Detaches this element from its parent

dispatch_event(uid, event, params=None)[source]

Dispatches an event to an element with given UID

Parameters:
  • uid (int) – element UID
  • event (str) – event name
  • params (dict, None) – event arguments
empty()[source]

Detaches all child elements

event(event, params=None)[source]

Invokes handler for event on this element with given **params

Parameters:
  • event (str) – event name
  • params (dict, None) – event arguments
find(id)[source]
Parameters:id (str) – element ID
Returns:the nearest child with given ID or None
Return type:UIElement, None
find_type(typeid)[source]
Returns:the nearest child with given type ID or None
Return type:UIElement, None
find_uid(uid)[source]
Parameters:uid (int) – element UID
Returns:the nearest child with given UID or None
Return type:UIElement, None
has_updates()[source]

Checks for pending UI updates

id

Element ID

init()[source]
invalidate()[source]
nearest(predicate, exclude=None, descend=True)[source]

Returns the nearest child which matches an arbitrary predicate lambda

Parameters:
  • predicate (function) – lambda element: bool
  • exclude (function, None) – lambda element: bool - excludes matching branches from search
  • descend (bool) – whether to descend inside matching elements
on(event, handler, *args)[source]

Binds event with ID event to handler. *args will be passed to the handler. :param event: event :type event: str :param handler: handler :type handler: function

path_to(element)[source]
Returns:a list of elements forming a path from self to element
Return type:list
post_clone()[source]
property_definitions
remove(child)[source]

Detaches the child

Parameters:child (UIElement) – child
render()[source]

Renders this element and its subtree to JSON

Return type:dict
reverse_event(event, params=None)[source]

Raises the event on this element by feeding it to the UI root (so that @on methods in ancestors will work).

Parameters:
  • event (str) – event name
  • params (dict) – event arguments
style

Additional CSS class

typeid = None
visible

Visibility of the element

ajenti.ui.p(prop, default=None, bindtypes=[], type=<type 'unicode'>, public=True, doc=None)[source]

Creates an UI property inside an UIElement:

@p('title')
@p('category', default='Other', doc='Section category name')
@p('active', default=False)
class SectionPlugin (BasePlugin, UIElement):
    typeid = 'main:section'
Parameters:
  • default (object) – Default value
  • bindtypes (list) – List of Python types that can be bound to this property
  • type (object) – expected Python type for this value
  • public (bool) – whether this property is rendered and sent to client
  • doc (str, None) – docstring
Return type:

function

ajenti.ui.on(id, event)[source]

Sets the decorated method to handle indicated event:

@plugin
class Hosts (SectionPlugin):
    def init(self):
        self.append(self.ui.inflate('hosts:main'))
        ...

    @on('save', 'click')
    def save(self):
        self.config.save()
Parameters:
  • id (str) – element ID
  • event (str) – event name
Return type:

function

comments powered by Disqus