Sat, 11 Nov 2023 12:44:51 +0100
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
5709
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | #!/usr/bin/env python3 |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | # -*- coding: utf-8 -*- |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
3 | |
9653
e67609152c5e
Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
4 | # Copyright (c) 2017 - 2023 Detlev Offenbach <detlev@die-offenbachs.de> |
5709
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | # |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | """ |
7960
e8fc383322f7
Harmonized some user visible strings and changed the term 'eric6' to the more generic 'eric'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
8 | eric Shell. |
5709
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | This is the main Python script that performs the necessary initialization |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | of the ShellWindow module and starts the Qt event loop. |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | """ |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
14 | import argparse |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
15 | import os |
6581
8eb6220f2bb7
Shell: changed code to start the shell/debugger backend with an unmodified PATH setting and added some more special commands (see what's this help of the shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
16 | import sys |
8eb6220f2bb7
Shell: changed code to start the shell/debugger backend with an unmodified PATH setting and added some more special commands (see what's this help of the shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
17 | |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
18 | from PyQt6.QtGui import QGuiApplication |
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
19 | |
6581
8eb6220f2bb7
Shell: changed code to start the shell/debugger backend with an unmodified PATH setting and added some more special commands (see what's this help of the shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
20 | originalPathString = os.getenv("PATH") |
8eb6220f2bb7
Shell: changed code to start the shell/debugger backend with an unmodified PATH setting and added some more special commands (see what's this help of the shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
21 | |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
22 | |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
23 | def createArgparseNamespace(): |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
24 | """ |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
25 | Function to create an argument parser. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
26 | |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
27 | @return created argument parser object |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
28 | @rtype argparse.ArgumentParser |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
29 | """ |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
30 | from eric7.UI.Info import Version |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
31 | |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
32 | # 1. create the argument parser |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
33 | parser = argparse.ArgumentParser( |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
34 | description="Stand alone variant of the eric interpreter shell." |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
35 | " It is part of the eric tool suite.", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
36 | epilog="Copyright (c) 2017 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>.", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
37 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
38 | |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
39 | # 2. add the arguments |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
40 | parser.add_argument( |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
41 | "-V", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
42 | "--version", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
43 | action="version", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
44 | version="%(prog)s {0}".format(Version), |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
45 | help="show version information and exit", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
46 | ) |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
47 | parser.add_argument( |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
48 | "--config", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
49 | metavar="config_dir", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
50 | help="use the given directory as the one containing the config files", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
51 | ) |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
52 | parser.add_argument( |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
53 | "--settings", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
54 | metavar="settings_dir", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
55 | help="use the given directory to store the settings files", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
56 | ) |
5709
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
58 | # 3. create the Namespace object by parsing the command line |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
59 | args = parser.parse_args() |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
60 | return args |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
61 | |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
62 | |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
63 | args = createArgparseNamespace() |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
64 | if args.config: |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
65 | from eric7 import Globals |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
66 | |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
67 | Globals.setConfigDir(args.config) |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
68 | if args.settings: |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
69 | from PyQt6.QtCore import QSettings |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
70 | |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
71 | SettingsDir = os.path.expanduser(args.settings) |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
72 | if not os.path.isdir(SettingsDir): |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
73 | os.makedirs(SettingsDir) |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
74 | QSettings.setPath( |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
75 | QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
76 | ) |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
77 | |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
78 | from eric7.Toolbox import Startup |
5709
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
81 | def createMainWidget(args): # noqa: U100 |
5709
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | """ |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | Function to create the main widget. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
84 | |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
85 | @param args namespace object containing the parsed command line parameters |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
86 | @type argparse.Namespace |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
87 | @return reference to the main widget |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
88 | @rtype QWidget |
5709
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | """ |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
90 | from eric7.QScintilla.ShellWindow import ShellWindow |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
91 | |
6581
8eb6220f2bb7
Shell: changed code to start the shell/debugger backend with an unmodified PATH setting and added some more special commands (see what's this help of the shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
92 | return ShellWindow(originalPathString) |
5709
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | def main(): |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | """ |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | Main entry point into the application. |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | """ |
10238
9ea4634a697e
Corrected the filename for 'QGuiApplication.setDesktopFileName()' to not include the '.desktop' extension anymore (as directed by Qt).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10069
diff
changeset
|
99 | QGuiApplication.setDesktopFileName("eric7_shell") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
100 | |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
101 | res = Startup.appStartup(args, createMainWidget) |
5709
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | sys.exit(res) |
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
104 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
105 | if __name__ == "__main__": |
5709
f81d0eca2c62
Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | main() |