[main] wrap code into functions, add argparse to allow to set log level
This commit is contained in:
parent
6f4ac1136b
commit
4762921ccd
21
main.py
21
main.py
@ -3,8 +3,10 @@ pyside6-rcc resources.qrc -o resources.py
|
||||
|
||||
"""
|
||||
import sys
|
||||
import platform
|
||||
import logging
|
||||
import argparse
|
||||
import platform
|
||||
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from PySide6.QtCore import QSettings
|
||||
from PySide6.QtGui import QIcon, QPalette
|
||||
@ -26,9 +28,11 @@ def is_dark_mode(app: QApplication) -> bool:
|
||||
|
||||
return brightness(base_color) < brightness(text_color)
|
||||
|
||||
def set_logging(loglevel):
|
||||
logging.basicConfig(level=loglevel, force=True)
|
||||
|
||||
# import resources # needs to be imported somewhere in the project to be picked up by qt
|
||||
|
||||
def main(args):
|
||||
set_logging(logging.DEBUG)
|
||||
if platform.system() == "Windows":
|
||||
# from PySide6.QtWinExtras import QtWin
|
||||
myappid = f"{info.organization_name}.{info.application_version}"
|
||||
@ -38,6 +42,7 @@ width = int(settings.value("app/width", 1024))
|
||||
height = int(settings.value("app/height", 768))
|
||||
x = int(settings.value("app/pos_x", 100))
|
||||
y = int(settings.value("app/pos_y", 100))
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
app.setApplicationName(info.application_name)
|
||||
app.setApplicationVersion(str(info.application_version))
|
||||
@ -63,3 +68,13 @@ settings.setValue("app/width", window.width())
|
||||
settings.setValue("app/height", window.height())
|
||||
settings.setValue("app/pos_x", pos.x())
|
||||
settings.setValue("app/pos_y", pos.y())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
levels = {"critical": logging.CRITICAL, "error": logging.ERROR, "warning":logging.WARNING, "info":logging.INFO, "debug":logging.DEBUG}
|
||||
parser = argparse.ArgumentParser(description="FixTracks. Tools for fixing animal tracking")
|
||||
parser.add_argument("-ll", "--loglevel", type=str, default="INFO", help=f"The log level that should be used. Valid levels are {[str(k) for k in levels.keys()]}")
|
||||
args = parser.parse_args()
|
||||
args.loglevel = levels[args.loglevel if args.loglevel.lower() in levels else "info"]
|
||||
|
||||
main(args)
|
||||
|
Loading…
Reference in New Issue
Block a user