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_COLORSenvironment variable. Its value must contain a:-delimited list of<key>=<value>pairs, where<key>is one ofTRACE,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
TRACElevel gray and messages with theINFOlevel white, setGLASGOW_COLORStoTRACE=37:INFO=1;37.A
logging.StreamHandlerwriting tosys.stderris 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
mainfunction called from a newasyncioevent 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 wrappedmainfunction, as if that file includes the following code immediately after the definition ofmain: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.