src/eric7/eric7_mpy.py

branch
eric7
changeset 10518
1682f3203ae5
child 10683
779cda568acb
equal deleted inserted replaced
10517:aecd5a8c958c 10518:1682f3203ae5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 eric MicroPython devices.
8
9 This is the main Python script to interact with MicroPython or CircuitPython devices
10 from outside of the IDE.
11 """
12
13 import argparse
14 import os
15 import sys
16
17 from PyQt6.QtGui import QGuiApplication
18
19
20 def createArgparseNamespace():
21 """
22 Function to create an argument parser.
23
24 @return created argument parser object
25 @rtype argparse.ArgumentParser
26 """
27 from eric7.UI.Info import Version
28
29 # 1. create the argument parser
30 parser = argparse.ArgumentParser(
31 description="Graphical tool of the eric tool suite to interact with µPy/CPy"
32 " devices",
33 epilog="Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de>.",
34 )
35
36 # 2. add the arguments
37 parser.add_argument(
38 "-V",
39 "--version",
40 action="version",
41 version="%(prog)s {0}".format(Version),
42 help="show version information and exit",
43 )
44 parser.add_argument(
45 "--config",
46 metavar="config_dir",
47 help="use the given directory as the one containing the config files",
48 )
49 parser.add_argument(
50 "--settings",
51 metavar="settings_dir",
52 help="use the given directory to store the settings files",
53 )
54
55 # 3. create the Namespace object by parsing the command line
56 args = parser.parse_args()
57 return args
58
59
60 args = createArgparseNamespace()
61 if args.config:
62 from eric7 import Globals
63
64 Globals.setConfigDir(args.config)
65 if args.settings:
66 from PyQt6.QtCore import QSettings
67
68 SettingsDir = os.path.expanduser(args.settings)
69 if not os.path.isdir(SettingsDir):
70 os.makedirs(SettingsDir)
71 QSettings.setPath(
72 QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir
73 )
74
75 from eric7.Toolbox import Startup
76
77
78 def createMainWidget(args): # noqa: U100
79 """
80 Function to create the main widget.
81
82 @param args namespace object containing the parsed command line parameters
83 @type argparse.Namespace
84 @return reference to the main widget
85 @rtype QWidget
86 """
87 from eric7.MicroPython.MicroPythonWindow import MicroPythonWindow
88
89 return MicroPythonWindow(None)
90
91
92 def main():
93 """
94 Main entry point into the application.
95 """
96 QGuiApplication.setDesktopFileName("eric7_mpy")
97
98 res = Startup.appStartup(args, createMainWidget)
99 sys.exit(res)
100
101
102 if __name__ == "__main__":
103 main()

eric ide

mercurial