src/eric7/eric7_mpy.py

branch
eric7
changeset 10518
1682f3203ae5
child 10683
779cda568acb
diff -r aecd5a8c958c -r 1682f3203ae5 src/eric7/eric7_mpy.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/eric7/eric7_mpy.py	Sun Jan 21 15:38:51 2024 +0100
@@ -0,0 +1,103 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+eric MicroPython devices.
+
+This is the main Python script to interact with MicroPython or CircuitPython devices
+from outside of the IDE.
+"""
+
+import argparse
+import os
+import sys
+
+from PyQt6.QtGui import QGuiApplication
+
+
+def createArgparseNamespace():
+    """
+    Function to create an argument parser.
+
+    @return created argument parser object
+    @rtype argparse.ArgumentParser
+    """
+    from eric7.UI.Info import Version
+
+    # 1. create the argument parser
+    parser = argparse.ArgumentParser(
+        description="Graphical tool of the eric tool suite to interact with µPy/CPy"
+        " devices",
+        epilog="Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de>.",
+    )
+
+    # 2. add the arguments
+    parser.add_argument(
+        "-V",
+        "--version",
+        action="version",
+        version="%(prog)s {0}".format(Version),
+        help="show version information and exit",
+    )
+    parser.add_argument(
+        "--config",
+        metavar="config_dir",
+        help="use the given directory as the one containing the config files",
+    )
+    parser.add_argument(
+        "--settings",
+        metavar="settings_dir",
+        help="use the given directory to store the settings files",
+    )
+
+    # 3. create the Namespace object by parsing the command line
+    args = parser.parse_args()
+    return args
+
+
+args = createArgparseNamespace()
+if args.config:
+    from eric7 import Globals
+
+    Globals.setConfigDir(args.config)
+if args.settings:
+    from PyQt6.QtCore import QSettings
+
+    SettingsDir = os.path.expanduser(args.settings)
+    if not os.path.isdir(SettingsDir):
+        os.makedirs(SettingsDir)
+    QSettings.setPath(
+        QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir
+    )
+
+from eric7.Toolbox import Startup
+
+
+def createMainWidget(args):  # noqa: U100
+    """
+    Function to create the main widget.
+
+    @param args namespace object containing the parsed command line parameters
+    @type argparse.Namespace
+    @return reference to the main widget
+    @rtype QWidget
+    """
+    from eric7.MicroPython.MicroPythonWindow import MicroPythonWindow
+
+    return MicroPythonWindow(None)
+
+
+def main():
+    """
+    Main entry point into the application.
+    """
+    QGuiApplication.setDesktopFileName("eric7_mpy")
+
+    res = Startup.appStartup(args, createMainWidget)
+    sys.exit(res)
+
+
+if __name__ == "__main__":
+    main()

eric ide

mercurial