--- a/src/eric7/Toolbox/Startup.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Toolbox/Startup.py Wed Jul 13 14:55:47 2022 +0200 @@ -27,22 +27,24 @@ 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") + ("-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)) + + 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) @@ -51,41 +53,39 @@ 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 - 2022 Detlev Offenbach""" - """ <detlev@die-offenbachs.de>\n""" - """This is free software; see LICENSE.GPL3 for copying""" - """ conditions.\n""" - """There is NO warranty; not even for MERCHANTABILITY or FITNESS""" - """ FOR A\n""" - """PARTICULAR PURPOSE.""".format(**appinfo)) + print( + """\n""" + """{name} {version}\n""" + """\n""" + """{description}\n""" + """\n""" + """Copyright (c) 2002 - 2022 Detlev Offenbach""" + """ <detlev@die-offenbachs.de>\n""" + """This is free software; see LICENSE.GPL3 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 = 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: @@ -107,7 +107,7 @@ 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) @@ -116,12 +116,12 @@ def initializeResourceSearchPath(application): """ Module function to initialize the default mime source factory. - + @param application reference to the application object @type EricApplication """ import Preferences - + defaultIconPaths = getDefaultIconPaths(application) iconPaths = Preferences.getIcons("Path") for iconPath in iconPaths: @@ -135,14 +135,14 @@ def getDefaultIconPaths(application): """ Module function to determine the default icon paths. - + @param application reference to the application object @type EricApplication @return list of default icon paths @rtype list of str """ import Preferences - + defaultIconsPath = Preferences.getIcons("DefaultIconsPath") if defaultIconsPath == "automatic": if application.usesDarkPalette(): @@ -151,10 +151,10 @@ else: # light desktop defaultIconsPath = "breeze-light" - + return [ - os.path.join(getConfig('ericIconDir'), defaultIconsPath), - os.path.join(getConfig('ericIconDir'), defaultIconsPath, "languages"), + os.path.join(getConfig("ericIconDir"), defaultIconsPath), + os.path.join(getConfig("ericIconDir"), defaultIconsPath, "languages"), ] @@ -166,7 +166,7 @@ os.path.join(Globals.getPyQt6ModulesDirectory(), "plugins"), os.path.join(Globals.getPyQt6ModulesDirectory(), "Qt6", "plugins"), ) - + libraryPaths = QApplication.libraryPaths() for libPath in libPaths: if os.path.exists(libPath): @@ -175,6 +175,7 @@ libraryPaths.insert(0, libPath) QApplication.setLibraryPaths(libraryPaths) + # the translator must not be deleted, therefore we save them here loaded_translators = {} @@ -182,7 +183,7 @@ def loadTranslators(qtTransDir, app, translationFiles=()): """ 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 translationFiles tuple of additional translations to @@ -190,12 +191,18 @@ @return the requested locale (string) """ import Preferences - + global loaded_translators - + translations = ( - "qt", "qt_help", "qtbase", "qtmultimedia", "qtserialport", - "qtwebengine", "qtwebsockets", "eric7" + "qt", + "qt_help", + "qtbase", + "qtmultimedia", + "qtserialport", + "qtwebengine", + "qtwebsockets", + "eric7", ) + translationFiles loc = Preferences.getUILanguage() if loc is None: @@ -204,7 +211,7 @@ if loc == "System": loc = QLocale.system().name() if loc != "C": - dirs = [getConfig('ericTranslationsDir'), Globals.getConfigDir()] + dirs = [getConfig("ericTranslationsDir"), Globals.getConfigDir()] if qtTransDir is not None: dirs.append(qtTransDir) @@ -223,14 +230,21 @@ return loc -def simpleAppStartup(argv, appinfo, mwFactory, quitOnLastWindowClosed=True, - app=None, raiseIt=True, installErrorHandler=False): +def simpleAppStartup( + argv, + appinfo, + mwFactory, + quitOnLastWindowClosed=True, + app=None, + raiseIt=True, + installErrorHandler=False, +): """ Module function to start up an application that doesn't need a specialized start up. - + 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 mwFactory factory function generating the main widget. This @@ -249,10 +263,10 @@ @return exit result (integer) """ 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 @@ -260,40 +274,41 @@ app = EricApplication(argv) application = app app.setQuitOnLastWindowClosed(quitOnLastWindowClosed) - + # the following code depends upon a valid application object import Preferences - + # set the application style sheet app.setStyleSheetFile(Preferences.getUI("StyleSheet")) - + initializeResourceSearchPath(app) QApplication.setWindowIcon(UI.PixmapCache.getIcon("eric")) - + qtTransDir = Preferences.getQtTranslationsDir() if not qtTransDir: - qtTransDir = QLibraryInfo.path( - QLibraryInfo.LibraryPath.TranslationsPath) + qtTransDir = QLibraryInfo.path(QLibraryInfo.LibraryPath.TranslationsPath) loadTranslators(qtTransDir, app, ("qscintilla",)) # qscintilla needed for web browser - + w = mwFactory(argv) if w is None: return 100 - + if quitOnLastWindowClosed: app.lastWindowClosed.connect(app.quit) w.show() if raiseIt: w.raise_() - + if installErrorHandler: # generate a graphical error handler from EricWidgets import EricErrorMessage + eMsg = EricErrorMessage.qtHandler() eMsg.setMinimumSize(600, 400) - + return app.exec() + # # eflag: noqa = M801