File indexing completed on 2024-12-08 10:58:23
0001 #!/usr/bin/env python3 0002 0003 # SPDX-License-Identifier: GPL-3.0-or-later 0004 # SPDX-FileCopyrightText: 2021 Anupam Basak <anupam.basak27@gmail.com> 0005 0006 import sys 0007 import os 0008 0009 # Add current dir to system path for module name resolution 0010 from PicoWizard.utils.config import Config 0011 0012 sys.path.append(os.path.dirname(os.path.realpath(__file__ + '/../'))) 0013 0014 import argparse 0015 import signal 0016 0017 from PySide2.QtCore import QUrl 0018 from PySide2.QtQml import QQmlApplicationEngine, qmlRegisterType, QQmlFileSelector 0019 from PySide2.QtQuickControls2 import QQuickStyle 0020 from PySide2.QtWidgets import QApplication 0021 0022 from PicoWizard.utils.logger import Logger 0023 import PicoWizard.utils.constants as Constants 0024 0025 0026 log = None 0027 0028 0029 def registerTypes(): 0030 log.info('Registering QML types') 0031 qmlRegisterType(ModuleLoader, 'PicoWizard', 1, 0, 'ModuleLoader') 0032 0033 0034 def __main__(): 0035 log.info('Initializing Application') 0036 0037 app = QApplication(sys.argv) 0038 app.setApplicationName('pico-wizard') 0039 app.setApplicationDisplayName('Pico Wizard') 0040 0041 registerTypes() 0042 ModuleLoader.registerModuleTypes() 0043 0044 engine = QQmlApplicationEngine() 0045 selector = QQmlFileSelector(engine); 0046 engine.addImportPath(os.path.dirname(os.path.realpath(__file__))) 0047 engine.rootContext().setContextProperty('maximizeWindow', args.maximize) 0048 engine.load(QUrl(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'start.qml'))) 0049 0050 if not engine.rootObjects(): 0051 sys.exit(-1) 0052 0053 signal.signal(signal.SIGINT, signal.SIG_DFL) 0054 0055 sys.exit(app.exec_()) 0056 0057 0058 parser = argparse.ArgumentParser(prog='pico-wizard', description='Pico Wizard') 0059 parser.add_argument('--debug', dest='debug', action='store_true', help='Enable debug mode') 0060 parser.add_argument('--maximize', dest='maximize', action="store_true", help='Maximize window') 0061 parser.set_defaults(debug=False) 0062 parser.set_defaults(maximize=False) 0063 args = parser.parse_args() 0064 0065 Logger.setLogMode(Config.getLogLevel()) 0066 0067 if args.debug: 0068 Logger.setLogMode(Logger.Mode.DEBUG) 0069 0070 log = Logger.getLogger(__name__) 0071 0072 log.info(f'Logging to file {Constants.LOG_FILE_PATH}') 0073 0074 # Import ModuleLoader after setting debug mode 0075 from PicoWizard.moduleloader import ModuleLoader 0076 0077 if __name__ == '__main__': 0078 # execute only if run as the entry point into the program 0079 __main__()