src/eric7/eric7_shell.py

Wed, 25 Sep 2024 14:48:57 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 25 Sep 2024 14:48:57 +0200
branch
eric7
changeset 10926
9ef616cd220d
parent 10716
11cdcc824469
child 11090
f5f5f5803935
permissions
-rw-r--r--

Moved some functions from 'Globals' to 'EricUtilities'.

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
10439
21c28b0f9e41 Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10303
diff changeset
4 # Copyright (c) 2017 - 2024 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 """
10716
11cdcc824469 Relocated the Version information into a top level '__version__.py' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10683
diff changeset
30 from eric7.__version__ import Version
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
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.",
10439
21c28b0f9e41 Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10303
diff changeset
36 epilog="Copyright (c) 2017 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>.",
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
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:
10926
9ef616cd220d Moved some functions from 'Globals' to 'EricUtilities'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10716
diff changeset
65 from eric7 import EricUtilities
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
66
10926
9ef616cd220d Moved some functions from 'Globals' to 'EricUtilities'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10716
diff changeset
67 EricUtilities.setConfigDir(args.config)
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
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
10683
779cda568acb Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10439
diff changeset
81 def createMainWidget(_args):
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
10683
779cda568acb Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10439
diff changeset
85 @param _args namespace object containing the parsed command line parameters
779cda568acb Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10439
diff changeset
86 (unused)
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
87 @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
88 @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
89 @rtype QWidget
5709
f81d0eca2c62 Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 """
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
91 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
92
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
93 return ShellWindow(originalPathString)
5709
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
f81d0eca2c62 Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 def main():
f81d0eca2c62 Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 """
f81d0eca2c62 Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 Main entry point into the application.
f81d0eca2c62 Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 """
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
100 QGuiApplication.setDesktopFileName("eric7_shell")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
101
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
102 res = Startup.appStartup(args, createMainWidget)
5709
f81d0eca2c62 Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 sys.exit(res)
f81d0eca2c62 Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
105
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
106 if __name__ == "__main__":
5709
f81d0eca2c62 Started implementing the standalone shell window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 main()

eric ide

mercurial