Source

ginsfsm / ginsfsm / scaffolds / simple_gobj / +package+ / c_+package+.py_tmpl

The default branch has multiple heads

Full commit
# -*- encoding: utf-8 -*-
""" {{package.capitalize()}} GObj

.. autoclass:: {{package.capitalize()}}
    :members: start_up

"""

from ginsfsm.gobj import GObj


def ac_sample(self, event):
    """ Event attributes:
        * :attr:`data`: example.

    """
    if self.output_event_name is not None:
        self.broadcast_event(self.output_event_name, data=event.data)


{{package.upper()}}_FSM = {
    'event_list': (
        'EV_INPUT_EVENT:top input',
        'EV_OUTPUT_EVENT:top output',
    ),
    'state_list': (
        'ST_IDLE',
    ),
    'machine': {
        'ST_IDLE':
        (
            ('EV_INPUT_EVENT',      ac_sample,      None),
        ),
    }
}

{{package.upper()}}_GCONFIG = {
    'subscriber': [
        None, None, 0, None,
        "subcriber of all output-events."
        "Default is ``None``, i.e., the parent"
    ],

    # If some name is None then the parent don't want receive it.
    'output_event_name': [
        str, 'EV_OUTPUT_EVENT', 0, None,
        "Name of the *sample output* event."
        " ``None`` if you want ignore the event"
    ],
}


class {{package.capitalize()}}(GObj):
    """  {{package.capitalize()}} GObj.
    A Sample gobj.

    .. ginsfsm::
       :fsm: {{package.upper()}}_FSM
       :gconfig: {{package.upper()}}_GCONFIG

    *Input-Events:*
        * :attr:`'EV_INPUT_EVENT'`: sample input event.

          Event attributes:

              * ``data``: sample event attribute.

    *Output-Events:*
        * :attr:`'EV_OUTPUT_EVENT'`: sample output event.

          Event attributes:

              * ``data``: sample event attribute.

    """
    def __init__(self):
        GObj.__init__(self, {{package.upper()}}_FSM, {{package.upper()}}_GCONFIG)

    def start_up(self):
        """ Initialization zone.
        """
        if self.config.subscriber is None:
            self.config.subscriber = self.parent
        self.subscribe_event(None, self.config.subscriber)