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 system-tray application. This acts as a quickstarter by providing a |
11 of the system-tray application. This acts as a quickstarter by providing a |
12 context menu to start the eric IDE and the eric tools. |
12 context menu to start the eric IDE and the eric tools. |
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 SettingsDir = None |
|
21 |
21 |
22 for arg in sys.argv[:]: |
22 def createArgparseNamespace(): |
23 if arg.startswith("--config="): |
23 """ |
24 from eric7 import Globals |
24 Function to create an argument parser. |
25 |
25 |
26 configDir = arg.replace("--config=", "") |
26 @return created argument parser object |
27 Globals.setConfigDir(configDir) |
27 @rtype argparse.ArgumentParser |
28 sys.argv.remove(arg) |
28 """ |
29 elif arg.startswith("--settings="): |
29 from eric7.UI.Info import Version |
30 from PyQt6.QtCore import QSettings |
|
31 |
30 |
32 SettingsDir = os.path.expanduser(arg.replace("--settings=", "")) |
31 # 1. create the argument parser |
33 if not os.path.isdir(SettingsDir): |
32 parser = argparse.ArgumentParser( |
34 os.makedirs(SettingsDir) |
33 description="Tray starter for the tools of the eric tool suite.", |
35 QSettings.setPath( |
34 epilog="Copyright (c) 2006 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>.", |
36 QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir |
35 ) |
37 ) |
|
38 sys.argv.remove(arg) |
|
39 |
36 |
40 from eric7.Globals import AppInfo |
37 # 2. add the arguments |
|
38 parser.add_argument( |
|
39 "-V", |
|
40 "--version", |
|
41 action="version", |
|
42 version="%(prog)s {0}".format(Version), |
|
43 help="show version information and exit", |
|
44 ) |
|
45 parser.add_argument( |
|
46 "--config", |
|
47 metavar="config_dir", |
|
48 help="use the given directory as the one containing the config files", |
|
49 ) |
|
50 parser.add_argument( |
|
51 "--settings", |
|
52 metavar="settings_dir", |
|
53 help="use the given directory to store the settings files", |
|
54 ) |
|
55 |
|
56 # 3. create the Namespace object by parsing the command line |
|
57 args = parser.parse_args() |
|
58 return args |
|
59 |
|
60 |
|
61 args = createArgparseNamespace() |
|
62 if args.config: |
|
63 from eric7 import Globals |
|
64 |
|
65 Globals.setConfigDir(args.config) |
|
66 if args.settings: |
|
67 from PyQt6.QtCore import QSettings |
|
68 |
|
69 SettingsDir = os.path.expanduser(args.settings) |
|
70 if not os.path.isdir(SettingsDir): |
|
71 os.makedirs(SettingsDir) |
|
72 QSettings.setPath( |
|
73 QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir |
|
74 ) |
|
75 else: |
|
76 SettingsDir = None |
41 from eric7.Toolbox import Startup |
77 from eric7.Toolbox import Startup |
42 |
78 |
43 |
79 |
44 def createMainWidget(argv): # noqa: U100 |
80 def createMainWidget(args): # noqa: U100 |
45 """ |
81 """ |
46 Function to create the main widget. |
82 Function to create the main widget. |
47 |
83 |
48 @param argv list of commandline parameters (list of strings) |
84 @param args namespace object containing the parsed command line parameters |
49 @return reference to the main widget (QWidget) |
85 @type argparse.Namespace |
|
86 @return reference to the main widget |
|
87 @rtype QWidget |
50 """ |
88 """ |
51 from eric7.Tools.TrayStarter import TrayStarter |
89 from eric7.Tools.TrayStarter import TrayStarter |
52 |
90 |
53 return TrayStarter(SettingsDir) |
91 return TrayStarter(SettingsDir) |
54 |
92 |
57 """ |
95 """ |
58 Main entry point into the application. |
96 Main entry point into the application. |
59 """ |
97 """ |
60 QGuiApplication.setDesktopFileName("eric7_tray") |
98 QGuiApplication.setDesktopFileName("eric7_tray") |
61 |
99 |
62 options = [ |
100 res = Startup.appStartup( |
63 ( |
101 args, createMainWidget, quitOnLastWindowClosed=False, raiseIt=False |
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, "eric Tray", "", "Traystarter for eric", options |
|
74 ) |
|
75 res = Startup.simpleAppStartup( |
|
76 sys.argv, appinfo, createMainWidget, quitOnLastWindowClosed=False, raiseIt=False |
|
77 ) |
102 ) |
78 sys.exit(res) |
103 sys.exit(res) |
79 |
104 |
80 |
105 |
81 if __name__ == "__main__": |
106 if __name__ == "__main__": |