Widget API¶
-
class
jibe.Widget(*args, style=None, identifier=None, render_on_change=True, notify_server_on_change=True)¶ Jibe widget.
-
attributes= None¶ DOM element attributes.
-
deliver(message)¶ Passes a message to the parent to be delivered to the Browser.
- Parameters
message –
- Returns
-
descendent_index= None¶ Index for fast lookup of children. TODO: Check if this contains only children or all descendents.
-
identifier= None¶ Unique identifier to find the browser counterpart.
-
message(message)¶ Send a message to this widget’s browser side.
- Parameters
message –
- Returns
-
notifyServerOnChange= None¶ Whether the JS widget should send the server a message to notify the change in its model (properties).
-
on_browser_side_ready(source, message)¶ Javascript counterpart is ready in the browser and can receive messages. Delivers all queued messages.
- Parameters
source – Widget where the event originated (should be self).
message – Message from the browser.
- Returns
None
-
on_change(propname, newval, oldval)¶ Callback for change in self.properties. Sends a message to the browser notifying of the change.
- Parameters
propname – Name of the property that has changed.
newval – New value of the property.
oldval – Previous value of the property.
- Returns
None
-
on_children(source, message)¶ Javascript counterpart request for children. Widgets that have children will request for their children once they are instantiated in the browser.
TODO: Check if this is still being used.
- Parameters
source – Widget that triggered the event. Should be self.
message – Message from the browser.
- Returns
None
-
on_children_append(*args, **kwargs)¶ Called when this.children.append() is called. Sends the appended child to the browser.
- Parameters
args –
kwargs –
- Returns
-
on_children_change()¶ Called when the children attribute is assigned.
Children are “adopted”, i.e. their parent property is set to this widget.
Triggers a call to self.update_descendents(). Actually, each child calls it when it detects that its ‘parent’ member is being set.
Sends the children to the browser.
- Returns
None
-
on_children_remove(*args, **kwargs)¶ Called when this.children.remove() is called. Notifies the browser of the removal.
TODO: Not yet implemented.
- Parameters
args –
kwargs –
- Returns
-
on_message(message)¶ Invoked when a message for this Widget is received from the browser.
- Parameters
message –
- Returns
-
outbox= None¶ Message queue waiting for browser side to be ready.
-
register(event: str, handler: Callable)¶ Register the event handler for the specified event (message). The handler receives two parameters, the widget generating the event and the message from the server.
- Parameters
event – Name of the event
handler – Callable.
- Returns
None
-
renderOnChange= None¶ Whether the JS widget should render when there is a change in its model (properties).
-
send_children()¶ Serialize and send children to the browser.
- Returns
None
-
serialize()¶ Returns a string with a JSON representation of this widget.
-
style= None¶ Style attribute
-
style_string()¶ Serialize this widget’s style member into a CSS compatible string.
- Returns
CSS string for this widget.
-
subscribers= None¶ For others to be notified of events. So far, these only get called by the methods in self.local_event_handlers. This is populated with self.register(callback).
-
tagname= None¶ DOM element tag type.
-
template_txt= None¶ Widget body template in Handlebars syntax. Has access to the widget’s properties.
-
toJSON()¶ JSON representation of the object.
- Returns
JSON-compatible object representation of this widget.
-
update_descendents(*args)¶ Called by children when adopted to notify about all known descendents. In turn, forwards this information to this widgent’s parent and should bubble up to the main app.
- Parameters
args – Widget, Dictionary of widgets by identifier or List of Widgets.
- Returns
None
-