def prepare_for_new_session(self):
        """Instantiate and set up objects.

        Also takes additional measures to free memory and
        check whether there are issues with the nodes
        directory, in case a file is to be loaded.
        """
        ### first of all free up memory used by data/objects
        ### from a possible previous session, data/objects
        ### that may not be needed anymore
        free_up_memory()

        ### check if a valid filepath sits on 'source_path'
        ### attribute of the APP_REFS object (it means a
        ### file is loaded)
        try:
            APP_REFS.source_path

        ### if not, pick 'no_file' state name
        except AttributeError:
            state_name = "no_file"

        ### otherwise perform setups and add the update
        ### viz widgets to the methods to be executed when
        ### updating the window manager

        else:

            ### check if the local node packs provided in
            ### the file are appropriate, to prevent the
            ### application from crashing if such node
            ### packs don't exist or are somehow faulty

            original_local_node_packs = (
                get_formatted_local_node_packs(APP_REFS.source_path)
            )

            current_local_node_packs = original_local_node_packs.copy()

            local_node_packs_are_ok = True

            while True:

                try:
                    check_local_node_packs(current_local_node_packs)

                except NODE_PACK_ERRORS as err:

                    message = (
                        "One of the provided local node packs"
                        " presented the following issue:"
                        f" {err}; what would you like to do?"
                    )

                    buttons = (
                        ("Select replacement/new path", "select"),
                        ("Cancel loading file", None),
                    )

                    answer = create_and_show_dialog(
                        message,
                        buttons,
                        level_name="warning",
                    )

                    if answer == "select":

                        result = select_paths(
                            caption="Select replacement/new path for local node pack"
                        )

                        if result:

                            current_local_node_packs.remove(err.faulty_pack)

                            replacement = result[0]
                            current_local_node_packs.append(replacement)

                    else:

                        local_node_packs_are_ok = False
                        break

                else:
                    break

            if local_node_packs_are_ok:

                ### if by this point the original node
                ### packs listed have changed, then it is
                ### as if we changed the file, so we save
                ### its current contents before assigning
                ### the new node packs

                if set(current_local_node_packs) != set(original_local_node_packs):

                    APP_REFS.data["node_packs"] = [
                        str(path) for path in current_local_node_packs
                    ]

                    ## pass content from source to backup
                    ## files just like rotating contents
                    ## between log files in Python

                    save_timestamped_backup(
                        APP_REFS.source_path, USER_PREFS["NUMBER_OF_BACKUPS"]
                    )

                    ## save the data in the source,
                    ## since it now have different node
                    ## packs
                    save_pyl(APP_REFS.data, APP_REFS.source_path)

                    ## finally, copy the contents of the
                    ## source to the swap file

                    APP_REFS.swap_path.write_text(
                        APP_REFS.source_path.read_text(encoding="utf-8"),
                        encoding="utf-8",
                    )

            ### check if the "installed" node packs provided in
            ### the file are appropriate, to prevent the
            ### application from crashing if such node
            ### packs can't be found or are somehow faulty

            installed_node_packs = get_formatted_installed_node_packs(
                APP_REFS.source_path
            )

            try:
                check_installed_node_packs(installed_node_packs)
            except NODE_PACK_ERRORS as err:

                message = (
                    "One of the provided node packs"
                    " (the ones supposed to be installed)"
                    " presented the following issue:"
                    f" {err}; aborting loading file now"
                )

                create_and_show_dialog(message, level_name='error')

                installed_node_packs_are_ok = False

            else:
                installed_node_packs_are_ok = True

            if local_node_packs_are_ok and installed_node_packs_are_ok:

                ### try preparing graph manager for
                ### edition
                try:
                    APP_REFS.gm.prepare_for_new_session()

                ### if it fails, report the problem to
                ### user and pick the 'no_file' state name

                except Exception as err:

                    ## do this to signal other method not to
                    ## create extra dependencies
                    del APP_REFS.source_path

                    ## report problem to user

                    show_dialog_from_key("error_while_loading_node_packs_dialog")

                    ## also log it

                    msg = (
                        "Unexpected error(s) while trying to load node"
                        " packs for new session"
                    )

                    logger.exception(msg)

                    USER_LOGGER.error(f"{msg}\n\n{err}")

                    ###
                    state_name = "no_file"

                ### otherwise, perform additional setups
                ### and pick the 'loaded_file' state name

                else:

                    APP_REFS.ea.prepare_for_new_session()

                    if not APP_REFS.temp_filepaths_man.is_temp_path(
                        APP_REFS.source_path
                    ):
                        store_recent_file(APP_REFS.source_path)

                    self.build_app_widgets()

                    state_name = "loaded_file"

            ### otherwise, trigger cancellation of file
            ### loading and pick the 'no_file' state name

            else:

                show_dialog_from_key("cancelled_file_loading_dialog")

                self.clean_loaded_file_data()

                state_name = "no_file"

        ### set the state picked
        self.set_state(state_name)

        ### instantiate support widgets and set manager
        self.build_support_widgets()

        ### check again whether a valid filepath still sits on 'source_path'
        ### attribute of the APP_REFS object (it means a file is loaded)
        try:
            source_path = APP_REFS.source_path

        ### if not, reset caption to its initial state and build log message

        except AttributeError:

            reset_caption()
            log_message = "User started new session with no file loaded"

        ### otherwise, create the popup menu and build log message

        else:

            self.create_canvas_popup_menu()

            log_message = (
                f"User started new session with {source_path} loaded"
            )

        logger.info(log_message)
        USER_LOGGER.info(log_message)
Instantiate and set up objects.

        Also takes additional measures to free memory and
        check whether there are issues with the nodes
        directory, in case a file is to be loaded.
        
nodezator/winman/main.py