Skip to content

function removeEventHandler

This function will unbind function from specified event.
Original: removeEventHandler

Declaration

def removeEventHandler(name : str, func : object)

Parameters

  • str name: the name of the event
  • object func: the reference to a function which is currently bound to specified event.

Usage

import g2o

@g2o.event('onTime')
def onTimeEvt(**kwargs):
    print('Calling only once')
    g2o.removeEventHandler('onTime', onTimeEvt)
Source code in src/pyg2o/functions/event.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def removeEventHandler(name : str, func : object):
    """
    This function will unbind function from specified event.
    Original: [removeEventHandler](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/event/removeEventHandler/)

    ## Declaration
    ```python
    def removeEventHandler(name : str, func : object)
    ```

    ## Parameters
    * `str` **name**: the name of the event
    * `object` **func**: the reference to a function which is currently bound to specified event.

    ## Usage
    ```python
    import g2o

    @g2o.event('onTime')
    def onTimeEvt(**kwargs):
        print('Calling only once')
        g2o.removeEventHandler('onTime', onTimeEvt)
    ```
    """
    if not name in eventList:
        pass

    for index, item in enumerate(eventList[name]):
        if item['function'] == func:
            del eventList[name][index]