src/eric7/eric7_qregularexpression.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'.

2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 #!/usr/bin/env python3
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
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) 2013 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5 #
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
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 QRegularExpression.
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 This is the main Python script that performs the necessary initialization
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2965
diff changeset
11 of the QRegularExpression wizard module and starts the Qt event loop. This is
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2965
diff changeset
12 a standalone version of the integrated QRegularExpression wizard.
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 """
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
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
15 import argparse
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
16 import os
6949
a5255f1ba3f0 setup.py: continued implementing support for setup.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
17 import sys
a5255f1ba3f0 setup.py: continued implementing support for setup.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
18
9482
a2bc06a54d9d Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
19 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
20
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
21
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 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
23 """
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 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
25
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
26 @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
27 @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
28 """
10716
11cdcc824469 Relocated the Version information into a top level '__version__.py' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10683
diff changeset
29 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
30
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 # 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
32 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
33 description="Graphical regexp editor for the Qt QRegularExpression class."
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 " It is part of the eric tool suite.",
10439
21c28b0f9e41 Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10303
diff changeset
35 epilog="Copyright (c) 2013 - 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
36 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
37
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
38 # 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
39 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
40 "-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
41 "--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
42 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
43 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
44 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
45 )
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 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
47 "--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
48 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
49 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
50 )
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 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
52 "--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
53 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
54 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
55 )
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
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
57 # 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
58 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
59 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
60
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 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
63 if args.config:
10926
9ef616cd220d Moved some functions from 'Globals' to 'EricUtilities'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10716
diff changeset
64 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
65
10926
9ef616cd220d Moved some functions from 'Globals' to 'EricUtilities'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10716
diff changeset
66 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
67 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
68 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
69
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 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
71 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
72 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
73 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
74 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
75 )
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
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
77 from eric7.Toolbox import Startup
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79
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
80 def createMainWidget(_args):
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 """
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 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
83
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
84 @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
85 (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
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
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
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.Plugins.WizardPlugins.QRegularExpressionWizard import (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
91 QRegularExpressionWizardDialog,
7257
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
92 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
93
7257
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
94 return QRegularExpressionWizardDialog.QRegularExpressionWizardWindow()
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 def main():
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 """
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 Main entry point into the application.
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 """
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
101 QGuiApplication.setDesktopFileName("eric7_qregularexpression")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
102
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
103 res = Startup.appStartup(args, createMainWidget)
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 sys.exit(res)
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
106
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
107 if __name__ == "__main__":
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 main()

eric ide

mercurial