--- a/src/eric7/Toolbox/Startup.py Sat Nov 11 10:13:29 2023 +0100 +++ b/src/eric7/Toolbox/Startup.py Sat Nov 11 12:44:51 2023 +0100 @@ -22,95 +22,6 @@ application = None -def usage(appinfo, optlen=12): - """ - Module function to show the usage information. - - @param appinfo dictionary describing the application - @param optlen length of the field for the commandline option (integer) - """ - options = [ - ("--version", "show the program's version number and exit"), - ("-h, --help", "show this help message and exit"), - ] - options.extend(appinfo["options"]) - - print( - """\n""" - """Usage: {bin} [OPTIONS] {arg}\n""" - """\n""" - """{name} - {description}\n""" - """\n""" - """Options:""".format(**appinfo) - ) - for opt in options: - print(" {0} {1}".format(opt[0].ljust(optlen), opt[1])) - sys.exit(0) - - -def version(appinfo): - """ - Module function to show the version information. - - @param appinfo dictionary describing the application - """ - print( - """\n""" - """{name} {version}\n""" - """\n""" - """{description}\n""" - """\n""" - """Copyright (c) 2002 - 2023 Detlev Offenbach""" - """ <detlev@die-offenbachs.de>\n""" - """This is free software; see LICENSE.txt for copying""" - """ conditions.\n""" - """There is NO warranty; not even for MERCHANTABILITY or FITNESS""" - """ FOR A\n""" - """PARTICULAR PURPOSE.""".format(**appinfo) - ) - sys.exit(0) - - -def handleArgs(argv, appinfo): - """ - Module function to handle the always present commandline options. - - @param argv list of commandline parameters (list of strings) - @param appinfo dictionary describing the application - @return index of the '--' option (integer). This is used to tell - the application, that all additional options don't belong to - the application. - """ - ddindex = 30000 # arbitrarily large number - args = {"--version": version, "--help": usage, "-h": usage} - if "--" in argv: - ddindex = argv.index("--") - for a in args: - if a in argv and argv.index(a) < ddindex: - args[a](appinfo) - return ddindex - - -def loadTranslatorForLocale(dirs, tn): - """ - Module function to find and load a specific translation. - - @param dirs Searchpath for the translations. (list of strings) - @param tn The translation to be loaded. (string) - @return Tuple of a status flag and the loaded translator - (int, QTranslator) - """ - trans = QTranslator(None) - for directory in dirs: - loaded = trans.load(tn, directory) - if loaded: - return (trans, True) - - print("Warning: translation file '" + tn + "'could not be loaded.") - print("Using default.") - return (None, False) - - def initializeResourceSearchPath(application): """ Module function to initialize the default mime source factory. @@ -182,11 +93,15 @@ """ Module function to load all required translations. - @param qtTransDir directory of the Qt translations files (string) - @param app reference to the application object (QApplication) + @param qtTransDir directory of the Qt translations files + @type str + @param app reference to the application object + @type QApplication @param translationFiles tuple of additional translations to - be loaded (tuple of strings) - @return the requested locale (string) + be loaded + @type tuple of str + @return the requested locale + @rtype str """ from eric7 import Preferences @@ -228,9 +143,30 @@ return loc -def simpleAppStartup( - argv, - appinfo, +def loadTranslatorForLocale(dirs, tn): + """ + Module function to find and load a specific translation. + + @param dirs searchpath for the translations + @type list of str + @param tn translation to be loaded + @type str + @return tuple containing a status flag and the loaded translator + @rtype tuple of (int, QTranslator) + """ + trans = QTranslator(None) + for directory in dirs: + loaded = trans.load(tn, directory) + if loaded: + return (trans, True) + + print("Warning: translation file '" + tn + "'could not be loaded.") + print("Using default.") + return (None, False) + + +def appStartup( + args, mwFactory, quitOnLastWindowClosed=True, app=None, @@ -243,33 +179,38 @@ This function is used by all of eric's helper programs. - @param argv list of commandline parameters (list of strings) - @param appinfo dictionary describing the application + @param args namespace object created by ArgumentParser.parse_args() containing + the parsed command line arguments + @type argparse.Namespace @param mwFactory factory function generating the main widget. This function must accept the following parameter. <dl> - <dt>argv</dt> - <dd>list of commandline parameters (list of strings)</dd> + <dt>args</dt> + <dd>parsed command line arguments (argparse.Namespace)</dd> </dl> @param quitOnLastWindowClosed flag indicating to quit the application, - if the last window was closed (boolean) - @param app reference to the application object (QApplication or None) + if the last window was closed + @type bool + @param app reference to the application object + @type QApplication or None @param raiseIt flag indicating to raise the generated application - window (boolean) + window + @type bool @param installErrorHandler flag indicating to install an error - handler dialog (boolean) - @return exit result (integer) + handler dialog + @type bool + @return exit result + @rtype int """ global application if "__PYVENV_LAUNCHER__" in os.environ: del os.environ["__PYVENV_LAUNCHER__"] - handleArgs(argv, appinfo) if app is None: # set the library paths for plugins setLibraryPaths() - app = EricApplication(argv) + app = EricApplication(sys.argv) application = app app.setQuitOnLastWindowClosed(quitOnLastWindowClosed) @@ -288,7 +229,7 @@ loadTranslators(qtTransDir, app, ("qscintilla",)) # qscintilla needed for web browser - w = mwFactory(argv) + w = mwFactory(args) if w is None: return 100