battery_boost.__main__

Entry point for the Battery Boost application.

Initialises and launches the Tkinter GUI for managing TLP battery charge profiles. Battery Boost allows users to toggle between normal optimization and full-charge modes, with battery status display.

main

Entry point of the TLP Battery Boost application.

  • Configures the logging level based on the DEBUG constant.
  • Parses command-line arguments to determine the GUI theme and font settings.
  • Instantiates the main App class with the chosen theme and fonts.
  • Starts the Tkinter main event loop.
  • Handles user interrupts and ensures clean shutdown.
  • Revokes any elevated permissions acquired during execution.

Raises:

Type Description
KeyboardInterrupt

Gracefully exits if the user sends an interrupt signal (e.g., Ctrl+C). The GUI is destroyed if it was created.

Exception

Any unhandled exception during app initialization or execution is logged as critical and causes the program to exit with a non-zero status.

Source code in src/battery_boost/__main__.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def main() -> None:
    """Entry point of the TLP Battery Boost application.

    - Configures the logging level based on the `DEBUG` constant.
    - Parses command-line arguments to determine the GUI theme and font settings.
    - Instantiates the main `App` class with the chosen theme and fonts.
    - Starts the Tkinter main event loop.
    - Handles user interrupts and ensures clean shutdown.
    - Revokes any elevated permissions acquired during execution.

    Exceptions:
        KeyboardInterrupt: Gracefully exits if the user sends an interrupt
            signal (e.g., Ctrl+C). The GUI is destroyed if it was created.
        Exception: Any unhandled exception during app initialization or
            execution is logged as critical and causes the program to exit
            with a non-zero status.
    """
    debug_level = logging.DEBUG if DEBUG else logging.WARNING
    logging.basicConfig(
        level=debug_level,
        format="%(levelname)s: %(name)s %(message)s",
    )

    theme_choice, font_normal, font_small, factor = parse_args(sys.argv[1:])
    app = None
    try:
        app = App(theme_choice, font_normal, font_small, factor)
        app.mainloop()
    except KeyboardInterrupt:
        if app:
            app.destroy()
    # Catchall if App fails to launch with unhandled exception.
    except Exception as exc:  # pylint: disable=broad-exception-caught
        logging.critical(exc)
        sys.exit(1)
    finally:
        revoke_permissions()