resources/helpers.py

Module functionality:

Setting up the script name on first launch

To set the name of the script, use the helpers.set_script_name function.

Function arguments:

  • name (str, optional)The name of the script that will be set on first launch. If not specified, the function parses the script name from the parameters in the format {title} v{version}, for example, My Script v1.0 .


The script changes the name only if the current script name is standard.

  • Yeni skript
  • Unnamed Script
  • უსახელო სკრიპტი
  • Жаңа скрипт
  • Script nou
  • Новый скрипт
  • Yeni skript dosyası
  • Новий скрипт
  • 未命名脚本

Code examples

Setting the script name from parameters. The name of the script will be: My Script v1.0

# Write script description here
'''
<parameters>
    <company>My Company</company>
    <title>My Script</title>
    <version>1.0</version>
</parameters>
'''
import helpers

helpers.set_script_name()

Setting the script name without parameters.

import helpers

helpers.set_script_name(name="My Best Script")

Logger setup

To work with the logger, the module provides two functions:

  • Logger initialization - helpers.init_logger
  • Getting the logger from the main script - helpers.get_logger

The helpers.init_logger function creates an instance of the logger and configures required handlers.

Function arguments:

  • name (str)The name of the logger. Each script should be assigned to unique logger name.
  • debug (bool, optional): Debug mode. False by default.
  • duplicate_filter (bool, optional)If True - ignores duplicate messages (only for MyFileHandler).

Available handlers:

  • HostLogHandlerWriting logs to the main Trassir log.
  • PopupHandlerDisplays popup messages in the lower right corner of the screen.
  • MyFileHandlerMyFileHandler - Writing logs to the file '{LOGGER_NAME} ({SCRIPT_GUID}). Log' to the screenshots folder. Added only in debug mode.

Logging level depending on the debug mode:

debugFalseTrue
HostLogHandlerINFODEBUG
PopupHandlerWARNINGINFO
MyFileHandler-DEBUG


The helpers.get_logger function looks for a logger object in the main body of the script. If not found - returns logging.getLogger.

Almost all modules, during the initialization, are trying to get a logger object from this function.
In order for all modules to be able to write a log to one script file, it is necessary to initialize the logger object into the logger variable before importing them.

Code example
# Standard library imports
import os
import sys

# Related third party imports
import host
import sqlalchemy

# Import helpers and init logger
import helpers

logger = helpers.init_logger("myLogger", debug=DEBUG)

# Local application/library specific imports
import shot_saver
import video_exporter


  • Нет меток