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 MiniEditor module and starts the Qt event loop. This is a standalone |
11 of the MiniEditor module and starts the Qt event loop. This is a standalone |
12 version of the integrated MiniEditor module. |
12 version of the integrated MiniEditor module. |
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="Simplified version of the eric-ide editor of the eric tool suite.", |
|
34 epilog="Copyright (c) 2007 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>.", |
|
35 ) |
|
36 |
|
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 parser.add_argument( |
|
56 "file", |
|
57 nargs="?", |
|
58 help="file to be opened for editing", |
|
59 ) |
|
60 |
|
61 # 3. create the Namespace object by parsing the command line |
|
62 args = parser.parse_args() |
|
63 return args |
|
64 |
|
65 |
|
66 args = createArgparseNamespace() |
|
67 if args.config: |
|
68 from eric7 import Globals |
|
69 |
|
70 Globals.setConfigDir(args.config) |
|
71 if args.settings: |
|
72 from PyQt6.QtCore import QSettings |
|
73 |
|
74 SettingsDir = os.path.expanduser(args.settings) |
|
75 if not os.path.isdir(SettingsDir): |
|
76 os.makedirs(SettingsDir) |
|
77 QSettings.setPath( |
|
78 QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir |
|
79 ) |
|
80 |
39 from eric7.Toolbox import Startup |
81 from eric7.Toolbox import Startup |
40 |
82 |
41 |
83 |
42 def createMainWidget(argv): |
84 def createMainWidget(args): |
43 """ |
85 """ |
44 Function to create the main widget. |
86 Function to create the main widget. |
45 |
87 |
46 @param argv list of commandline parameters (list of strings) |
88 @param args namespace object containing the parsed command line parameters |
47 @return reference to the main widget (QWidget) |
89 @type argparse.Namespace |
|
90 @return reference to the main widget |
|
91 @rtype QWidget |
48 """ |
92 """ |
49 from eric7.QScintilla.MiniEditor import MiniEditor |
93 from eric7.QScintilla.MiniEditor import MiniEditor |
50 |
94 |
51 if len(argv) > 1: |
95 if args.file: |
52 return MiniEditor(argv[1]) |
96 return MiniEditor(args.file) |
53 else: |
97 else: |
54 return MiniEditor() |
98 return MiniEditor() |
55 |
99 |
56 |
100 |
57 def main(): |
101 def main(): |
58 """ |
102 """ |
59 Main entry point into the application. |
103 Main entry point into the application. |
60 """ |
104 """ |
61 QGuiApplication.setDesktopFileName("eric7_editor") |
105 QGuiApplication.setDesktopFileName("eric7_editor") |
62 |
106 |
63 options = [ |
107 res = Startup.appStartup(args, createMainWidget) |
64 ( |
|
65 "--config=configDir", |
|
66 "use the given directory as the one containing the config files", |
|
67 ), |
|
68 ( |
|
69 "--settings=settingsDir", |
|
70 "use the given directory to store the settings files", |
|
71 ), |
|
72 ("", "name of file to edit"), |
|
73 ] |
|
74 appinfo = AppInfo.makeAppInfo( |
|
75 sys.argv, "eric Editor", "", "Simplified version of the eric editor", options |
|
76 ) |
|
77 res = Startup.simpleAppStartup(sys.argv, appinfo, createMainWidget) |
|
78 sys.exit(res) |
108 sys.exit(res) |
79 |
109 |
80 |
110 |
81 if __name__ == "__main__": |
111 if __name__ == "__main__": |
82 main() |
112 main() |