def build_mode_behaviour_map(self):
        """Build map with behaviours for each mode.

        The memory freeing behaviours for each mode,
        however, should be stored in a list apart, since we
        do not switch between them during the lifetime of the
        colors viewer; instead they are executed together
        whenever the user leaves the colors viewer.

        Both mode exiting (exit_mode) and memory freeing
        operations aim to perform cleanup operations,
        but the cleanup performed by memory freeing
        operations is more deep or definitive,
        since mode exiting operations perform cleanup
        when switching between modes while memory freeing
        operations perform cleanups when leaving the colors
        viewer.
        """
        ### create and store map in its own attribute,
        ### also referencing it in a local variable
        mdb_map = self.mode_behaviour_map = {}

        ### also create a custom list where we'll gather
        ### all memory freeing behaviours, referencing it
        ### locally as well
        memory_freeing_behaviours = self.memory_freeing_behaviours = CallList()

        ### create a behaviour map for each mode, storing
        ### it in the map created above, associated with
        ### a string representing the name of the mode

        for mode_name in MODE_NAMES:

            ## create, store and reference behaviour map
            ## locally
            behaviour_map = mdb_map[mode_name] = {}

            ## for each behaviour name, gather the
            ## corresponding behaviour for the current
            ## mode (or an empty function, if said behaviour
            ## is missing) and assign it to the map using
            ## the behaviour name as a key;
            ##
            ## unless the behaviour is a memory freeing
            ## behaviour, in which case it goes in the
            ## dedicated list for memory freeing operations

            for behaviour_name in BEHAVIOUR_NAMES:

                ## build the attribute name for this
                ## behaviour in this mode
                attr_name = mode_name + "_" + behaviour_name

                ## use the name as an attribute name,
                ## retrieving the corresponding behaviour
                ## from that attribute;
                ##
                ## if the attribute doesn't exist, an empty
                ## function is used instead

                behaviour = getattr(self, attr_name, empty_function)

                ## if we are dealing with a memory freeing
                ## behaviour, store it in the dedicated list

                if behaviour_name == "free_up_memory":
                    memory_freeing_behaviours.append(behaviour)

                ## otherwise, store the behaviour in the map
                ## using the behaviour name as the key

                else:

                    behaviour_map[behaviour_name] = behaviour
Build map with behaviours for each mode.

        The memory freeing behaviours for each mode,
        however, should be stored in a list apart, since we
        do not switch between them during the lifetime of the
        colors viewer; instead they are executed together
        whenever the user leaves the colors viewer.

        Both mode exiting (exit_mode) and memory freeing
        operations aim to perform cleanup operations,
        but the cleanup performed by memory freeing
        operations is more deep or definitive,
        since mode exiting operations perform cleanup
        when switching between modes while memory freeing
        operations perform cleanups when leaving the colors
        viewer.
        
nodezator/colorsman/viewer/main.py