56 |
57 |
57 WEBENGINE_AVAILABLE = True |
58 WEBENGINE_AVAILABLE = True |
58 except ImportError: |
59 except ImportError: |
59 WEBENGINE_AVAILABLE = False |
60 WEBENGINE_AVAILABLE = False |
60 |
61 |
|
62 |
|
63 def createArgparseNamespace(): |
|
64 """ |
|
65 Function to create an argument parser. |
|
66 |
|
67 @return created argument parser object |
|
68 @rtype argparse.ArgumentParser |
|
69 """ |
|
70 from eric7.UI.Info import Version |
|
71 |
|
72 # 1. create the argument parser |
|
73 parser = argparse.ArgumentParser( |
|
74 description="The full featured eric Python IDE.", |
|
75 epilog="Use '--' to indicate that there are options for the program to be" |
|
76 " debugged (everything after that is considered arguments for this program)", |
|
77 ) |
|
78 |
|
79 # 2. add the arguments |
|
80 parser.add_argument( |
|
81 "-V", |
|
82 "--version", |
|
83 action="version", |
|
84 version="%(prog)s {0}".format(Version), |
|
85 help="show version information and exit", |
|
86 ) |
|
87 parser.add_argument( |
|
88 "--debug", |
|
89 action="store_true", |
|
90 help="activate debugging output to the console", |
|
91 ) |
|
92 parser.add_argument( |
|
93 "--config", |
|
94 metavar="config_dir", |
|
95 help="use the given directory as the one containing the config files", |
|
96 ) |
|
97 parser.add_argument( |
|
98 "--settings", |
|
99 metavar="settings_dir", |
|
100 help="use the given directory to store the settings files", |
|
101 ) |
|
102 parser.add_argument( |
|
103 "--small-screen", |
|
104 action="store_true", |
|
105 help="adjust the interface for screens smaller than FHD", |
|
106 ) |
|
107 parser.add_argument( |
|
108 "--no-multimedia", |
|
109 action="store_true", |
|
110 help="disable the support of multimedia functions", |
|
111 ) |
|
112 parser.add_argument( |
|
113 "--no-open", |
|
114 action="store_true", |
|
115 help="don't open anything at startup except that given in command", |
|
116 ) |
|
117 parser.add_argument( |
|
118 "--no-splash", |
|
119 action="store_true", |
|
120 help="don't show the splash screen", |
|
121 ) |
|
122 parser.add_argument( |
|
123 "--no-crash", |
|
124 action="store_true", |
|
125 help="don't check for a crash session file on startup", |
|
126 ) |
|
127 parser.add_argument( |
|
128 "--disable-crash", |
|
129 action="store_true", |
|
130 help="disable the support for crash sessions", |
|
131 ) |
|
132 parser.add_argument( |
|
133 "--disable-plugin", |
|
134 metavar="plugin-name", |
|
135 default=[], |
|
136 action="append", |
|
137 help="disable the given plugin (may be repeated)", |
|
138 ) |
|
139 parser.add_argument( |
|
140 "--plugin", |
|
141 metavar="plugin-file", |
|
142 help="load the given plugin file (plugin development)", |
|
143 ) |
|
144 parser.add_argument( |
|
145 "--start-file", |
|
146 action="store_true", |
|
147 help="load the most recently opened file", |
|
148 ) |
|
149 parser.add_argument( |
|
150 "--start-multi", |
|
151 action="store_true", |
|
152 help="load the most recently opened multi-project", |
|
153 ) |
|
154 parser.add_argument( |
|
155 "--start-project", |
|
156 action="store_true", |
|
157 help="load the most recently opened project", |
|
158 ) |
|
159 parser.add_argument( |
|
160 "--start-session", |
|
161 action="store_true", |
|
162 help="load the global session file", |
|
163 ) |
|
164 parser.add_argument( |
|
165 "file_or_project", |
|
166 nargs="*", |
|
167 metavar="multi-project | project | file", |
|
168 help="open a project, multi-project or a list of files", |
|
169 ) |
|
170 |
|
171 # 3. preprocess the command line ('--' detection and split) |
|
172 if "--" in sys.argv: |
|
173 ddindex = sys.argv.index("--") |
|
174 argv = sys.argv[1:ddindex] |
|
175 dd_argv = sys.argv[ddindex + 1 :] |
|
176 else: |
|
177 argv = sys.argv[1:] |
|
178 dd_argv = [] |
|
179 |
|
180 # 4. create the Namespace object by parsing the command line |
|
181 args = parser.parse_args(argv) |
|
182 args.dd_args = dd_argv |
|
183 |
|
184 return args |
|
185 |
|
186 |
61 # some global variables needed to start the application |
187 # some global variables needed to start the application |
62 args = None |
188 args = createArgparseNamespace() |
63 mainWindow = None |
189 mainWindow = None |
64 splash = None |
190 splash = None |
65 inMainLoop = False |
191 inMainLoop = False |
66 app = None |
192 app = None |
67 |
193 |
68 if "--debug" in sys.argv: |
194 if args.debug: |
69 del sys.argv[sys.argv.index("--debug")] |
|
70 logging.basicConfig(level=logging.DEBUG) |
195 logging.basicConfig(level=logging.DEBUG) |
71 |
196 |
72 for arg in sys.argv[:]: |
197 if args.config: |
73 if arg.startswith("--config="): |
198 from eric7 import Globals |
74 from eric7 import Globals |
199 |
75 |
200 Globals.setConfigDir(args.config) |
76 configDir = arg.replace("--config=", "") |
201 if args.settings: |
77 Globals.setConfigDir(configDir) |
202 from PyQt6.QtCore import QSettings |
78 sys.argv.remove(arg) |
203 |
79 elif arg.startswith("--settings="): |
204 settingsDir = os.path.expanduser(args.settings) |
80 from PyQt6.QtCore import QSettings |
205 if not os.path.isdir(settingsDir): |
81 |
206 os.makedirs(settingsDir) |
82 settingsDir = os.path.expanduser(arg.replace("--settings=", "")) |
207 QSettings.setPath( |
83 if not os.path.isdir(settingsDir): |
208 QSettings.Format.IniFormat, QSettings.Scope.UserScope, settingsDir |
84 os.makedirs(settingsDir) |
209 ) |
85 QSettings.setPath( |
|
86 QSettings.Format.IniFormat, QSettings.Scope.UserScope, settingsDir |
|
87 ) |
|
88 sys.argv.remove(arg) |
|
89 |
210 |
90 from eric7.EricWidgets.EricApplication import EricApplication |
211 from eric7.EricWidgets.EricApplication import EricApplication |
91 |
212 |
92 |
213 |
93 def handleSingleApplication(ddindex): |
214 def handleSingleApplication(): |
94 """ |
215 """ |
95 Global function to handle the single application mode. |
216 Global function to handle the single application mode. |
96 |
|
97 @param ddindex index of a '--' option in the options list |
|
98 """ |
217 """ |
99 from eric7.EricWidgets.EricSingleApplication import EricSingleApplicationClient |
218 from eric7.EricWidgets.EricSingleApplication import EricSingleApplicationClient |
100 |
219 |
101 client = EricSingleApplicationClient() |
220 client = EricSingleApplicationClient() |
102 res = client.connect() |
221 res = client.connect() |
103 if res > 0: |
222 if res > 0: |
104 for switch in ( |
223 client.processArgs(args) |
105 "--debug", |
|
106 "--disable-crash", |
|
107 "--no-crash", |
|
108 "--no-multimedia", |
|
109 "--no-open", |
|
110 "--no-splash", |
|
111 "--small-screen", |
|
112 ): |
|
113 if switch in sys.argv and sys.argv.index(switch) < ddindex: |
|
114 sys.argv.remove(switch) |
|
115 ddindex -= 1 |
|
116 for arg in sys.argv[:]: |
|
117 for switch in ( |
|
118 "--config=", |
|
119 "--plugin=", |
|
120 "--disable-plugin=", |
|
121 "--settings=", |
|
122 ): |
|
123 if arg.startswith(switch) and sys.argv.index(arg) < ddindex: |
|
124 sys.argv.remove(arg) |
|
125 ddindex -= 1 |
|
126 break |
|
127 |
|
128 if len(sys.argv) > 1: |
|
129 client.processArgs(sys.argv[1:]) |
|
130 sys.exit(0) |
224 sys.exit(0) |
131 |
225 |
132 elif res < 0: |
226 elif res < 0: |
133 print("eric7: {0}".format(client.errstr())) |
227 print("eric7: {0}".format(client.errstr())) |
134 # __IGNORE_WARNING_M801__ |
228 # __IGNORE_WARNING_M801__ |
219 |
313 |
220 def main(): |
314 def main(): |
221 """ |
315 """ |
222 Main entry point into the application. |
316 Main entry point into the application. |
223 """ |
317 """ |
224 from eric7.Globals import AppInfo |
|
225 from eric7.SystemUtilities import OSUtilities, QtUtilities |
318 from eric7.SystemUtilities import OSUtilities, QtUtilities |
226 from eric7.Toolbox import Startup |
319 from eric7.Toolbox import Startup |
227 |
320 |
228 global app, args, mainWindow, splash, restartArgs, inMainLoop |
321 global app, args, mainWindow, splash, restartArgs, inMainLoop |
229 |
322 |
230 sys.excepthook = excepthook |
323 sys.excepthook = excepthook |
231 if OSUtilities.isLinuxPlatform(): |
324 if OSUtilities.isLinuxPlatform(): |
232 multiprocessing.set_start_method("spawn") |
325 multiprocessing.set_start_method("spawn") |
233 |
326 |
234 QGuiApplication.setDesktopFileName("eric7") |
327 QGuiApplication.setDesktopFileName("eric7") |
235 |
|
236 options = [ |
|
237 ( |
|
238 "--config=configDir", |
|
239 "use the given directory as the one containing the config files", |
|
240 ), |
|
241 ("--debug", "activate debugging output to the console"), |
|
242 ("--no-multimedia", "disable the support of multimedia functions"), |
|
243 ("--no-open", "don't open anything at startup except that given in command"), |
|
244 ("--no-splash", "don't show the splash screen"), |
|
245 ("--no-crash", "don't check for a crash session file on startup"), |
|
246 ("--disable-crash", "disable the support for crash sessions"), |
|
247 ( |
|
248 "--disable-plugin=<plug-in name>", |
|
249 "disable the given plug-in (may be repeated)", |
|
250 ), |
|
251 ("--plugin=plugin-file", "load the given plugin file (plugin development)"), |
|
252 ( |
|
253 "--settings=settingsDir", |
|
254 "use the given directory to store the settings files", |
|
255 ), |
|
256 ("--small-screen", "adjust the interface for screens smaller than FHD"), |
|
257 ("--start-file", "load the most recently opened file"), |
|
258 ("--start-multi", "load the most recently opened multi-project"), |
|
259 ("--start-project", "load the most recently opened project"), |
|
260 ("--start-session", "load the global session file"), |
|
261 ("--", "indicate that there are options for the program to be debugged"), |
|
262 ("", "(everything after that is considered arguments for this program)"), |
|
263 ] |
|
264 appinfo = AppInfo.makeAppInfo( |
|
265 sys.argv, |
|
266 "Eric7", |
|
267 "[project | files... [--] [debug-options]]", |
|
268 "A Python IDE", |
|
269 options, |
|
270 ) |
|
271 |
328 |
272 if "__PYVENV_LAUNCHER__" in os.environ: |
329 if "__PYVENV_LAUNCHER__" in os.environ: |
273 del os.environ["__PYVENV_LAUNCHER__"] |
330 del os.environ["__PYVENV_LAUNCHER__"] |
274 |
331 |
275 # make sure our executable directory (i.e. that of the used Python |
332 # make sure our executable directory (i.e. that of the used Python |
287 scheme = QWebEngineUrlScheme(b"qthelp") |
344 scheme = QWebEngineUrlScheme(b"qthelp") |
288 scheme.setSyntax(QWebEngineUrlScheme.Syntax.Path) |
345 scheme.setSyntax(QWebEngineUrlScheme.Syntax.Path) |
289 scheme.setFlags(QWebEngineUrlScheme.Flag.SecureScheme) |
346 scheme.setFlags(QWebEngineUrlScheme.Flag.SecureScheme) |
290 QWebEngineUrlScheme.registerScheme(scheme) |
347 QWebEngineUrlScheme.registerScheme(scheme) |
291 |
348 |
292 app = EricApplication(sys.argv) |
349 app = EricApplication(args) |
293 ddindex = Startup.handleArgs(sys.argv, appinfo) |
|
294 |
350 |
295 logging.debug("Importing Preferences") |
351 logging.debug("Importing Preferences") |
296 from eric7 import Preferences # __IGNORE_WARNING_I101__ |
352 from eric7 import Preferences # __IGNORE_WARNING_I101__ |
297 |
353 |
298 if Preferences.getUI("SingleApplicationMode"): |
354 if Preferences.getUI("SingleApplicationMode"): |
299 handleSingleApplication(ddindex) |
355 handleSingleApplication() |
300 |
356 |
301 # set the application style sheet |
357 # set the application style sheet |
302 app.setStyleSheetFile(Preferences.getUI("StyleSheet")) |
358 app.setStyleSheetFile(Preferences.getUI("StyleSheet")) |
303 |
359 |
304 # set the search path for icons |
360 # set the search path for icons |
327 path = os.path.join(pyqtDataDir, "bin") |
381 path = os.path.join(pyqtDataDir, "bin") |
328 else: |
382 else: |
329 path = pyqtDataDir |
383 path = pyqtDataDir |
330 os.environ["PATH"] = path + os.pathsep + os.environ["PATH"] |
384 os.environ["PATH"] = path + os.pathsep + os.environ["PATH"] |
331 |
385 |
332 pluginFile = None |
|
333 noopen = False |
|
334 nocrash = False |
|
335 disablecrash = False |
|
336 disabledPlugins = [] |
|
337 if "--no-open" in sys.argv and sys.argv.index("--no-open") < ddindex: |
|
338 sys.argv.remove("--no-open") |
|
339 ddindex -= 1 |
|
340 noopen = True |
|
341 if "--no-crash" in sys.argv and sys.argv.index("--no-crash") < ddindex: |
|
342 sys.argv.remove("--no-crash") |
|
343 ddindex -= 1 |
|
344 nocrash = True |
|
345 if "--disable-crash" in sys.argv and sys.argv.index("--disable-crash") < ddindex: |
|
346 sys.argv.remove("--disable-crash") |
|
347 ddindex -= 1 |
|
348 disablecrash = True |
|
349 for arg in sys.argv[:]: |
|
350 if arg.startswith("--disable-plugin=") and sys.argv.index(arg) < ddindex: |
|
351 # extract the plug-in name |
|
352 pluginName = arg.replace("--disable-plugin=", "") |
|
353 sys.argv.remove(arg) |
|
354 ddindex -= 1 |
|
355 disabledPlugins.append(pluginName) |
|
356 for arg in sys.argv: |
|
357 if arg.startswith("--plugin=") and sys.argv.index(arg) < ddindex: |
|
358 # extract the plugin development option |
|
359 pluginFile = arg.replace("--plugin=", "").replace('"', "") |
|
360 sys.argv.remove(arg) |
|
361 ddindex -= 1 |
|
362 pluginFile = os.path.expanduser(pluginFile) |
|
363 pluginFile = os.path.abspath(pluginFile) |
|
364 break |
|
365 |
|
366 # is there a set of filenames or options on the command line, |
|
367 # if so, pass them to the UI |
|
368 if len(sys.argv) > 1: |
|
369 args = sys.argv[1:] |
|
370 |
|
371 # get the Qt translations directory |
386 # get the Qt translations directory |
372 qtTransDir = Preferences.getQtTranslationsDir() |
387 qtTransDir = Preferences.getQtTranslationsDir() |
373 if not qtTransDir: |
388 if not qtTransDir: |
374 qtTransDir = QLibraryInfo.path(QLibraryInfo.LibraryPath.TranslationsPath) |
389 qtTransDir = QLibraryInfo.path(QLibraryInfo.LibraryPath.TranslationsPath) |
375 |
390 |