src/eric7/eric7_qregularexpression.py

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

eric ide

mercurial