9 |
9 |
10 This is the main Python script that performs the necessary initialization |
10 This is the main Python script that performs the necessary initialization |
11 of the ShellWindow module and starts the Qt event loop. |
11 of the ShellWindow module and starts the Qt event loop. |
12 """ |
12 """ |
13 |
13 |
|
14 import argparse |
14 import os |
15 import os |
15 import sys |
16 import sys |
16 |
17 |
17 from PyQt6.QtGui import QGuiApplication |
18 from PyQt6.QtGui import QGuiApplication |
18 |
19 |
19 originalPathString = os.getenv("PATH") |
20 originalPathString = os.getenv("PATH") |
20 |
21 |
21 for arg in sys.argv[:]: |
|
22 if arg.startswith("--config="): |
|
23 from eric7 import Globals |
|
24 |
22 |
25 configDir = arg.replace("--config=", "") |
23 def createArgparseNamespace(): |
26 Globals.setConfigDir(configDir) |
24 """ |
27 sys.argv.remove(arg) |
25 Function to create an argument parser. |
28 elif arg.startswith("--settings="): |
|
29 from PyQt6.QtCore import QSettings |
|
30 |
26 |
31 settingsDir = os.path.expanduser(arg.replace("--settings=", "")) |
27 @return created argument parser object |
32 if not os.path.isdir(settingsDir): |
28 @rtype argparse.ArgumentParser |
33 os.makedirs(settingsDir) |
29 """ |
34 QSettings.setPath( |
30 from eric7.UI.Info import Version |
35 QSettings.Format.IniFormat, QSettings.Scope.UserScope, settingsDir |
|
36 ) |
|
37 sys.argv.remove(arg) |
|
38 |
31 |
39 from eric7.Globals import AppInfo |
32 # 1. create the argument parser |
|
33 parser = argparse.ArgumentParser( |
|
34 description="Stand alone variant of the eric interpreter shell." |
|
35 " It is part of the eric tool suite.", |
|
36 epilog="Copyright (c) 2017 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>.", |
|
37 ) |
|
38 |
|
39 # 2. add the arguments |
|
40 parser.add_argument( |
|
41 "-V", |
|
42 "--version", |
|
43 action="version", |
|
44 version="%(prog)s {0}".format(Version), |
|
45 help="show version information and exit", |
|
46 ) |
|
47 parser.add_argument( |
|
48 "--config", |
|
49 metavar="config_dir", |
|
50 help="use the given directory as the one containing the config files", |
|
51 ) |
|
52 parser.add_argument( |
|
53 "--settings", |
|
54 metavar="settings_dir", |
|
55 help="use the given directory to store the settings files", |
|
56 ) |
|
57 |
|
58 # 3. create the Namespace object by parsing the command line |
|
59 args = parser.parse_args() |
|
60 return args |
|
61 |
|
62 |
|
63 args = createArgparseNamespace() |
|
64 if args.config: |
|
65 from eric7 import Globals |
|
66 |
|
67 Globals.setConfigDir(args.config) |
|
68 if args.settings: |
|
69 from PyQt6.QtCore import QSettings |
|
70 |
|
71 SettingsDir = os.path.expanduser(args.settings) |
|
72 if not os.path.isdir(SettingsDir): |
|
73 os.makedirs(SettingsDir) |
|
74 QSettings.setPath( |
|
75 QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir |
|
76 ) |
|
77 |
40 from eric7.Toolbox import Startup |
78 from eric7.Toolbox import Startup |
41 |
79 |
42 |
80 |
43 def createMainWidget(argv): # noqa: U100 |
81 def createMainWidget(args): # noqa: U100 |
44 """ |
82 """ |
45 Function to create the main widget. |
83 Function to create the main widget. |
46 |
84 |
47 @param argv list of commandline parameters (list of strings) |
85 @param args namespace object containing the parsed command line parameters |
48 @return reference to the main widget (QWidget) |
86 @type argparse.Namespace |
|
87 @return reference to the main widget |
|
88 @rtype QWidget |
49 """ |
89 """ |
50 from eric7.QScintilla.ShellWindow import ShellWindow |
90 from eric7.QScintilla.ShellWindow import ShellWindow |
51 |
91 |
52 return ShellWindow(originalPathString) |
92 return ShellWindow(originalPathString) |
53 |
93 |
56 """ |
96 """ |
57 Main entry point into the application. |
97 Main entry point into the application. |
58 """ |
98 """ |
59 QGuiApplication.setDesktopFileName("eric7_shell") |
99 QGuiApplication.setDesktopFileName("eric7_shell") |
60 |
100 |
61 options = [ |
101 res = Startup.appStartup(args, createMainWidget) |
62 ( |
|
63 "--config=configDir", |
|
64 "use the given directory as the one containing the config files", |
|
65 ), |
|
66 ( |
|
67 "--settings=settingsDir", |
|
68 "use the given directory to store the settings files", |
|
69 ), |
|
70 ] |
|
71 appinfo = AppInfo.makeAppInfo( |
|
72 sys.argv, |
|
73 "eric Shell", |
|
74 "", |
|
75 "Stand alone version of the eric interpreter shell", |
|
76 options, |
|
77 ) |
|
78 res = Startup.simpleAppStartup(sys.argv, appinfo, createMainWidget) |
|
79 sys.exit(res) |
102 sys.exit(res) |
80 |
103 |
81 |
104 |
82 if __name__ == "__main__": |
105 if __name__ == "__main__": |
83 main() |
106 main() |