ajenti.ui¶
-
class
ajenti.ui.UI[source]¶ The root UI object, one per session
-
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
-
-
class
ajenti.ui.UIElement(ui, typeid=None, children=[], **kwargs)[source]¶ Base UI element class
-
bind¶ Bound property name
-
bindtransform¶ Value transformation function for one-direction bindings
-
broadcast(method, *args, **kwargs)[source]¶ Calls
methodon every member of the subtreeParameters: method (str) – method
-
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
elementis in the subtree ofselfParameters: element ( UIElement) – element
-
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
-
event(event, params=None)[source]¶ Invokes handler for
eventon this element with given**paramsParameters: - 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 NoneReturn type: UIElement, None
-
find_type(typeid)[source]¶ Returns: the nearest child with given type ID or NoneReturn type: UIElement, None
-
find_uid(uid)[source]¶ Parameters: uid (int) – element UID Returns: the nearest child with given UID or NoneReturn type: UIElement, None
-
id¶ Element ID
-
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
- predicate (function) –
-
on(event, handler, *args)[source]¶ Binds event with ID
eventtohandler.*argswill be passed to thehandler. :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 selftoelementReturn type: list
-
property_definitions¶
-
reverse_event(event, params=None)[source]¶ Raises the event on this element by feeding it to the UI root (so that
@onmethods 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