WhakerPy 0.8

https://sourceforge.net/projects/whakerpy/

Module whakerpy.htmlmaker

Class HTMLButtonNode

Description

Represent a button element.

The set_attribute method should be overridden to check if the given key is in the list of accepted attributes.

Constructor

Create an input node. Default type is 'text'.

Parameters
  • parent
  • identifier
  • attributes
View Source
def __init__(self, parent, identifier, attributes=dict()):
    """Create an input node. Default type is 'text'.

    """
    super(HTMLButtonNode, self).__init__(parent, identifier, 'button', attributes=attributes)
    if 'id' not in attributes:
        self.add_attribute('id', self.identifier)
    if 'name' not in attributes:
        self.add_attribute('name', self.identifier)
    if 'type' not in attributes:
        self.add_attribute('type', 'button')

Public functions

set_icon

Set an icon to the button from its filename.

Parameters
  • icon: (str) Name of an icon in the app.
  • attributes: (dict).
View Source
def set_icon(self, icon, attributes=dict()):
    """Set an icon to the button from its filename.

        :param icon: (str) Name of an icon in the app.
        :param attributes: (dict).

        """
    node = HTMLImage(self.identifier, None, src=icon)
    if len(attributes) > 0:
        for key in attributes:
            node.set_attribute(key, attributes[key])
    self.append_child(node)
    return node

set_text

Set a text to the button.

Parameters
  • ident: (str) Identifier for the span text.
  • text: (str) Button text.
  • attributes: (dict)
View Source
def set_text(self, ident, text, attributes=dict()):
    """Set a text to the button.

        :param ident: (str) Identifier for the span text.
        :param text: (str) Button text.
        :param attributes: (dict)

        """
    node = HTMLNode(self.identifier, ident, 'span', value=text, attributes=attributes)
    if ident is not None:
        node.set_attribute('id', ident)
    self.append_child(node)
    if ident is not None:
        self.set_attribute('aria-labelledby', node.identifier)
    return node