src/eric7/eric7_qregularexpression.py

Mon, 07 Nov 2022 17:19:58 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 07 Nov 2022 17:19:58 +0100
branch
eric7
changeset 9482
a2bc06a54d9d
parent 9473
3f23dbf37dbe
child 9653
e67609152c5e
permissions
-rw-r--r--

Corrected/acknowledged some bad import style and removed some obsolete code.

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
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
4 # Copyright (c) 2013 - 2022 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
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
15 import os
6949
a5255f1ba3f0 setup.py: continued implementing support for setup.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
16 import sys
a5255f1ba3f0 setup.py: continued implementing support for setup.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
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
4343
afe0da217745 Added the '--settings=' command line switch to store the settings files in a non-standard directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4289
diff changeset
20 for arg in sys.argv[:]:
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 if arg.startswith("--config="):
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
22 from eric7 import Globals
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
23
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 configDir = arg.replace("--config=", "")
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Globals.setConfigDir(configDir)
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 sys.argv.remove(arg)
4343
afe0da217745 Added the '--settings=' command line switch to store the settings files in a non-standard directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4289
diff changeset
27 elif arg.startswith("--settings="):
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8314
diff changeset
28 from PyQt6.QtCore import QSettings
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
29
4343
afe0da217745 Added the '--settings=' command line switch to store the settings files in a non-standard directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4289
diff changeset
30 settingsDir = os.path.expanduser(arg.replace("--settings=", ""))
afe0da217745 Added the '--settings=' command line switch to store the settings files in a non-standard directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4289
diff changeset
31 if not os.path.isdir(settingsDir):
afe0da217745 Added the '--settings=' command line switch to store the settings files in a non-standard directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4289
diff changeset
32 os.makedirs(settingsDir)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7960
diff changeset
33 QSettings.setPath(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
34 QSettings.Format.IniFormat, QSettings.Scope.UserScope, settingsDir
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
35 )
4343
afe0da217745 Added the '--settings=' command line switch to store the settings files in a non-standard directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4289
diff changeset
36 sys.argv.remove(arg)
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
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
38 from eric7.Globals import AppInfo
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
39 from eric7.Toolbox import Startup
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 def createMainWidget(argv):
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 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
45
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @param argv list of commandline parameters (list of strings)
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 @return reference to the main widget (QWidget)
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 """
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
49 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
50 QRegularExpressionWizardDialog,
7257
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
51 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
52
7257
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
53 return QRegularExpressionWizardDialog.QRegularExpressionWizardWindow()
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 def main():
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 """
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 Main entry point into the application.
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
8314
e3642a6a1e71 Finished renaming eric6 to eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
60 QGuiApplication.setDesktopFileName("eric7_qregularexpression.desktop")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
61
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
62 options = [
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
63 (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
64 "--config=configDir",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
65 "use the given directory as the one containing the config files",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
66 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
67 (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
68 "--settings=settingsDir",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
69 "use the given directory to store the settings files",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
70 ),
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 ]
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2965
diff changeset
72 appinfo = AppInfo.makeAppInfo(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2965
diff changeset
73 sys.argv,
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
74 "eric QRegularExpression",
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2965
diff changeset
75 "",
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2965
diff changeset
76 "Regexp editor for Qt's QRegularExpression class",
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
77 options,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
78 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
79 res = Startup.simpleAppStartup(sys.argv, appinfo, createMainWidget)
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 sys.exit(res)
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
82
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
83 if __name__ == "__main__":
2736
86cd4d14b58e Added a wizard for the Qt5 QRegularExpression class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 main()

eric ide

mercurial