src/eric7/eric7_configure.py

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

eric ide

mercurial