main

Application entry point.

This module contains utility functions that handle start-up of the Glasgow CLI as well as custom applications based on the Glasgow API. To begin building your application, copy the following example:

from glasgow.hardware.device import GlasgowDevice
from glasgow.main import run_async, setup_logging

@run_async
async def main():
    setup_logging(level="TRACE")

    device = await GlasgowDevice.find()
    print(device.serial_number)
glasgow.main.setup_logging(*, level: int | str | None = None) → StreamHandler

Configure logging.

The ANSI escape sequences used to colorize the output can be customized via the GLASGOW_COLORS environment variable. Its value must contain a :-delimited list of <key>=<value> pairs, where <key> is one of TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL, RESET, and <value> is used as the core of an escape sequence "033[<value>m".

For example, to make messages with the TRACE level gray and messages with the INFO level white, set GLASGOW_COLORS to TRACE=37:INFO=1;37.

A logging.StreamHandler writing to sys.stderr is created, attached to the root logger, and returned.

glasgow.main.run_async(main: Callable[[], int | None])

Configure the runtime and call main.

This decorator is used as a convenient way to use the Glasgow library in your own scripts. The main function called from a new asyncio event loop after applying any necessary workarounds for platform and library quirks.

Moreover, if the file with the run_async() decorator is directly invoked from the command line (as opposed to being imported), it also calls the wrapped main function, as if that file includes the following code immediately after the definition of main:

if __name__ == "__main__":
    main()
glasgow.main.run_async_qtwidgets(main: Callable[[], int | None])

Configure the Qt runtime and call main.

This decorator serves the same purpose as run_async() and works the same way, except that it initializes a graphical application using the QtWidgets library.

glasgow.main.run_async_qtqml(main: Callable[[], int | None])

Configure the Qt runtime and call main.

This decorator serves the same purpose as run_async() and works the same way, except that it initializes a graphical application using the QtQml library.